Shraddha C# Final
Shraddha C# Final
Shraddha C# Final
PROGRAM 1: Write a C# console application to ask the user for a symbol and answer
if it is a (lowercase) vowel, a digit, or any other symbol. (using switch or if and use {0}).
REG NO: 221919
DATE:08/11/2023
***************************************************************************
using System;
namespace Program1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the Character :");
char ch = Console.ReadKey().KeyChar;
Console.WriteLine();
if (char.IsLetter(ch))
{
String vows = "aeiouAEIOU";
if (vows.IndexOf(ch) != -1)
{
Console.WriteLine("It's a vowel");
}
if (char.IsLower(ch))
{
Console.WriteLine("It's a lowercase letter");
}
else
{
Console.WriteLine("It's an uppercase letter");
}
}
else if (char.IsDigit(ch))
{
Console.WriteLine("It's a digit");
}
else
{
Console.WriteLine("It's neither a letter nor a digit");
}
Console.ReadLine();
}
}
}
OUTPUT:
***************************************************************************
PROGRAM 2: Write a C# console application to read a user input as either a word or a
sentence and display each word in sorted order with the length of each word.
REG NO: 221919
DATE:15/11/2023
***************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace program2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a sentence or words");
String st = Console.ReadLine();
String[] arr = st.Split(' ');
}
}
}
for (int i = 0; i < arr.Length; i++)
{
Console.WriteLine(arr[i] + " Length is : " + arr[i].Length);
}
Console.ReadLine();
}
}
}
OUTPUT:
***************************************************************************
PROGRAM 3: Write a C# console application for conversion of a number to its
corresponding string (create string array, and use string methods trim, length,
elementat).
REG NO: 221919
DATE:21/11/2023
***************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace program3
{
class Program
{
static void Main(string[] args)
{
String[] first_twenty = { "", "one", "two", "three", "four", "five", "six", "seven",
"eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen",
"seventeen", "eighteen", "ninghteen" };
String[] tens = { "", "ten", "twenty", "thirty", "fourty", " fifty", "sixty", "seventy",
"eighty", "ninty" };
String[] hundreds = { "", "hundred and ", "two hundred and", "three hundred and",
"four hundred and", "five hundred and", "six hundred and", "seven hundred and", "eight
hundred and", "nine hundred and" };
String[] thousands = { "", "one thousand", "two thousand", "three thousand", "four
thousand", "five thousand", "six thousand", "seven thousand", "eigth thousand", "nine
thousand" };
Console.ReadLine();
}
}
}
OUTPUT:
***************************************************************************
PROGRAM 4: Write a C# console application to remove all characters in the second
string that are present in the first string.
REG NO: 221919
DATE:28/11/2023
***************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace program4
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter the first string");
string st1 = Console.ReadLine();
Console.WriteLine("enter the second string");
string st2 = Console.ReadLine();
sb2.Remove(j, 1);
matchFound = true;
}
}
if (matchFound)
i--;
}
Console.WriteLine("After removing all characters " + sb2);
Console.ReadLine();
}
}
}
OUTPUT:
***************************************************************************
PROGRAM 5: Write a C# console application to perform the following.
• Print the string in ascending order of their size.
• Ignore similar words
• Print all the words of the same size.
REG NO: 221919
DATE:29/11/2023
***************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace program5
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a sentence or words : ");
String sentence = Console.ReadLine();
String[] narray = sentence.Split(' ');
Console.WriteLine("\nPrinting the string in ascending order of their size:");
for (int i = 0; i < narray.Length; i++)
{
for (int j = i + 1; j < narray.Length; j++)
{
if (narray[i].Length > narray[j].Length)
{
string temp = narray[j];
narray[j] = narray[i];
narray[i] = temp;
}
}
}
for (int i = 0; i < narray.Length; i++)
{
Console.Write(narray[i] + " ");
}
Console.WriteLine();
for (int i = 0; i < narray.Length; i++)
{
for (int j = i + 1; j < narray.Length; j++)
{
if (narray[i] == narray[j])
narray[i] = null;
}
}
Console.WriteLine("\nAfter ignoring similar words :");
for (int i = 0; i < narray.Length; i++)
{
if (narray[i] != null)
Console.Write(narray[i] + " ");
}
Console.WriteLine();
Console.WriteLine("Words of similar size:");
int currentLength = -1;
foreach (string word in narray)
{
if (word != null && word.Length != currentLength)
{
Console.WriteLine($"Words of length {word.Length}:");
currentLength = word.Length;
}
if (word != null)
Console.Write(word + " ");
Console.WriteLine();
}
Console.ReadLine();
}
}
}
OUTPUT:
***************************************************************************
PROGRAM 6: Write a C# console application that asks the user to enter a six-digit
ticket number. Ticket numbers are designed so that if you drop the last digit of the
number, and then divide the number by 7, the remainder of the division will be identical
to the last dropped digit.
REG NO: 221919
DATE:05/12/2023
***************************************************************************
WebForm1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="WebApplication6.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Ticket Number"></asp:Label>
<asp:TextBox ID="txtnum" runat="server"></asp:TextBox>
<br />
<br />
&nbs
p;
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit"
/>
<br />
<br />
<asp:Label ID="lblres" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
WebForm1.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication6
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (rem1 == rem)
{
lblres.Text = "It is a valid ticket number";
}
else
{
lblres.Text = "Its not a valid ticket number";
}
}
}
}
}
OUTPUT:
***************************************************************************
PROGRAM 7: Write a C# program to create an array of 5 strings containing the first
name of your friends. Count and display the total number of vowels (Uppercase and
lowercase) in all five strings that you have entered.
REG NO: 221919
DATE:06/12/2023
***************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace program7
{
class Program
{
static void Main(string[] args)
{
string[] narray = new string[5];
string vow = "aeiou";
Console.WriteLine("Enter 5 names:");
for (int i = 0; i < narray.Length; i++)
{
narray[i] = Console.ReadLine();
}
foreach (string str in narray)
{
int count = 0; string vowstr = "";
string s = str.ToLower();
char[] charay = str.ToCharArray();
for (int i = 0; i < charay.Length; i++)
{
if (vow.Contains(charay[i]))
{
count++;
vowstr = vowstr + charay[i];
}
}
Console.WriteLine("vowel count in " + str + " is " + count + " and vowels are " +
vowstr);
}
Console.ReadLine();
}
}
}
OUTPUT:
***************************************************************************
PROGRAM 8: Write a C# program to check whether the given string is colindrome or
not. A string is said to be colindrome if it has consecutive 3 alphabets followed by the
reverse of these 3 alphabets and so on.
REG NO: 221919
DATE:12/12/2023
***************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace program8
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the string");
string st = Console.ReadLine();
bool colin=false;
int len = st.Length;
if (len % 6 == 0)
{
while(len != 0)
{
colin = false;
string s1 = "", s2 = "", s3 = "";
s1 = st.Substring(0, 3);
s2 = st.Substring(3, 3);
for(int i = s2.Length-1; i >= 0; i--)
{
s3 = s3 + s2[i];
}
if (string.Equals(s1, s3))
{
colin = true;
}
st = st.Remove(0, 6);
len = len - 6;
}
if (colin)
{
Console.WriteLine("Given String is Colindrome");
}
else
{
Console.WriteLine("Given String is not colindrome");
}
}
else
{
Console.WriteLine("Given String is not colindrome");
}
Console.ReadLine();
}
}
}
OUTPUT:
***************************************************************************
PROGRAM 9: Write a C# console application to perform flames game.
REG NO: 221919
DATE:13/12/2023
***************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace flames_pgm9
{
class Program
{
public static void Main(string[] args)
{
Console.WriteLine("enter the first string");
string st1 = Console.ReadLine();
Console.WriteLine("enter the second string");
string st2 = Console.ReadLine();
StringBuilder sb1 = new StringBuilder(st1);
StringBuilder sb2 = new StringBuilder(st2);
for (int i = 0; i < sb1.Length; i++)
{
bool matchFound = false;
for (int j = 0; j < sb2.Length; j++)
{
if (sb1[i] == sb2[j])
{
sb1.Remove(i, 1);
sb2.Remove(j, 1);
matchFound = true;
break;
}
}
if (matchFound)
i--;
}
int len = sb1.Length + sb2.Length;
if (len > 5)
{
len = len % 6;
}
switch (len)
{
case 1:
Console.WriteLine("Friends");
break;
case 2:
Console.WriteLine("Love");
break;
case 3:
Console.WriteLine("Affection");
break;
case 4:
Console.WriteLine("Marriage");
break;
case 5:
Console.WriteLine("Engage");
break;
case 0:
Console.WriteLine("Sister");
break;
}
Console.ReadLine();
}
}
}
OUTPUT:
***************************************************************************
PROGRAM 10: Write a C# console application to create item class with Ino, Iname,
Rate, Qty and amount. Calculate amount using the appropriate method. Create an
array of 5 item objects. Display the details of item objects in the descending order of
amount.
REG NO: 221919
DATE:19/12/2023
***************************************************************************
using System;
namespace program10
{
public class Item
{
int no, qty;
string name;
double rate;
public Item(int Ino, string Iname, double Irate, int Iqty)
{
no = Ino;
name = Iname;
rate = Irate;
qty = Iqty;
}
public double CalculateAmount()
{
return rate * qty;
}
public void Display()
{
double amount = CalculateAmount();
Console.WriteLine("{0,-5} {1,-15} {2,-10} {3,-10} {4,-10}", no, name, rate, qty,
amount);
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the number of Items: ");
int n = Convert.ToInt32(Console.ReadLine());
Item[] items = new Item[n];
for (int i = 0; i < n; i++)
{
Console.Write("Enter Item No : ");
int Ino = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter Item Name : ");
string Iname = Console.ReadLine();
Console.Write("Enter Item Rate : ");
double Irate = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter Item Qty : ");
int Iqty = Convert.ToInt32(Console.ReadLine());
items[i] = new Item(Ino, Iname, Irate, Iqty);
}
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - i - 1; j++)
{
if (items[j].CalculateAmount() < items[j + 1].CalculateAmount())
{
Item temp = items[j];
items[j] = items[j + 1];
items[j + 1] = temp;
}
}
}
Console.WriteLine("Items in ascending order of their amount:");
Console.WriteLine("INO INAME IRATE IQTY IAMOUNT");
foreach (Item item in items)
{
item.Display();
Console.WriteLine();
}
Console.ReadLine();
}
}
}
OUTPUT:
***************************************************************************
PROGRAM 11: Write a C# program to show class and object creation (Student class).
REG NO: 221919
DATE:20/12/2023
***************************************************************************
using System;
namespace program11
{
public class Student
{
string name, course;
int id, marks;
class Program
{
static void Main(string[] args)
{
string sname, scourse;
int sid, smarks;
{
public class Overloading_Method
{
public void add(int a, int b)
{
Console.WriteLine("Addition of two integers : " + (a + b));
}
public void add(float a, float b)
{
Console.WriteLine("Addition of two float values : " + (a + b));
}
public void add(string a, string b)
{
Console.WriteLine("Addition of two strings : " + (a + b));
}
}
class Program
{
static void Main(string[] args)
{
Overloading_Method obj = new Overloading_Method();
Console.WriteLine("Method Overloading Program");
obj.add(200, 400);
obj.add(25.5f, 45.5f);
obj.add("Chandler", "bling");
Console.ReadLine();
}
}
}
OUTPUT:
***************************************************************************
PROGRAM 14: Write a C# program to demonstrate the concept of Polymorphism via
Method Overriding/ Dynamic Method Dispatch [Runtime Polymorphism (Shape class)]
and Abstract class
REG NO: 221919
DATE:09/01/2024
***************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace program14
{
abstract class Shape
{
public abstract void area();
public void display()
{
Console.Write("The area of a ");
}
}
class Circle : Shape
{
float r;
public Circle(float rad)
{
r = rad;
}
public override void area()
{
float pi = 3.14f;
float Ar = pi * r * r;
Console.WriteLine("Circle: {0}", Ar);
}
public void display()
{
base.display();
}
}
class Rectangle : Shape
{
int l, b;
public Rectangle(int len, int br)
{
l = len;
b = br;
}
public override void area()
{
int Ar = l * b;
Console.WriteLine("Rectangle: {0}", Ar);
}
public void display()
{
base.display();
}
}
class Triangle : Shape
{
int b, h;
public Triangle(int bse, int height)
{
b = bse;
h = height;
}
public override void area()
{
float Ar = 0.5f * b * h;
Console.WriteLine("Triangle: {0}", Ar);
}
public void display()
{
base.display();
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Abstract class for Shape");
Shape Sobj;
Sobj = new Circle(8f);
Sobj.display();
Sobj.area();
Sobj = new Rectangle(3, 2);
Sobj.display();
Sobj.area();
Sobj = new Triangle(2, 8);
Sobj.display();
Sobj.area();
Console.ReadLine();
}
}
}
OUTPUT:
***************************************************************************
PROGRAM 15: Write a C# program to demonstrate the concept of Interface.
REG NO: 221919
DATE:10/01/2024
***************************************************************************
using System;
namespace program15
{
interface Addition
{
int Add(int x, int y);
}
interface Substraction : Addition
{
int Sub(int x, int y);
}
interface Multiplication : Substraction
{
int Mul(int x, int y);
}
class A
{
public virtual void display()
{
Console.WriteLine("Hello there");
}
}
abstract class B : A, Multiplication
{
public abstract int Add(int x, int y);
public abstract int Sub(int x, int y);
public abstract int Mul(int x, int y);
public override void display()
{
Console.WriteLine("Hello");
}
}
class C : B
{
public override int Add(int x, int y)
{
return x + y;
}
OUTPUT:
***************************************************************************
PROGRAM 16: Write a C# program to demonstrate the concept of Exception Handling
and User Defined Exceptions.
REG NO: 221919
DATE:17/01/2024
***************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace program16
{
class AgeException : Exception
{
public AgeException(string message)
{
Console.WriteLine(message);
Console.WriteLine("You are not eligible for voting");
}
}
class Program
{
static void Main(string[] args)
{
try
{
int age;
Console.WriteLine("Enter Your age");
age = Convert.ToInt32(Console.ReadLine());
if (age < 18)
{
throw new AgeException("Age is below 18 ");
}
else
{
Console.WriteLine("You are eligible for voting");
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
Console.WriteLine("execution completed..");
}
Console.ReadLine();
}
}
}
OUTPUT: