Write A Program To Develop A Control Application To Demonstrate The Control Structure in C#
Write A Program To Develop A Control Application To Demonstrate The Control Structure in C#
Write A Program To Develop A Control Application To Demonstrate The Control Structure in C#
Write a program
Console to develop
application a control application
to demonstrate
to demonstrate the control structure in c#.
DATE: 07.02.2022 the control structures in C#
Aim
Algorithm
If
using System;
using System.Collections.Generic;
using System.Text;
namespace @if
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a number");
int num = Convert.ToInt32(Console.ReadLine());
if (num % 2 == 0)
{
Console.WriteLine("It is even number");
}
Console.WriteLine("Press Enter key to Exit...");
Console.ReadLine();
}
}
}
Output
Enter a number
18
It is even number
using System;
using System.Collections.Generic;
using System.Text;
namespace ifelse
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a number");
int num = Convert.ToInt32(Console.ReadLine());
if (num % 2 == 0)
{
Console.WriteLine("It is even number");
}
else
{
Console.WriteLine("It is odd number");
}
Console.WriteLine("Press Enter key to Exit...");
Console.ReadLine();
}
}
}
Output
Enter a number
59
It is odd number
using System;
using System.Collections.Generic;
using System.Text;
namespace elseif
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a number");
int number = Convert.ToInt32(Console.ReadLine());
if (number < 0 || number > 100)
{
Console.WriteLine("Wrong Number");
}
else if (number >= 10 && number < 0)
{
Console.WriteLine("Fail");
}
else if (number >= 50 && number < 60)
{
Console.WriteLine("D Grade");
}
else if (number >= 60 && number < 70)
{
Console.WriteLine("C Grade");
}
else if (number >= 70 && number < 80)
{
Console.WriteLine("B Grade");
}
else if (number >= 80 && number < 90)
{
Console.WriteLine("A Grade");
}
else if (number >= 90 && number < 100)
{
Console.WriteLine("A+ Grade");
}
Console.WriteLine("Press Enter key to Exit...");
Console.ReadLine();
}
}
}
Output
Enter a number
98
A+ Grade
using System;
using System.Collections.Generic;
using System.Text;
namespace For
{
class Program
{
static void Main(string[] args)
{
int a = 5, sum = 0;
for(int i=1;i<=a; i++)
{
//sum=sum+i;
sum+=i;
}
Console.WriteLine("Sum of the first {0} natural numbers={1}",a,sum);
Console.ReadKey();
}
}
}
Output
using System;
using System.Collections.Generic;
using System.Text;
namespace dowhile
{
class Program
{
static void Main(string[] args)
{
int i = 1, n = 5, product;
Console.WriteLine("The product of n and i are:");
Console.WriteLine("---------------------------");
do
{
product = n * i;
Console.WriteLine("{0} * {1} = {2}", n, i, product);
i++;
}
while (i <= 10);
Console.ReadKey();
}
}
}
Output
The product of n and i are:
---------------------------
5*1=5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
For Each
using System;
using System.Collections.Generic;
namespace Loop
{
class ForEachLoop
{
public static void Main(string[] args)
{
var numbers = new List<int>() { 5, -8, 3, 14, 9, 17, 0, 4 };
int sum = 0;
foreach (int number in numbers)
{
sum += number;
}
Console.WriteLine("The sum of numbers in the Array are:");
Console.WriteLine("Sum = {0}", sum);
Console.ReadLine();
}
}
}
Output
Result
Thus the program was executed successfully and the output was verified.
EX NO: 02
Change color of label text control
DATE: 14.02.2022 programmatically in ASP.NET
Aim
Algorithm
Source code
Button Click
using System;
using System.Collections;
using System.Configuration;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace WebApplication1
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Font.Name = "Arial";
Label1.Font.Bold = true;
Label1.ForeColor = Color.Red;
Label1.Font.Italic = true;
}
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Font.Name = "Times new Roman";
Label1.Font.Bold = true;
Label1.ForeColor = Color.Blue;
Label1.Font.Strikeout = true;
Label1.Font.Size = FontUnit.Large;
}
protected void Button3_Click(object sender, EventArgs e)
{
Label1.Font.Name = "Bookman Old";
Label1.Font.Bold = true;
Label1.ForeColor = Color.Green;
Label1.Font.Italic = true;
Label1.Font.Size = FontUnit.Large;
}
}
}
Output
Result
Thus the program was executed successfully and the output as verified.
EX NO: 03
Type casting Methods
DATE: 21.02.2022
Aim
Algorithm
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ExplicitTypeconversion
{
class Program
{
static void Main(string[] args)
{
double d = 5673.74;
int i;
i=(int)d;
Console.WriteLine(i);
Console.ReadKey();
}
}
}
Output
5673
Implicit Type Conversion
using System;
using System.Collections.Generic;
using System.Text;
using System;
namespace ImplicitTypeConversion
{
class Program
{
static void Main(string[] args)
{
int numInt = 500;
// Implicit Conversion
double numDouble = numInt;
Result
Thus the program was executed successfully and the output was verified.
EX NO: 04
Thus the program was executed successfully and the output was verified
Convert Infix notation to Postfix notation.
DATE: 28.02.2022
Aim
Algorithm
Infix : a+b*c-d
Postfix : abc*+d-
Infix : a+b*c-d/e*f
Postfix : abc*+de/f*-
Infix : a-b/c*d-e--f/b*i++
Postfix : abc/d*-e--fb/i*-++
Result
Thus the program was executed successfully and the output was verified.
EX NO: 05
Convert Digits to Words
DATE: 03.03.2022
Aim
Algorithm
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace numbertoword
{
class Program
{
static void Main(string[] args)
{
int number;
int nextDigit;
int numDigits;
int[] n = new int[20];
String[]
digits={"Zero","one","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
Console.WriteLine("Enter any number");
number = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Entered number is:" + number);
Console.Write("Number in words:");
nextDigit = 0;
numDigits = 0;
do
{
nextDigit = number % 10;
n[numDigits] = nextDigit;
numDigits++;
number = number / 10;
}while (number > 0);
numDigits--;
for ( ; numDigits >= 0; numDigits--)
Console.Write(digits[n[numDigits]] + "");
Console.WriteLine();
Console.ReadLine();
}
}
}
Output
19856321
Number in words: one Nine Eight Five Six Three Two one
Result
Thus the program was executed successfully and the output was verified.
EX NO: 06
Increase and Decrease font size
DATE: 10.03.2022 programmatically
Aim
Algorithm
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace fontsize
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
FontDialog fd=new FontDialog();
if (fd.ShowDialog() == DialogResult.OK)
{
richTextBox1.Font=fd.Font;
}
}
private void button2_Click(object sender, EventArgs e)
{
ColorDialog col = new ColorDialog();
col.ShowDialog();
richTextBox1.SelectionColor=col.Color;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
Output
Result
Thus the program was executed successfully and the output was verified.
EX NO: 07
Develop a console application to demonstrate
Aim
Algorithm
Break Statement
using System;
using System.Collections.Generic;
using System.Text;
namespace breakexample
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Example of Break Statement:");
Console.WriteLine("--------------------------");
for(int i=1;i<=4;i++)
{
if(i==3)
break;
Console.WriteLine("The Value of i is:{0}",i);
}
Console.WriteLine("Press any key to exit...");
Console.ReadLine();
}
}
}
Output
-----------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace @continue
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("USE OF CONTINUE STATEMENT:");
Console.WriteLine("-------------------------");
for (int x = 1; x <= 6; x++)
{
if (x == 5)
continue;
Console.WriteLine("The value of x is:{0}", x);
}
Console.WriteLine("Press any key to exit.....");
Console.ReadLine();
}
}
}
Output
---------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace goto1
{
class Program
{
static void Main(string[] args)
{
//label
repeat:
Console.WriteLine("Enter a number less than 10");
int num = Convert.ToInt32(Console.ReadLine());
if(num>=10)
{
//Transfers control to repeat
goto repeat;
}
Console.WriteLine(num+ "is less than 10");
Console.ReadLine();
}
}
}
Output
8 is less than 10
Result
Thus the program was executed successfully and the output was verified.
EX NO: 08
Multilevel Inheritance
DATE: 28.03.2022
Aim
Algorithm
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
public class person
{
protected string regno,name;
public void get()
{
Console.WriteLine("Multilevel inheritence");
Console.WriteLine("----------------------");
Console.WriteLine("Enter the Register Number:");
regno = Console.ReadLine();
Console.WriteLine("Enter the name of the student:");
name = Console.ReadLine();
}
public virtual void display()
{
Console.WriteLine("The register number of the student is {0} & the name of the student is
{1}",regno,name);
Console.ReadLine();
}
}
class student:person
{
public string classincharge="Mrs.Anitha";
public override void display()
{
base.display();
Console.WriteLine("Class in charge of student is {0}", classincharge);
}
}
class Details:student
{
private string StudentAddress="SRM University,Girls hostel,Chennai";
public void display()
{
Console.WriteLine("Student address:{0}",StudentAddress);
}
}
class textclass
{
public static void Main()
{
student s = new student();
s.get();
s.display();
Details d = new Details();
d.display();
Console.ReadKey();
Console.ReadKey();
}
}
}
Output
Multilevel inheritance
---------------------------
201
Abi
The register number of the student is 201 & the name of the student is Abi
Result
Thus, the program was executed successfully and the output was verified.
EX NO: 09
Polymorphism
DATE: 05.04.2022
Aim
Algorithm
Method Overloading
Method Overriding
Program coding
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace polymorphism
{
class ADD1
{
public void add(int a, int b)
{
Console.WriteLine(a + b);
}
public void add(float x, float y)
{
Console.WriteLine(x + y);
}
}
class ADD2:ADD1
{
public void add(string s1, string s2)
{
Console.WriteLine(s1 + s2);
}
}
class program
{
public static void Main(string[] args)
{
ADD2 obj = new ADD2();
obj.add(15, 400);
obj.add("Vijaya", "kumar");
Console.WriteLine("Press any to exit");
Console.ReadKey();
}
}
}
Output
415
Vijayakumar
Program coding
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace poly2
{
class shape
{
protected int length, width;
public shape(int a, int b)
{
length = a;
width = b;
}
public virtual int area()
{
Console.WriteLine("parent class area");
return 0;
}
}
class Rectangle : shape
{
public Rectangle(int a, int b)
: base(a, b)
{
}
public override int area()
{
Console.WriteLine("Rectangle class area:");
return (length * width);
}
}
class Triangle : shape
{
public Triangle(int a, int b)
: base(a, b)
{
}
public override int area()
{
{
Console.WriteLine("Triangle class area:");
return (length*width/2);
}
}
class caller
{
public void callArea(shape sh)
{
int a;
a = sh.area();
Console.WriteLine("Area:{0}", a);
}
}
class Tester
{
static void Main(string[] args)
{
caller c = new caller();
Rectangle r = new Rectangle(15, 7);
Triangle t = new Triangle(20, 5);
c.callArea(r);
c.callArea(t);
Console.ReadKey();
}
}
}
}
Output
Area:105
Area:50
Result
Thus the program was executed successfully and the output was verified.
EX NO: 10
Currency conversion for Rupees to
Aim
To write a code to convert currency conversion for rupees to dollar, franc, euro.
Algorithm
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace rupees
{
class Program
{
static void Main(string[] args)
{
while(true)
{
Console.WriteLine("Enter your choice:");
Console.WriteLine("1.Rupees to France");
Console.WriteLine("2.Rupees to dollar:");
Console.WriteLine("3.Rupees to euro:");
Console.WriteLine("4.Exit");
int choice = int.Parse(Console.ReadLine());
switch (choice)
{
case 1:
franc();
break;
case 2:
dollar();
break;
case 3:
euro();
break;
case 4:
break;
default:
Console.WriteLine("Enter valid choice");
break;
}
if
(choice == 4)
break;}
Console.ReadKey();
}
static void franc()
{
Console.WriteLine("Enter amount in Rupees:");
double r=double.Parse(Console.ReadLine());
double f=r/83.52;
Console.Write("franc:\t{0}\n",f);
}
static void dollar()
{
Console.WriteLine("Enter amount in Rupees:");
double r=double.Parse(Console.ReadLine());
double d=r/76.90;
Console.WriteLine("dollar :{0}\n",d);
}
static void euro()
{
Console.WriteLine("Enter amount in Rupees:");
double r=double.Parse(Console.ReadLine());
double e=r/83.65;
Console.Write("euro:\t{0}\n",e);
}}}
Output
Result
Thus the program was executed successfully and the output was verified.
EX NO: 11
String Functions
DATE: 19.04.2022
Aim
Algorithm
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace String
{
class Program
{
static void Main(string[] args)
{
string A, B;
A = "Hello World";
B = "World";
Console.WriteLine(A.Clone());
Console.WriteLine(A.Contains("llo"));
Console.WriteLine(A.EndsWith("o"));
Console.WriteLine(A.Equals(B));
Console.WriteLine(A.GetHashCode());
Console.WriteLine(A.GetType());
Console.WriteLine(A.GetTypeCode());
Console.WriteLine(A.IndexOf("e"));
Console.WriteLine(A.ToLower());
Console.WriteLine(A.ToUpper());
Console.WriteLine(A.Insert(0,"Hai"));
Console.WriteLine(A.IsNormalized());
Console.WriteLine(A.LastIndexOf("b"));
Console.WriteLine(B.Length);
Console.WriteLine(B.Remove(2));
Console.WriteLine(B.Replace("o","i"));
string[] Split = A.Split(new char[] { 'e' });
Console.WriteLine(Split[0]);
Console.WriteLine(Split[1]);
Console.WriteLine(B.StartsWith("H"));
Console.WriteLine(A.Substring(2,5));
Console.WriteLine(A.ToCharArray());
Console.WriteLine(A.Trim());
Console.ReadKey();
}
}
}
Output
Hello World
True
False
False
1411332840
System.String
String
1
hello world
HELLO WORLD
HaiHello World
True
-1
5
Wo
Wirld
H
llo World
False
llo W
Hello World
Hello World
Result
Thus the program was executed successfully and the output was verified.
EX NO: 12
Program containing a List Box, a Button an Image
DATE: 26.04.2022 and Label
Aim
To write a program containing a list box, a button, an image and a label in ASP.Net.
Algorithm
Inherits System.Web.UI.Page
If (ListBox1.SelectedIndex = 0) Then
Image1.ImageUrl = ".\images\bangles1.jfif"
Image1.ImageUrl = ".\images\chain1.jfif"
Image1.ImageUrl = ".\images\goldchain.jfif"
Image1.ImageUrl = ".\images\jummki.jfif"
Image1.ImageUrl = ".\images\kolusu.jfif"
End If
End Sub
Label1.Text = ListBox1.SelectedValue
End Sub
End Class
Output
Result
Thus the program was executed successfully and the output was verified.
EX NO: 13
Validation Control
DATE: 04.05.2022
Aim
Algorithm
Thus the program was executed successfully and the output was verified.
EX NO: 14
Web Server Control
DATE: 11.05.2022
Aim
Algorithm
Button Click
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
usingSystem.Web.UI.WebControls;
namespace WebApplication10
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Button_Click(object sender, EventArgs e)
{
String name = TextBox1.Text;
String email = TextBox2.Text;
String course = Textbox3.Text;
String gender = "";
String Sports="";
if(RadioButton1.Checked)
gender=RadioButton1.Text;
else
gender=RadioButton2.Text;
if(CheckBox1.Checked)
Sports=CheckBox1.Text+"";
if(CheckBox2.Checked)
Sports=CheckBox2.Text+"";
if(CheckBox3.Checked)
Sports=CheckBox3.Text+"";
if(CheckBox4.Checked)
Sports=CheckBox4.Text+"";
Label1.Text="Name:"+name;
Label2.Text="Email id:"+email;
Label3.Text="Course:"+course;
Label4.Text="Gender:"+gender;
Label5.Text="sports:"+Sports;
}
}
Output
Result
Thus the program was executed successfully and the output was verified.
EX NO: 15
Develop a basic windows
DATE: 18.05.2022 phone application
Aim
To develop a basic windows phone Application.
Algorithm
Result
Thus the application ran succuessfully and the output was verified.