SlideShare a Scribd company logo
1 of 31
BRANCHING AND LOOPING
EX.NO:1
Date :
AIM:
To write a C# program using Branching and Looping statements.
ALGORITHM:
Steps:
1. Start the program.
2. Declare the required variables.
3. Using for loop print i values.
4. Check the condition using if.
5. If the condition is true exit the loop and print the result.
6. If the condition is false check the for loop using “continue”.
7. Stop the process.
PROGRAM:
using System;
using System.Collections.Generic;
using System.Text;
namespace branch
{
class Program
{
static void Main(string[] args)
{
int i;
for(i=1;i<10;i++)
{
Console.WriteLine ("i={0}",i);
if(i>=5)
goto loopst;
else
continue ;
loopst:{break;}
} Console.Read();
}
}
}
OUTPUT:
i=1
i=2
i=3
i=4
i=5
RESULT:
Thus the program is compiled and executed successfully and the results are
obtained.
ARRAY, STRINGS & METHODS
EX.NO:2
Date :
AIM:
To write a C# program using Arrays and Strings methods.
ALGORITHM:
Steps:
1. Start the program.
2. Declare the array and string variables.
3. Create a method named getnames()
4. Get the input from user .
5. Create another method named shownames()
6. Using for loop display all names.
7. Create an object.
8. Using the object call all the methods.
9. Print the result.
10. Stop the process.
PROGRAM:
using System;
using System.Collections.Generic;
using System.Text;
namespace array1
{
class Program
{
private string[] names = new string[5];
void getnames()
{
for (int i = 0; i < names.Length; i++)
{
Console.Write("enter name[{0}]:", i);
names[i] = Console.ReadLine();
}
}
void shownames()
{
for (int i = 0; i < names.Length; i++)
{
Console.WriteLine("names[{0}]={1}"
, i, names[i]);
}
}
static void Main(string[] args)
{
Program obj = new Program ();
obj.getnames();
obj.shownames();
Console.Read();
}
}
}
OUTPUT:
Enter name[0]:gopi
Enter name[1]:logu
Enter name[2]:ravi
Enter name[3]:ragu
Enter name[4]:aravindhan
names[0]:gopi
names[1]:logu
names[2]:ravi
names[3]:ragu
names[4]:aravindhan
RESULT:
Thus the program is compiled and executed successfully and the results are
obtained.
STRUCTURES & ENUMERATIONS
EX.NO:3
Date :
AIM:
To write a C# program using Structures and enumerations
ALGORITHM:
Steps:
1. Start the program.
2. Declare the required data types and declare enumeration as months.
3. Declare the constructor.
4. Create an object for class.
5. Create the structure and call the enumeration.
6. Display the result.
7. Stop the process
PROGRAM:
using System;
using System.Collections.Generic;
using System.Text;
namespace mns
{
class ex3
{
int classvar;
int anothervar=20;
enum months { January=31,february=28,March=31 };
public ex3()
{
classvar=28;
}
public static void Main()
{
ex3 e=new ex3();
examplestruct strct=new examplestruct(20);
Console.WriteLine(strct.i);
strct.i=10;
Console.WriteLine(e.classvar);
Console.WriteLine(strct.i);
strct.trial();
months m=(mns.ex3.months)28;
Console.WriteLine("{0}",m);
Console.Read();
}
}
struct examplestruct
{
public int i;
public examplestruct(int j)
{
i=j;
}
public void trial()
{
Console.WriteLine("Inside Trial Method");
}
}
}
OUTPUT:
20
28
10
Inside Trial Method
february
RESULT:
Thus the program is compiled and executed successfully and the results are
obtained.
INHERITANCE
EX.NO:4
Date :
AIM:
To write a C# program using inheritance concepts.
ALGORITHM:
Steps:
1. Start the program.
2. Create a class named room and declare the required variables and
methods.
3. Create a sub class named bed and declare the required variables .
4. Create an object for the sub class.
5. Using the object call the methods and functions.
6. Display the result.
7. Stop the program
PROGRAM:
using System;
using System.Collections.Generic;
using System.Text;
class room
{
public int length;
public int breadth;
public room(int x,int y)
{
length=x;
breadth=y;
}
public int area()
{
return(length*breadth);
}
}
class br:room
{
int height;
public br(int x,int y,int z):base(x,y)
{
height=z;
}
public int volume()
{
return(length*breadth*height);
}
}
class ex4
{
public static void Main()
{
br r1=new br(14,12,10);
int area1=r1.area();
int volume1=r1.volume();
Console.WriteLine("Area : "+area1);
Console.WriteLine("Volume : "+volume1);
}
}
OUTPUT:
Area:168
Volume:1680
RESULT:
Thus the program is compiled and executed successfully and the results are
obtained.
POLYMORPHISM
EX.NO:5
Date :
AIM:
To write a C# program using Polymorphism.
ALGORITHM:
Steps:
1. Start the program.
2. Create a base class named vehicle and declare the variables.
3. Create a derived class named automobile and perform the calculations.
4. Create a class and create an object for the derived class.
5. Call the methods using objects.
6. Display the result.
7. Stop the program.
PROGRAM:
using System;
using System.Collections.Generic;
using System.Text;
namespace polymorphismexample
{
class ex5
{
static void Main(string[] args)
{
Automobile a= new Automobile();
a.PowerSource="100 H.P";
a.IncreaseVelocity(60);
BMW car=new BMW();
car.Color("Black");
Console.WriteLine("press enter to exit...");
Console.ReadLine();
}
}
class vehicle
{
string VehiclePower=" ";
public string PowerSource
{
set
{
VehiclePower=value;
Console.WriteLine("power of engine is set to "{0}"
",val ue.ToString());
}
get
{
return VehiclePower;
}
}
public virtual void IncreaseVelocity(int i)
{
Console.WriteLine("The Speed Increases To "
"+i.ToString()+"m.p.h");
}
}
class Automobile:vehicle
{
public override void IncreaseVelocity(int i)
{
if(i>120)
{
i=120;
}
Console.WriteLine("Increasing Its Speed To "+i.ToString()+ " m.p.h");
}
public virtual void Color(string col)
{
col="Blue";
Console.WriteLine("The Color Of BMW is: ");
Console.WriteLine(col);
}
}
class BMW:Automobile
{
public override void Color(string col)
{
col="navy";
Console.WriteLine("The Color Of BMW is: ");
Console.WriteLine(col);
}
}
}
OUTPUT:
Power of engine is set to “100 H.P”
Increasing Its Speed To 60 m.p.h
The color of BMW is:
Navy
Press enter to exit..
RESULT:
Thus the program is compiled and executed successfully and the results
are obtained.
INTERFACES
EX.NO:6
Date :
AIM:
To write a c# program using interfaces.
ALGORITHM:
Steps:
1. Start the program
2. Create two interfaces and declare the required variables.
3. Create the class and implement the two interfaces.
4. Create objects for both class and interfaces.
5. Call the methods using objects.
6. Display the result.
7. Stop the program.
PROGRAM:
Using System;
namespace box
{
interface IEnglishDimension
{
float length();
float width();
}
interface IMetricDimension
{
float length();
float width();
}
class ex06:IEnglishDimension,IMetricDimension
{
float lengthinches;
float widthinches;
public ex06(float length,float width)
{
lengthinches=length;
widthinches=width;
}
float IEnglishDimension.length()
{
return lengthinches;
}
float IEnglishDimension.width()
{
return widthinches;
}
float IMetricDimension.length()
{
return lengthinches*2.54f;
}
float IMetricDimension.width()
{
return widthinches*2.54f;
}
public static void Main()
{
ex06 mybox=new ex06(30.0f,20.0f);
IEnglishDimension ed=(IEnglishDimension)mybox;
IMetricDimension md=(IMetricDimension)mybox;
Console.WriteLine("Length(in):{0}",ed.length());
Console.WriteLine("Width(in) :{0}",ed.width());
Console.WriteLine("Length(cm):{0}",md.length());
Console.WriteLine("Width(cm) :{0}",md.width());
Console.Read();
}
}
}
OUTPUT:
Length(in)=30
Width(in)=20
Length(cm)=76.2
Width(cm)=50.8
RESULT:
Thus the program is compiled and executed successfully and the results are
obtained.
OPERATOR OVERLOADING
EX.NO:7
Date :
AIM:
To write a C# program by using operator overloading.
ALGORITHM:
Steps:
1. Start the program.
2. Create a class named complex and declare the variables.
3. Create a constructor and assign the values to variables.
4. Write a function to implement operator overloading concept.
5. Create a class and create an object for the class complex.
6. Perform the calculations.
7. Display the result.
8. Stop the program.
PROGRAM:
using System;
using System.Collections.Generic;
using System.Text;
namespace overload1
{
class complex
{
double x;
double y;
public complex()
{
}
public complex(double real, double imag)
{
x = real;
y = imag;
}
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 void display()
{
Console.Write(x);
Console.Write(" " + y);
Console.WriteLine(" ");
}
}
class Program
{
static void Main(string[] args)
{
complex a, b, c;
a = new complex(2.5, 3.5);
b = new complex(1.6, 2.7);
c = a + b;
Console.Write("a =");
a.display();
Console.Write("b=");
b.display();
Console.Write("c=");
c.display();
Console.Read();
}
}
}
OUTPUT:
a=2.5 3.5
b=1.6 2.7
c=4.1 6.2
RESULT:
Thus the program is compiled and executed successfully and the results are
obtained.
DELEGATES, EVENTS, ERRORS AND EXCEPTIONS
EX.NO:8(a)
Date :
AIM:
To write a C# program using delegates, events, errors and exceptions.
ALGORITHM:
Steps:
1. Start the program.
2. Create a namespace and declare a delegate function.
3. Create a class named event class and declare the variables.
4. Create a function and check the status.
5. Create a class named event test and create object for both classes.
6. Call the methods using that objects.
7. Display the result.
8. Stop the program.
PROGRAM:
using System;
using System.Collections.Generic;
using System.Text;
namespace dele2
{
public delegate void EDelegate(String str);
class eventclass
{
public event EDelegate status;
public void TriggerEvent()
{
if(status!=null)
status("event triggered");
}
}
class ex8
{
public static void Main()
{
eventclass ec=new eventclass();
ex8 et=new ex8();
ec.status+=new EDelegate(et.EventCatch);
ec.TriggerEvent();
Console.Read();
}
public void EventCatch(string str)
{
Console.WriteLine(str);
}
}
}
OUTPUT:
Event triggered
EX.NO:8. (b)
AIM:
To write a C# program using Errors and Exceptions.
ALGORITHM:
Steps:
1. Start the program.
2. Create a namespace and declare Exception function.
3. Create a class name Exception class and declare the variables.
4. Create a try, catch, finally blocks functions.
5. Display the result.
6. Stop the program.
PROGRAM:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
try
{
Decimal dresult = Decimal.Divide(5, 0);
Console.WriteLine("Result is :{0}", dresult);
}
//catch (ArithmeticException exarith)
//{
// Console.WriteLine("Caught Arithmetic Exception : {0}",
// exarith.Message);
//}
catch (DivideByZeroException exdiv)
{
Console.WriteLine("Caught Divide By Zero Exception : {0}",
exdiv.Message);
}
catch (Exception ex)
{
Console.WriteLine("Caught Exception : {0}", ex.Message);
}
finally
{
Console.WriteLine("In Finally");
}
}
}
}
OUTPUT:
Caught Divide By Zero Exception: Attempted to divide by zero.
In Finally
Press any key to continue . . .
RESULT:
Thus the program is compiled and executed successfully and the results are
obtained.
CALCULATOR WIDGET
EX.NO:9
Date :
AIM:
To build a calculator widget in windows application using C#.
ALGORITHM:
Steps:
1. Create a windows application using C#.
2. Design the form with buttons and textbox like a calculator.
3. Name the buttons using property window.
3. Write the code for each button.
4. Build the application.
5. Display the result.
6. Stop the program
PROGRAM:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class frmcalc : Form
{
private string s1, s2, oper;
private bool isoper;
public frmcalc()
{
InitializeComponent();
s1 = s2 = oper = " ";
isoper = true;
}
private void button17_Click(object sender, EventArgs e)
{
s1 = s2 = oper = " ";
isoper = true;
txtResult.Text = s1;
this.dot.Enabled = false;
}
private void zero_Click(object sender, EventArgs e)
{
s1 += "0";
txtResult.Text = s1;
}
private void one_Click(object sender, EventArgs e)
{
s1 += "1";
txtResult.Text = s1;
}
private void two_Click(object sender, EventArgs e)
{
s1 += "2";
txtResult.Text = s1;
}
private void three_Click(object sender, EventArgs e)
{
s1 += "3";
txtResult.Text = s1;
}
private void four_Click(object sender, EventArgs e)
{
s1 += "4";
txtResult.Text = s1;
}
private void five_Click(object sender, EventArgs e)
{
s1 += "5";
txtResult.Text = s1;
}
private void six_Click(object sender, EventArgs e)
{
s1 += "6";
txtResult.Text = s1;
}
private void seven_Click(object sender, EventArgs e)
{
s1 += "7";
txtResult.Text = s1;
}
private void eight_Click(object sender, EventArgs e)
{
s1 += "8";
txtResult.Text = s1;
}
private void div_Click(object sender, EventArgs e)
{
oper = "/";
s2 = s1;
s1 = null;
txtResult.Text = oper;
isoper = true;
this.dot.Enabled = true;
}
private void mul_Click(object sender, EventArgs e)
{
oper = "*";
s2 = s1;
s1 = null;
txtResult.Text = oper;
isoper = true;
this.dot.Enabled = true;
}
private void sub_Click(object sender, EventArgs e)
{
oper = "-";
s2 = s1;
s1 = null;
txtResult.Text = oper;
isoper = true;
this.dot.Enabled = true;
}
private void nine_Click(object sender, EventArgs e)
{
s1 += "9";
txtResult.Text = s1;
}
private void add_Click(object sender, EventArgs e)
{
oper = "+";
s2 = s1;
s1 = null;
txtResult.Text = oper;
isoper = true;
this.dot.Enabled = true;
}
private void dot_Click(object sender, EventArgs e)
{
if (isoper)
{
s1 += ".";
this.dot.Enabled = false;
isoper = false;
txtResult.Text = s1;
}
}
private void equal_Click(object sender, EventArgs e)
{
float n1, n2, res = 0.0f;
n1 = float.Parse(s2);
n2 = float.Parse(s1);
switch (oper)
{
case "+":
res = n1 + n2;
break;
case "-":
res = n1 - n2;
break;
case "*":
res = n1 * n2;
break;
case "/":
res = n1 / n2;
break;
}
this.txtResult.Text = res.ToString();
isoper = true;
}
private void QUIT_Click(object sender, EventArgs e)
{
MessageBox.Show("See You Again", "Thank You");
this.Close();
}
}
}
OUTPUT:
RESULT:
Thus the program is compiled and executed successfully and the results are
obtained.
MULTI MODULE ASSEMBLY
EX.NO:10
Date :
AIM:
To write a C# program using multi module Assembly.
ALGORITHM:
Step 1 — Compiling Files with Namespaces Referenced by Other Files
csc /t:module Stringer.cs
Specifying the module parameter with the /t: compiler option indicates that
the file should be compiled as a module rather than as an assembly. The compiler
produces a module called Stringer.netmodule, which can be added to an assembly
Step 2 — Compiling Modules with References to Other Modules
csc /addmodule:Stringer.netmodule /t:module Client.cs
Specify the /t:module option because this module will be added to an
assembly in a future step. Specify the /addmodule option because the code in
Client references a namespace created by the code in Stringer.netmodule.
The compiler produces a module called Client.netmodule that contains a
reference to another module, Stringer.netmodule.
Step 3 — Creating a Multifile Assembly Using the Assembly Linker
al Client.netmodule Stringer.netmodule
/main:MainClientApp.Main /out:myAssembly.exe /target:exe
You can use the MSIL Disassembler (Ildasm.exe) to examine the contents
of an assembly, or determine whether a file is an assembly or a module.
PROGRAM:
Stringer.cs
using System;
namespace myStringer
{
public class Stringer
{
public void StringerMethod()
{
System.Console.WriteLine("This is a line from
StringerMethod.");
}
}
}
Client.cs
using System;
using myStringer;
class MainClientApp
{
public static void Main()
{
Stringer myStringInstance = new Stringer();
Console.WriteLine("Client code executes");
myStringInstance.StringerMethod();
}
}
Compile:
C:WINNT>cd microsoft.net
C:WINNTMicrosoft.NET>cd framework
C:WINNTMicrosoft.NETFramework>cd v2.0.50727
C:WINNTMicrosoft.NETFrameworkv2.0.50727>edit Stringer.cs
C:WINNTMICROS~1.NETFRAMEW~1V20~1.507>csc /t:module Stringer.cs
C:WINNTMICROS~1.NETFRAMEW~1V20~1.507>csc
/addmodule:Stringer.netmodule /t:module Client.cs
C:WINNTMICROS~1.NETFRAMEW~1V20~1.507>al Client.netmodule
Stringer.netmodule /main:MainClientApp.Main /out:myAssembly.exe
/target:exe
C:WINNTMICROS~1.NETFRAMEW~1V20~1.507>
OUTPUT:
RESULT:
Thus the program is compiled and executed successfully and the results are
obtained.
APPLICATION DEVELOPMENT ON .NET
EX.NO:11
Date :
AIM:
To write a application using Windows Forms .
ALGORITHM:
Steps:
1. Create a windows application using C#.
2. Design the form with buttons and textbox like a calculation forms.
3. Name the buttons using property window.
3. Write the code for each button.
4. Build the application.
5. Display the result.
6. Stop the program
PROGRAM:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WAArith
{
public partial class frmArith : Form
{
public frmArith()
{
InitializeComponent();
}
private void optAdd_CheckedChanged(object sender, EventArgs e)
{
try
{
txtResult.Text =
Convert.ToString(Convert.ToSingle(txtN1.Text) +
Convert.ToSingle(txtN2.Text));
}
catch (Exception er)
{
MessageBox.Show(er.Message);
}
}
private void optSub_CheckedChanged(object sender, EventArgs e)
{
txtResult.Text = Convert.ToString(Convert.ToSingle(txtN1.Text) -
Convert.ToSingle(txtN2.Text));
}
private void optMul_CheckedChanged(object sender, EventArgs e)
{
txtResult.Text = Convert.ToString(Convert.ToSingle(txtN1.Text)
* Convert.ToSingle(txtN2.Text));
}
private void optDiv_CheckedChanged(object sender, EventArgs e)
{
txtResult.Text = Convert.ToString(Convert.ToSingle(txtN1.Text) /
Convert.ToSingle(txtN2.Text));
}
private void cmdRepeat_Click(object sender, EventArgs e)
{
txtN1.Text = "";
txtN2.Text = "";
txtResult.Text = "";
txtN1.Focus();
}
private void btnExit_Click(object sender, EventArgs e)
{
MessageBox.Show("Bye to you");
this.Close();
}
private void tmrTime_Tick(object sender, EventArgs e)
{
string st;
st = Convert.ToString((DateTime.Now).Hour) +
":";
st += Convert.ToString((DateTime.Now).Minute) +
":";
st += Convert.ToString ((DateTime.Now).Second);
this.Text = st;
}
private void button1_Click(object sender, EventArgs e)
{
ofdlg.ShowDialog();
picStart.ImageLocation = ofdlg.FileName;
cdlg.ShowDialog();
groupBox1.BackColor = Color.Red;
}
}
}
OUTPUT:
RESULT:
Thus the program is compiled and executed successfully and the results are
obtained.
WEB APPLICATIONS
EX.NO:12
Date :
AIM:
ALGORITHM:
Steps:
1. Enter into the Microsoft Visual studio 2005.
2. Create a new project based on ASP.NET website.[File->New-
>Website->ASP.NET Website].
3. Enter into the design of the page.
4. Type the text in the design page.
5. Double click on “access data source” icon under the data toolbox.
6. Click on configure data source.
7. Type the specified database path and finally click finish.
8. Place the control data grid view from the data toolbox.
9. Set accessdatasource1 to the data source property of the data grid view.
10. Save and run the website.
PROGRAM:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
if (this.txtFruit.Text != "")
{
lstFruits.Items.Add(txtFruit.Text);
txtFruit.Text = "";
txtFruit.Focus();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (this.lstFruits.Items.Count != 0 && lstFruits.SelectedIndex != -1)
lstFruits.Items.Remove(lstFruits.SelectedItem);
}
protected void txtselFruit_TextChanged(object sender, EventArgs e)
{
}
protected void lstFruits_SelectedIndexChanged(object sender, EventArgs
e)
{
txtselFruit.Text = lstFruits.SelectedItem.Text;
}
}
OUTPUT:
RESULT:
Thus the program is compiled and executed successfully and the results are
obtained.

More Related Content

What's hot

C#.net
C#.netC#.net
C#.netvnboghani
 
Csphtp1 09
Csphtp1 09Csphtp1 09
Csphtp1 09HUST
 
The Ring programming language version 1.5.1 book - Part 175 of 180
The Ring programming language version 1.5.1 book - Part 175 of 180 The Ring programming language version 1.5.1 book - Part 175 of 180
The Ring programming language version 1.5.1 book - Part 175 of 180 Mahmoud Samir Fayed
 
Bijender (1)
Bijender (1)Bijender (1)
Bijender (1)Ankush Kumar
 
1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professionalIsabella789
 
Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output) Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output) Aman Deep
 
Technical questions for interview c programming
Technical questions for interview  c programmingTechnical questions for interview  c programming
Technical questions for interview c programmingCHANDAN KUMAR
 
Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manualSANTOSH RATH
 
CS6311- PROGRAMMING & DATA STRUCTURE II LABORATORY
CS6311- PROGRAMMING & DATA STRUCTURE II LABORATORYCS6311- PROGRAMMING & DATA STRUCTURE II LABORATORY
CS6311- PROGRAMMING & DATA STRUCTURE II LABORATORYRadha Maruthiyan
 

What's hot (18)

29. Treffen - Tobias Meier - TypeScript
29. Treffen - Tobias Meier - TypeScript29. Treffen - Tobias Meier - TypeScript
29. Treffen - Tobias Meier - TypeScript
 
C#.net
C#.netC#.net
C#.net
 
Muzzammilrashid
MuzzammilrashidMuzzammilrashid
Muzzammilrashid
 
Qno 1 (c)
Qno 1 (c)Qno 1 (c)
Qno 1 (c)
 
Csphtp1 09
Csphtp1 09Csphtp1 09
Csphtp1 09
 
C++ file
C++ fileC++ file
C++ file
 
Dsprograms(2nd cse)
Dsprograms(2nd cse)Dsprograms(2nd cse)
Dsprograms(2nd cse)
 
C program
C programC program
C program
 
The Ring programming language version 1.5.1 book - Part 175 of 180
The Ring programming language version 1.5.1 book - Part 175 of 180 The Ring programming language version 1.5.1 book - Part 175 of 180
The Ring programming language version 1.5.1 book - Part 175 of 180
 
Bijender (1)
Bijender (1)Bijender (1)
Bijender (1)
 
1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional
 
Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output) Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output)
 
Technical questions for interview c programming
Technical questions for interview  c programmingTechnical questions for interview  c programming
Technical questions for interview c programming
 
Cs practical file
Cs practical fileCs practical file
Cs practical file
 
Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manual
 
Java file
Java fileJava file
Java file
 
CS6311- PROGRAMMING & DATA STRUCTURE II LABORATORY
CS6311- PROGRAMMING & DATA STRUCTURE II LABORATORYCS6311- PROGRAMMING & DATA STRUCTURE II LABORATORY
CS6311- PROGRAMMING & DATA STRUCTURE II LABORATORY
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
 

Similar to 39927902 c-labmanual

Java practical
Java practicalJava practical
Java practicalwilliam otto
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfmayorothenguyenhob69
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manualsameer farooq
 
Net practicals lab mannual
Net practicals lab mannualNet practicals lab mannual
Net practicals lab mannualAbhishek Pathak
 
Java doc Pr ITM2
Java doc Pr ITM2Java doc Pr ITM2
Java doc Pr ITM2Aram Mohammed
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4Abed Bukhari
 
5 Rmi Print
5  Rmi Print5  Rmi Print
5 Rmi Printvaradasuren
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsMuhammadTalha436
 
Java Practical File Diploma
Java Practical File DiplomaJava Practical File Diploma
Java Practical File Diplomamustkeem khan
 
Java practical(baca sem v)
Java practical(baca sem v)Java practical(baca sem v)
Java practical(baca sem v)mehul patel
 
Csphtp1 07
Csphtp1 07Csphtp1 07
Csphtp1 07HUST
 

Similar to 39927902 c-labmanual (20)

Java programs
Java programsJava programs
Java programs
 
C# programs
C# programsC# programs
C# programs
 
Java practical
Java practicalJava practical
Java practical
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
Net practicals lab mannual
Net practicals lab mannualNet practicals lab mannual
Net practicals lab mannual
 
Java doc Pr ITM2
Java doc Pr ITM2Java doc Pr ITM2
Java doc Pr ITM2
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 
Java file
Java fileJava file
Java file
 
Java and j2ee_lab-manual
Java and j2ee_lab-manualJava and j2ee_lab-manual
Java and j2ee_lab-manual
 
C# Lab Programs.pdf
C# Lab Programs.pdfC# Lab Programs.pdf
C# Lab Programs.pdf
 
C# Lab Programs.pdf
C# Lab Programs.pdfC# Lab Programs.pdf
C# Lab Programs.pdf
 
5 Rmi Print
5  Rmi Print5  Rmi Print
5 Rmi Print
 
Dotnet 18
Dotnet 18Dotnet 18
Dotnet 18
 
ASP.NET
ASP.NETASP.NET
ASP.NET
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
 
Java Practical File Diploma
Java Practical File DiplomaJava Practical File Diploma
Java Practical File Diploma
 
Java practical(baca sem v)
Java practical(baca sem v)Java practical(baca sem v)
Java practical(baca sem v)
 
Csphtp1 07
Csphtp1 07Csphtp1 07
Csphtp1 07
 
P2
P2P2
P2
 

Recently uploaded

High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...Call Girls in Nagpur High Profile
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoĂŁo Esperancinha
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 

Recently uploaded (20)

High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 

39927902 c-labmanual

  • 1. BRANCHING AND LOOPING EX.NO:1 Date : AIM: To write a C# program using Branching and Looping statements. ALGORITHM: Steps: 1. Start the program. 2. Declare the required variables. 3. Using for loop print i values. 4. Check the condition using if. 5. If the condition is true exit the loop and print the result. 6. If the condition is false check the for loop using “continue”. 7. Stop the process. PROGRAM: using System; using System.Collections.Generic; using System.Text; namespace branch { class Program { static void Main(string[] args) { int i; for(i=1;i<10;i++) { Console.WriteLine ("i={0}",i); if(i>=5) goto loopst; else continue ; loopst:{break;} } Console.Read(); } } }
  • 2. OUTPUT: i=1 i=2 i=3 i=4 i=5 RESULT: Thus the program is compiled and executed successfully and the results are obtained.
  • 3. ARRAY, STRINGS & METHODS EX.NO:2 Date : AIM: To write a C# program using Arrays and Strings methods. ALGORITHM: Steps: 1. Start the program. 2. Declare the array and string variables. 3. Create a method named getnames() 4. Get the input from user . 5. Create another method named shownames() 6. Using for loop display all names. 7. Create an object. 8. Using the object call all the methods. 9. Print the result. 10. Stop the process. PROGRAM: using System; using System.Collections.Generic; using System.Text; namespace array1 { class Program { private string[] names = new string[5]; void getnames() { for (int i = 0; i < names.Length; i++) { Console.Write("enter name[{0}]:", i); names[i] = Console.ReadLine(); } } void shownames() { for (int i = 0; i < names.Length; i++) {
  • 4. Console.WriteLine("names[{0}]={1}" , i, names[i]); } } static void Main(string[] args) { Program obj = new Program (); obj.getnames(); obj.shownames(); Console.Read(); } } } OUTPUT: Enter name[0]:gopi Enter name[1]:logu Enter name[2]:ravi Enter name[3]:ragu Enter name[4]:aravindhan names[0]:gopi names[1]:logu names[2]:ravi names[3]:ragu names[4]:aravindhan RESULT: Thus the program is compiled and executed successfully and the results are obtained.
  • 5. STRUCTURES & ENUMERATIONS EX.NO:3 Date : AIM: To write a C# program using Structures and enumerations ALGORITHM: Steps: 1. Start the program. 2. Declare the required data types and declare enumeration as months. 3. Declare the constructor. 4. Create an object for class. 5. Create the structure and call the enumeration. 6. Display the result. 7. Stop the process PROGRAM: using System; using System.Collections.Generic; using System.Text; namespace mns { class ex3 { int classvar; int anothervar=20; enum months { January=31,february=28,March=31 }; public ex3() { classvar=28; } public static void Main() { ex3 e=new ex3(); examplestruct strct=new examplestruct(20); Console.WriteLine(strct.i); strct.i=10; Console.WriteLine(e.classvar); Console.WriteLine(strct.i); strct.trial(); months m=(mns.ex3.months)28; Console.WriteLine("{0}",m); Console.Read(); }
  • 6. } struct examplestruct { public int i; public examplestruct(int j) { i=j; } public void trial() { Console.WriteLine("Inside Trial Method"); } } } OUTPUT: 20 28 10 Inside Trial Method february RESULT: Thus the program is compiled and executed successfully and the results are obtained.
  • 7. INHERITANCE EX.NO:4 Date : AIM: To write a C# program using inheritance concepts. ALGORITHM: Steps: 1. Start the program. 2. Create a class named room and declare the required variables and methods. 3. Create a sub class named bed and declare the required variables . 4. Create an object for the sub class. 5. Using the object call the methods and functions. 6. Display the result. 7. Stop the program PROGRAM: using System; using System.Collections.Generic; using System.Text; class room { public int length; public int breadth; public room(int x,int y) { length=x; breadth=y; } public int area() { return(length*breadth); } } class br:room { int height; public br(int x,int y,int z):base(x,y) { height=z; } public int volume() { return(length*breadth*height);
  • 8. } } class ex4 { public static void Main() { br r1=new br(14,12,10); int area1=r1.area(); int volume1=r1.volume(); Console.WriteLine("Area : "+area1); Console.WriteLine("Volume : "+volume1); } } OUTPUT: Area:168 Volume:1680 RESULT: Thus the program is compiled and executed successfully and the results are obtained.
  • 9. POLYMORPHISM EX.NO:5 Date : AIM: To write a C# program using Polymorphism. ALGORITHM: Steps: 1. Start the program. 2. Create a base class named vehicle and declare the variables. 3. Create a derived class named automobile and perform the calculations. 4. Create a class and create an object for the derived class. 5. Call the methods using objects. 6. Display the result. 7. Stop the program. PROGRAM: using System; using System.Collections.Generic; using System.Text; namespace polymorphismexample { class ex5 { static void Main(string[] args) { Automobile a= new Automobile(); a.PowerSource="100 H.P"; a.IncreaseVelocity(60); BMW car=new BMW(); car.Color("Black"); Console.WriteLine("press enter to exit..."); Console.ReadLine(); } } class vehicle { string VehiclePower=" "; public string PowerSource { set { VehiclePower=value; Console.WriteLine("power of engine is set to "{0}" ",val ue.ToString()); }
  • 10. get { return VehiclePower; } } public virtual void IncreaseVelocity(int i) { Console.WriteLine("The Speed Increases To " "+i.ToString()+"m.p.h"); } } class Automobile:vehicle { public override void IncreaseVelocity(int i) { if(i>120) { i=120; } Console.WriteLine("Increasing Its Speed To "+i.ToString()+ " m.p.h"); } public virtual void Color(string col) { col="Blue"; Console.WriteLine("The Color Of BMW is: "); Console.WriteLine(col); } } class BMW:Automobile { public override void Color(string col) { col="navy"; Console.WriteLine("The Color Of BMW is: "); Console.WriteLine(col); } } } OUTPUT: Power of engine is set to “100 H.P” Increasing Its Speed To 60 m.p.h The color of BMW is: Navy Press enter to exit.. RESULT: Thus the program is compiled and executed successfully and the results are obtained.
  • 11. INTERFACES EX.NO:6 Date : AIM: To write a c# program using interfaces. ALGORITHM: Steps: 1. Start the program 2. Create two interfaces and declare the required variables. 3. Create the class and implement the two interfaces. 4. Create objects for both class and interfaces. 5. Call the methods using objects. 6. Display the result. 7. Stop the program. PROGRAM: Using System; namespace box { interface IEnglishDimension { float length(); float width(); } interface IMetricDimension { float length(); float width(); } class ex06:IEnglishDimension,IMetricDimension { float lengthinches; float widthinches; public ex06(float length,float width) { lengthinches=length; widthinches=width; } float IEnglishDimension.length() { return lengthinches; } float IEnglishDimension.width()
  • 12. { return widthinches; } float IMetricDimension.length() { return lengthinches*2.54f; } float IMetricDimension.width() { return widthinches*2.54f; } public static void Main() { ex06 mybox=new ex06(30.0f,20.0f); IEnglishDimension ed=(IEnglishDimension)mybox; IMetricDimension md=(IMetricDimension)mybox; Console.WriteLine("Length(in):{0}",ed.length()); Console.WriteLine("Width(in) :{0}",ed.width()); Console.WriteLine("Length(cm):{0}",md.length()); Console.WriteLine("Width(cm) :{0}",md.width()); Console.Read(); } } } OUTPUT: Length(in)=30 Width(in)=20 Length(cm)=76.2 Width(cm)=50.8 RESULT: Thus the program is compiled and executed successfully and the results are obtained.
  • 13. OPERATOR OVERLOADING EX.NO:7 Date : AIM: To write a C# program by using operator overloading. ALGORITHM: Steps: 1. Start the program. 2. Create a class named complex and declare the variables. 3. Create a constructor and assign the values to variables. 4. Write a function to implement operator overloading concept. 5. Create a class and create an object for the class complex. 6. Perform the calculations. 7. Display the result. 8. Stop the program. PROGRAM: using System; using System.Collections.Generic; using System.Text; namespace overload1 { class complex { double x; double y; public complex() { } public complex(double real, double imag) { x = real; y = imag; } public static complex operator +(complex c1, complex c2) { complex c3 = new complex(); c3.x = c1.x + c2.x; c3.y = c1.y + c2.y;
  • 14. return (c3); } public void display() { Console.Write(x); Console.Write(" " + y); Console.WriteLine(" "); } } class Program { static void Main(string[] args) { complex a, b, c; a = new complex(2.5, 3.5); b = new complex(1.6, 2.7); c = a + b; Console.Write("a ="); a.display(); Console.Write("b="); b.display(); Console.Write("c="); c.display(); Console.Read(); } } } OUTPUT: a=2.5 3.5 b=1.6 2.7 c=4.1 6.2 RESULT: Thus the program is compiled and executed successfully and the results are obtained.
  • 15. DELEGATES, EVENTS, ERRORS AND EXCEPTIONS EX.NO:8(a) Date : AIM: To write a C# program using delegates, events, errors and exceptions. ALGORITHM: Steps: 1. Start the program. 2. Create a namespace and declare a delegate function. 3. Create a class named event class and declare the variables. 4. Create a function and check the status. 5. Create a class named event test and create object for both classes. 6. Call the methods using that objects. 7. Display the result. 8. Stop the program. PROGRAM: using System; using System.Collections.Generic; using System.Text; namespace dele2 { public delegate void EDelegate(String str); class eventclass { public event EDelegate status; public void TriggerEvent() { if(status!=null) status("event triggered"); } } class ex8 { public static void Main() { eventclass ec=new eventclass(); ex8 et=new ex8(); ec.status+=new EDelegate(et.EventCatch); ec.TriggerEvent(); Console.Read(); } public void EventCatch(string str) {
  • 16. Console.WriteLine(str); } } } OUTPUT: Event triggered EX.NO:8. (b) AIM: To write a C# program using Errors and Exceptions. ALGORITHM: Steps: 1. Start the program. 2. Create a namespace and declare Exception function. 3. Create a class name Exception class and declare the variables. 4. Create a try, catch, finally blocks functions. 5. Display the result. 6. Stop the program. PROGRAM: using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { try { Decimal dresult = Decimal.Divide(5, 0); Console.WriteLine("Result is :{0}", dresult); }
  • 17. //catch (ArithmeticException exarith) //{ // Console.WriteLine("Caught Arithmetic Exception : {0}", // exarith.Message); //} catch (DivideByZeroException exdiv) { Console.WriteLine("Caught Divide By Zero Exception : {0}", exdiv.Message); } catch (Exception ex) { Console.WriteLine("Caught Exception : {0}", ex.Message); } finally { Console.WriteLine("In Finally"); } } } } OUTPUT: Caught Divide By Zero Exception: Attempted to divide by zero. In Finally Press any key to continue . . . RESULT: Thus the program is compiled and executed successfully and the results are obtained.
  • 18. CALCULATOR WIDGET EX.NO:9 Date : AIM: To build a calculator widget in windows application using C#. ALGORITHM: Steps: 1. Create a windows application using C#. 2. Design the form with buttons and textbox like a calculator. 3. Name the buttons using property window. 3. Write the code for each button. 4. Build the application. 5. Display the result. 6. Stop the program PROGRAM: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class frmcalc : Form { private string s1, s2, oper; private bool isoper; public frmcalc() { InitializeComponent(); s1 = s2 = oper = " "; isoper = true; } private void button17_Click(object sender, EventArgs e) { s1 = s2 = oper = " "; isoper = true; txtResult.Text = s1;
  • 19. this.dot.Enabled = false; } private void zero_Click(object sender, EventArgs e) { s1 += "0"; txtResult.Text = s1; } private void one_Click(object sender, EventArgs e) { s1 += "1"; txtResult.Text = s1; } private void two_Click(object sender, EventArgs e) { s1 += "2"; txtResult.Text = s1; } private void three_Click(object sender, EventArgs e) { s1 += "3"; txtResult.Text = s1; } private void four_Click(object sender, EventArgs e) { s1 += "4"; txtResult.Text = s1; } private void five_Click(object sender, EventArgs e) { s1 += "5"; txtResult.Text = s1; } private void six_Click(object sender, EventArgs e) { s1 += "6"; txtResult.Text = s1; } private void seven_Click(object sender, EventArgs e) { s1 += "7"; txtResult.Text = s1;
  • 20. } private void eight_Click(object sender, EventArgs e) { s1 += "8"; txtResult.Text = s1; } private void div_Click(object sender, EventArgs e) { oper = "/"; s2 = s1; s1 = null; txtResult.Text = oper; isoper = true; this.dot.Enabled = true; } private void mul_Click(object sender, EventArgs e) { oper = "*"; s2 = s1; s1 = null; txtResult.Text = oper; isoper = true; this.dot.Enabled = true; } private void sub_Click(object sender, EventArgs e) { oper = "-"; s2 = s1; s1 = null; txtResult.Text = oper; isoper = true; this.dot.Enabled = true; } private void nine_Click(object sender, EventArgs e) { s1 += "9"; txtResult.Text = s1; } private void add_Click(object sender, EventArgs e) { oper = "+"; s2 = s1; s1 = null; txtResult.Text = oper;
  • 21. isoper = true; this.dot.Enabled = true; } private void dot_Click(object sender, EventArgs e) { if (isoper) { s1 += "."; this.dot.Enabled = false; isoper = false; txtResult.Text = s1; } } private void equal_Click(object sender, EventArgs e) { float n1, n2, res = 0.0f; n1 = float.Parse(s2); n2 = float.Parse(s1); switch (oper) { case "+": res = n1 + n2; break; case "-": res = n1 - n2; break; case "*": res = n1 * n2; break; case "/": res = n1 / n2; break; } this.txtResult.Text = res.ToString(); isoper = true; } private void QUIT_Click(object sender, EventArgs e) { MessageBox.Show("See You Again", "Thank You"); this.Close(); } } }
  • 22. OUTPUT: RESULT: Thus the program is compiled and executed successfully and the results are obtained.
  • 23. MULTI MODULE ASSEMBLY EX.NO:10 Date : AIM: To write a C# program using multi module Assembly. ALGORITHM: Step 1 — Compiling Files with Namespaces Referenced by Other Files csc /t:module Stringer.cs Specifying the module parameter with the /t: compiler option indicates that the file should be compiled as a module rather than as an assembly. The compiler produces a module called Stringer.netmodule, which can be added to an assembly Step 2 — Compiling Modules with References to Other Modules csc /addmodule:Stringer.netmodule /t:module Client.cs Specify the /t:module option because this module will be added to an assembly in a future step. Specify the /addmodule option because the code in Client references a namespace created by the code in Stringer.netmodule. The compiler produces a module called Client.netmodule that contains a reference to another module, Stringer.netmodule. Step 3 — Creating a Multifile Assembly Using the Assembly Linker al Client.netmodule Stringer.netmodule /main:MainClientApp.Main /out:myAssembly.exe /target:exe You can use the MSIL Disassembler (Ildasm.exe) to examine the contents of an assembly, or determine whether a file is an assembly or a module. PROGRAM: Stringer.cs using System; namespace myStringer { public class Stringer
  • 24. { public void StringerMethod() { System.Console.WriteLine("This is a line from StringerMethod."); } } } Client.cs using System; using myStringer; class MainClientApp { public static void Main() { Stringer myStringInstance = new Stringer(); Console.WriteLine("Client code executes"); myStringInstance.StringerMethod(); } } Compile: C:WINNT>cd microsoft.net C:WINNTMicrosoft.NET>cd framework C:WINNTMicrosoft.NETFramework>cd v2.0.50727 C:WINNTMicrosoft.NETFrameworkv2.0.50727>edit Stringer.cs C:WINNTMICROS~1.NETFRAMEW~1V20~1.507>csc /t:module Stringer.cs C:WINNTMICROS~1.NETFRAMEW~1V20~1.507>csc /addmodule:Stringer.netmodule /t:module Client.cs C:WINNTMICROS~1.NETFRAMEW~1V20~1.507>al Client.netmodule
  • 26. APPLICATION DEVELOPMENT ON .NET EX.NO:11 Date : AIM: To write a application using Windows Forms . ALGORITHM: Steps: 1. Create a windows application using C#. 2. Design the form with buttons and textbox like a calculation forms. 3. Name the buttons using property window. 3. Write the code for each button. 4. Build the application. 5. Display the result. 6. Stop the program PROGRAM: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WAArith { public partial class frmArith : Form { public frmArith() { InitializeComponent(); } private void optAdd_CheckedChanged(object sender, EventArgs e) { try { txtResult.Text = Convert.ToString(Convert.ToSingle(txtN1.Text) + Convert.ToSingle(txtN2.Text)); }
  • 27. catch (Exception er) { MessageBox.Show(er.Message); } } private void optSub_CheckedChanged(object sender, EventArgs e) { txtResult.Text = Convert.ToString(Convert.ToSingle(txtN1.Text) - Convert.ToSingle(txtN2.Text)); } private void optMul_CheckedChanged(object sender, EventArgs e) { txtResult.Text = Convert.ToString(Convert.ToSingle(txtN1.Text) * Convert.ToSingle(txtN2.Text)); } private void optDiv_CheckedChanged(object sender, EventArgs e) { txtResult.Text = Convert.ToString(Convert.ToSingle(txtN1.Text) / Convert.ToSingle(txtN2.Text)); } private void cmdRepeat_Click(object sender, EventArgs e) { txtN1.Text = ""; txtN2.Text = ""; txtResult.Text = ""; txtN1.Focus(); } private void btnExit_Click(object sender, EventArgs e) { MessageBox.Show("Bye to you"); this.Close(); } private void tmrTime_Tick(object sender, EventArgs e) { string st; st = Convert.ToString((DateTime.Now).Hour) + ":"; st += Convert.ToString((DateTime.Now).Minute) + ":"; st += Convert.ToString ((DateTime.Now).Second); this.Text = st; } private void button1_Click(object sender, EventArgs e)
  • 28. { ofdlg.ShowDialog(); picStart.ImageLocation = ofdlg.FileName; cdlg.ShowDialog(); groupBox1.BackColor = Color.Red; } } } OUTPUT: RESULT: Thus the program is compiled and executed successfully and the results are obtained.
  • 29. WEB APPLICATIONS EX.NO:12 Date : AIM: ALGORITHM: Steps: 1. Enter into the Microsoft Visual studio 2005. 2. Create a new project based on ASP.NET website.[File->New- >Website->ASP.NET Website]. 3. Enter into the design of the page. 4. Type the text in the design page. 5. Double click on “access data source” icon under the data toolbox. 6. Click on configure data source. 7. Type the specified database path and finally click finish. 8. Place the control data grid view from the data toolbox. 9. Set accessdatasource1 to the data source property of the data grid view. 10. Save and run the website. PROGRAM: using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button2_Click(object sender, EventArgs e) { if (this.txtFruit.Text != "") { lstFruits.Items.Add(txtFruit.Text); txtFruit.Text = "";
  • 30. txtFruit.Focus(); } } protected void Button1_Click(object sender, EventArgs e) { if (this.lstFruits.Items.Count != 0 && lstFruits.SelectedIndex != -1) lstFruits.Items.Remove(lstFruits.SelectedItem); } protected void txtselFruit_TextChanged(object sender, EventArgs e) { } protected void lstFruits_SelectedIndexChanged(object sender, EventArgs e) { txtselFruit.Text = lstFruits.SelectedItem.Text; } } OUTPUT: RESULT: Thus the program is compiled and executed successfully and the results are