[Link].
1
Date :
SORTING
Aim:
To write a C# program for sorting list of numbers.
Algorithm:
Step 1: Start the process.
Step 2: Get the list of numbers from the users.
Step 3: Sort the numbers using array.
Step 4: Display the sorted numbers.
Step 5: Stop the process.
Program:
using System;
using [Link];
using [Link];
namespace sorting
{
class Program
{
static void Main(string[] args)
{
[Link]("Enter No of Elements :");
int n = [Link]([Link]());
int[] arr = new int[n];
int i,j,temp;
for (i = 0; i < n; i++)
{
[Link]("Enter value for Element arr[{0}] : ",i);
arr[i] = [Link]([Link]() );
}
[Link]();
[Link]("\nUnsorted List");
foreach (int x in arr)
{
[Link](" {0} ", x);
}
[Link]();
for(i=0 ;i<n;i++)
for(j=i;j<n;j++)
1
if (arr[i] > arr[j])
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
[Link]("\nSorted List");
foreach (int x in arr)
{
[Link](" {0} ", x);
}
[Link]();
[Link]();
}
}
}
Output
Result
Thus C# program for sorting list of numbers is sorted successfully.
2
[Link].2
Date.
FLOYDS TRIANGLE
Aim:
To write a C# program for displaying Floyds triangle.
Algorithm:
Step 1: Start the process.
Step 2: Get the number of line from the users
Step 3: Print the ones and zeros alternatively.
Step 4: Display the lines such a way that forms of triangle.
Step 5: Stop the process.
Program:
using System;
using [Link];
using [Link];
namespace ftriangle
{
class Program
{
static void Main(string[] args)
{
int n=5, i, j;
[Link]("N=");
n = [Link]([Link]() );
for (i = 1; i <= n; i++)
{
for (j = i; j>0; j--)
[Link]("{0} ", (j % 2));
[Link]();
}
[Link]();
3
for (i = n; i>=0; i--)
{
for (j = i; j > 0; j--)
[Link]("{0} ", (j % 2));
[Link]();
} } }}
Output
Result
Thus a C# program for Floyds triangle is displayed successfully.
4
[Link].3
Date
STUDENT DETAILS USING CLASS
Aim:
To write a C# program for the student details using class.
Algorithm:
Step 1: Start the process.
Step 2: Get the inputs related to the students.
Step 3: Calculate the total marks.
Step 4: Calculate the average.
Step 5: Calculate the result whether it is pass or fail.
Step 6: Display the result.
Step 7: Stop the process.
Program:
using System;
using [Link];
using [Link];
namespace studetail
{
class Program
{
static void Main(string[] args)
{
Stu o = new Stu();
[Link]();
[Link]();
}
}
class Stu
{
long Regno;
5
int Eng, Tam, Mat;
float Total, Avg;
public bool pf;
public Stu()
{
pf = false;
Eng = Tam = Mat = 0;
Total = Avg = 0;
}
void StuResult()
{
if (Eng >= 50 && Tam >= 50 && Mat >= 50)
pf = true;
}
void StuTotal()
{
Total = Eng + Tam + Mat;
}
void StuAvg()
{
Avg = ((Eng + Tam + Mat)/3.0f);
}
public void Idata()
{
[Link]("Enter The Reg No. : ");
Regno = [Link]([Link]());
[Link]("\nEnter English Mark : ");
Eng = [Link]([Link]());
[Link]("\nEnter Tamil Mark : ");
Tam = [Link]([Link]());
[Link]("\nEnter Maths Mark : ");
Mat = [Link]([Link]());
}
public void Odata() {
StuResult();
6
StuTotal();
StuAvg();
[Link]();
[Link]("Regno :{0}", Regno);
[Link]("English :{0}", Eng);
[Link]("Tamil :{0}", Tam);
[Link]("Maths :{0}", Mat);
[Link]("Result :{0}",(pf ? "Pass" :"Fail" ));
if (pf)
{ [Link]("\nTotal :{0}", Total );
[Link]("\nAvg :{0}", Avg);
} } }}
Output
Result
Thus a C# program for the student details using class is done successfully.
7
[Link].4
Date
STRUCTURES
Aim:
To write a C# program to find out volumes of rectangle and square using
structures.
Algorithm:
Step 1: Start the process.
Step 2: Declare a shape structure to calculate area and volume.
Step 3: Get the inputs for rectangle.
Step 4: Calculate the area and volume for rectangle.
Step 5: Get the inputs for square.
Step 6: Calculate the area and volume for square.
Step 7: Display the results.
Step 8: Stop the process.
Program:
using System;
using [Link];
using [Link];
namespace ssss
{ struct shape
{ int l, b, h, s;
public shape(int i)
{ [Link]("l=");
l = [Link]([Link]());
[Link]("b=");
b = [Link]([Link]());
[Link]("h=");
h = [Link]([Link]());
[Link]("s=");
8
s = [Link]([Link]()); }
public int Rectarea()
{ return (l * b); }
public int Rectvolume()
{ return (l * b * h); }
public int sqrarea()
{ return (s*s); }
public int sqrvolume()
{ return (s * s * s); }
public void Display()
{ [Link]("\n\nRectancle\n~~~~~~~~~\nArea = " + Rectarea());
[Link]("Volume = " + Rectvolume());
[Link]("\n\nSquare\n~~~~~~\nArea =" + sqrarea());
[Link]("Volume=" + sqrvolume());
} }
class Testrectangle
{ public static void Main()
{ shape shaba = new shape(0);
[Link](); } }}
Output
Result
Thus a C# program is to find out volumes of rectangle and square is created
successfully using structures.
9
[Link].5
Date
ENUMERATOR
Aim:
To Write a C# program to find out the shape of the area using enumerator.
Algorithm:
Step 1: Stat the process.
Step 2: Declare the circle of the area.
Step 3: Declare the square of the area.
Step 4: Display using switch case.
Step 5: Display the output.
Step 6: Stop the process.
Program:
using System;
using [Link];
using [Link];
namespace enumerator
{
class Area
{
public enum Shape
{
Circle, Square
}
public void AreaShape (int x, Shape shape)
{
double area;
switch (shape)
{
case [Link]:
area = [Link] * x*x;
10
[Link]("\nCircle Area = " + area);
break;
case [Link]:
area = x*x;
[Link]("\nSquare Area = " + area);
break;
default:
[Link]("\nInvalied Input\n");
break;
}
}
}
class Enumtest
{
public static void Main()
{
[Link]("Enter the value of n =");
int n = [Link]([Link]());
Area area = new Area();
[Link](n,[Link]);
[Link](n,[Link]);
[Link](n,([Link]) 1);
[Link](n,([Link]) 10);
}
}
}
11
Output
Result
Thus a C# program is to find out the shape of the area is created successfully
using enumerator.
[Link].6
12
Date.
INHERITANCE
Aim:
To write a C# program calculate sum and average using inheritance.
Algorithm:
Step 1: Start the process.
Step 2: Get the list of numbers from the users.
Step 3: Define the array for the list of numbers.
Step 4: Find out sum and average to the list of numbers.
Step 5: Print the result.
Step 6: Stop the process.
Program:
using System;
using [Link];
using [Link];
namespace Int
{
class Program
{
static void Main(string[] args)
{
B o = new B();
[Link]();
[Link]();
[Link]();
} }
class A
{
protected int[] arr = new int[5];
protected int sum;
public A()
13
{ sum = 0; }
public void Idata()
{ int i = 0;
for (i = 0; i < 5; i++)
{
[Link]("Enter the value of Element {0}/{1}=", (i + 1), 5);
arr[i] = [Link]([Link]());
} } }
class B : A
{ float avg=0;
public void calc()
{ int i;
for (i = 0; i < 5; i++)
{ sum = sum + arr[i]; }
avg = sum / 5.0f;
}
public void Odata()
{ [Link]("\n\nArray List");
[Link]("~~~~~~~~~~\n");
for (int i = 0; i < 5; i++)
[Link](" {0}",arr[i]);
[Link]("\n\nSum : {0}\n", sum);
[Link]("\nAvg : {0}\n", avg);
}
}
}
14
Output
Result
Thus a C# program of sum and average is calculated successfully using
inheritance.
15
[Link].7
Date.
POLYMORPHISM
Aim:
To write a C# program for calculating area and volume of shape using
overriding in polymorphism.
Algorithm:
Step 1: Start the process.
Step 2: Get data of square and rectangle
Step 3: Calculate the area and volume of square.
Step 4: Calculate the area and volume of rectangle.
Step 5: Print the result.
Step 6: Stop the process.
Program:
using System;
using [Link];
using [Link];
namespace poly
{
class Program
{
static void Main(string[] args)
{
Sqr s = new Sqr(50f);
[Link]();
[Link]();
Rect o = new Rect(10f, 20f, 30f);
[Link]();
[Link]();
} }
class Sqr
16
{ protected float a;
float area,vol;
public Sqr() { }
public Sqr(float x)
{ a = x; }
public virtual void Calc ()
{ area = a * a;
vol = a*a*a ; }
public virtual void Odata()
{
[Link]("\n\nSide of Square is {0}.", a);
[Link]("\n\nVolume of square is {0}.", vol);
[Link]("\n\nArea of Square is {0}.", area);
}
}
class Rect : Sqr
{
float area, vol,l,b,w;
public Rect() { }
public Rect(float x, float y,float z):base(x)
{ l = x; b = y; w = z; }
public override void Calc()
{ area = l * b;
vol = l * b * w;
[Link](); }
public override void Odata()
{ [Link]("\n\nRect \n~~~~\nl={0}\nb={1}\nw={2} ", l,b,w);
[Link]("\n\nRect Volume is {0}.", vol);
[Link]("\n\nRect Area is {0}.", area);
[Link](); } }}
17
Output
Result
Thus a C# program for area and volume of shape is calculated successfully
using overriding in polymorphism.
18
[Link].8
Date
OPERATOR OVERLOADING
Aim:
To write a C# program using Operator Overloading.
Algorithm:
Step 1: Start the process.
Step 2: Create an operator overloading in a class for addition and subtraction.
Step 3: Get the input form the user.
Step 4: Call the operator overloading functions using objects.
Step 5: Display the output of addition and subtraction.
Step 6: Stop the process.
Program:
using System;
using [Link];
using [Link];
namespace operator_overloading
{ class Complex
{
double x;
double y;
public Complex() { }
public Complex(double real, double img)
{ x = real;
y = img; }
public static Complex operator +(Complex c1, Complex c2)
{ Complex c3 = new Complex();
c3.x = c1.x + c2.x;
c3.y = c1.y + c2.y;
return (c3); }
public static Complex operator -(Complex c1, Complex c2)
19
{ Complex c3 = new Complex();
c3.x = c1.x - c2.x;
c3.y = c1.y - c2.y;
return (c3); }
public void Display()
{ [Link]("\nX="+x);
[Link]("\nY="+ y);
[Link]();
} }
class ComplexTest
{
public static void Main()
{
Complex a, b, c,d;
a = new Complex(5.5, 3.5);
b = new Complex(4.5, 6.5);
c = a + b;
[Link]("\n\nObject a:");
[Link]();
[Link]("\n\nObject b:");
[Link]();
[Link]("\n\nAdd Object c:");
[Link]();
d = a - b;
[Link]("\n\nSub Object d:");
[Link]();
}
}
}
20
Output
Result
Thus a C# program using Operator Overloading is created successfully.
21
[Link].9
Date.
WINDOWS APPLICATION
Aim:
To write a C# program for calculator using windows form designs.
Algorithm:
Step 1: Start the process.
Step 2: Design the form using tools as calculator.
Step 3: Define the functionalities to the each element in the form.
Step 4: Check the functions of the calculator.
Step 5: Stop the process.
Program:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace win
{
public partial class Form1 : Form
{
int op;
public Form1()
{ InitializeComponent(); }
private void button3_Click(object sender, EventArgs e)
{ clacinput(3); }
private void button1_Click(object sender, EventArgs e)
{ clacinput(1); }
22
private void clacinput(int n)
{
if ([Link] == "")
[Link] = [Link]() ;
else
[Link] = (([Link]([Link]) * 10) + n).ToString();
}
private void button2_Click(object sender, EventArgs e)
{ clacinput(2); }
private void button4_Click(object sender, EventArgs e)
{ clacinput(4); }
private void button5_Click(object sender, EventArgs e)
{ clacinput(5); }
private void button6_Click(object sender, EventArgs e)
{ clacinput(6); }
private void button7_Click(object sender, EventArgs e)
{ clacinput(7); }
private void button8_Click(object sender, EventArgs e)
{ clacinput(8); }
private void button9_Click(object sender, EventArgs e)
{ clacinput(9); }
private void button10_Click(object sender, EventArgs e)
{ [Link] = "0"; }
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the '[Link]' table. You can
move, or remove it, as needed.
[Link] = "0";
}
private void button12_Click(object sender, EventArgs e)
{ [Link] = [Link];
[Link] = "0";
op = 0;
}
private void button13_Click(object sender, EventArgs e)
23
{
if (op == 0)
{
[Link] = ([Link]([Link]) + [Link]([Link])).ToString();
[Link] = "";
}
if (op == 1)
{
[Link] = ([Link]([Link]) - [Link]([Link])).ToString();
[Link] = "";
}
if (op == 2)
{
[Link] = ([Link]([Link]) * [Link]([Link])).ToString();
[Link] = "";
}
if (op == 3)
{
[Link] = ([Link]([Link]) / [Link]([Link])).ToString();
[Link] = "";
}
}
private void button14_Click(object sender, EventArgs e)
{
[Link] = [Link];
[Link] = "0";
op = 3;
}
private void button15_Click(object sender, EventArgs e)
{
[Link] = [Link];
[Link] = "0";
op = 1;
}
24
private void button16_Click(object sender, EventArgs e)
{
[Link] = [Link];
[Link] = "0";
op = 2;
}
private void button11_Click(object sender, EventArgs e)
{
[Link] = "";
[Link] = "0";
}
private void button17_Click(object sender, EventArgs e)
{
[Link] = ([Link]([Link]) * 10).ToString();
}
}
}
Output
25
Result
Thus a C# program for calculator using windows form designs is done
successfully.
26
[Link].10
Date
DATABASE CONNECTION
Aim:
To write a C# program for connect a database using student details.
Algorithm:
Step 1: Start the process.
Step 2: Open the new windows application form.
Step 3: Create the database using SQL database.
Step 4: Create the new database table.
Step 5: Connect to the database and table.
Step 6: Display the table.
Step 7: Stop the process.
Form Design
27
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace db
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void studBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
[Link]();
[Link]();
[Link]([Link]);
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the '[Link]' table. You can
move, or remove it, as needed.
[Link]([Link]);
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
[Link] =( [Link]([Link]) + [Link]([Link]) +
[Link]([Link])).ToString() ;
[Link] = ([Link]([Link])/3.0f).ToString();
}
private void totalTextBox_TextChanged(object sender, EventArgs e)
{ } }}
28