SlideShare ist ein Scribd-Unternehmen logo
1 von 10
Practical No.11 
Program Name :- WAP in c# , to design a class employee such that it will 
automatically emp no. and also keep total no. of employee by using the concept of 
static data member function. 
Date :- 12/9/2014 
using System; 
using System.Collections.Generic; 
using System.Text; 
namespace demo 
{ 
class employee 
{ 
public static void Main() 
{ 
static int i, empno, n, count = 0; 
static string name; 
Console.WriteLine("How many you want to require?n"); 
n = int.Parse(Console.ReadLine()); 
Console.WriteLine("Enter information of the employeen"); 
for (i = 1; i <= n; i++) 
{ 
Console.WriteLine("Enter name of employeen"); 
name = Console.ReadLine(); 
Console.WriteLine("Employee no.ist10" + i); 
count++; 
} 
Console.WriteLine("Total no. of employee=" + count); 
Console.ReadKey(); 
} 
} 
} 
/*********OUTPUT 
How many you want to require? 
3 
Enter information of the employee 
Enter name of employee 
AAA 
Employee no.is 101 
Enter name of employee 
BBB 
Employee no.is 102 
Enter name of employee 
CCC 
Employee no.is 103 
Total no. of employee=3 *************/
Practical no 12 
using System; 
classbook 
{ 
pubicintbookno, bookname; 
public book(int x, string y) 
{ 
get 
{ 
Console.WriteLine(“Book No. :”+bookno”nBookName : ”+bookname); 
} 
set 
{ 
bookno=value; 
bookname=value; 
} 
} 
classbooktest 
{ 
public static void Main() 
{ 
book b1=new book(1, “E. Balgurusamy”); 
} 
} 
// Practical No. 13 
//Program Name :- WAP in C#, to find circumference of circle by using 
multilevel inheritance. 
//Written By Anand M. Khandre 
Date :- 22/9/2014 
using System; 
using System.Collections.Generic; 
using System.Text; 
namespace program 
{ 
classdemo 
{ 
publicint r;
public demo(int r) 
{ 
this.r = r; 
} 
publicvirtualvoid display() 
{ 
Console.WriteLine(" Radius of Circle =" + r); 
} 
} 
classdemo1 : demo 
{ 
double c; 
public demo1(int r,double x): demo(r) 
{ 
this.x=x; 
} 
publicoverridevoid display() 
{ 
c = 2 * x * r; 
Console.WriteLine(" Cirumferene of Circle =" + c); 
} 
} 
classoverridetest 
{ 
publicstaticvoid Main() 
{ 
demo1 d = newdemo1(5,3.14); 
d.display(); 
Console.ReadKey(); 
} 
} 
} 
//Practical No. 14 
//Program Name :- WAP, to find the simple interest by using multilevel 
inheritance. 
//Written By Anand M. Khandre 
//Date :- 20/9/2014 
using System; 
using System.Collections.Generic; 
using System.Text; 
namespace demo 
{ 
publicclass person 
{ 
publicdouble SI,P,R,T; 
publicvoid fun1()
{ 
Console.WriteLine("nEnter the value of the total amountn"); 
P=double.Parse(Console.ReadLine()); 
Console.WriteLine("nEnter the rate of interestn"); 
R=double.Parse(Console.ReadLine()); 
Console.WriteLine("nEnter the time spann"); 
T=double.Parse(Console.ReadLine()); 
} 
} 
class p1: person 
{ 
publicvoid fun2() 
{ 
person.fun1(); 
SI=((P*R*T)/100); 
} 
} 
class p2: p1 
{ 
publicvoid fun3() 
{ 
p1.fun2(); 
Console.WriteLine("nSimple interest="+SI); 
} 
} 
class display 
{ 
publicstaticvoid Main() 
{ 
p1 S=new p1(); 
S.fun2(); 
p2 I=new p2(); 
I.fun3(); 
Console.ReadLine(); 
Console.ReadKey(); 
} 
} 
} 
Practical no;-15 Multiple inheritance. 
using System; 
interface volume 
{ 
double compute(double x); 
} 
class box : volume 
{ 
public double compute(double x) 
{ 
return(x*x*x);
} 
} 
classcylender : volume 
{ 
public double compute(double x) 
{ 
public double h; 
h=6; 
return(3.14*x*x*h); 
} 
} 
class cone : volume 
{ 
public double compute(double x) 
{ 
return(0.33*3.14*x*x*h); 
} 
} 
classinttest 
{ 
pubic static void Main() 
{ 
box b=new box(); 
cylinder c=new cylinder(); 
cone c1=new cone() 
volume v; 
v=b as volume; 
Console.WriteLine(“Volume of box=”+v.compute(12)); 
v=c as volume; 
Console.WriteLine(“Volume of cylender=”+v.compute(10)); 
v=c1 as volume; 
Console.WriteLine(“Volume of cone=”+v.compute(14)); 
} 
}
//Practical No. 16 
//Program Name :- WAP, to find the area of trapezium and cube by using the 
concept of multiple implementation of interface. 
//Written By Anand M. Khandre 
//Date :- 22/9/2014 
using System; 
using System.Collections.Generic; 
using System.Text; 
interfacetrap 
{ 
double a1(); 
} 
interfacecube 
{ 
double a2(); 
} 
classval : trap, cube 
{ 
double a, b, h; 
public val(double a, double b, double h) 
{ 
this.a = a; 
this.b = b; 
this.h = h; 
} 
publicint a1() 
{ 
return (0.5*(a+b)*h); 
} 
publicint a2() 
{ 
return (6 * a * a); 
} 
} 
classdisplay 
{ 
publicstaticvoid Main() 
{ 
val d=newval(10,20,30); 
trap t=(trap)d; 
Console.Write("Area of trapazium="+t.a1()); 
cube c=(cube)d; 
Console.Write("Surface area of cube="+c.a2()); 
Console.ReadKey(); 
} 
}
// Practical No. 18 
//Program Name :- WAP in C#, to add and multiply of two nos. by using 
concept of delegate. 
//Written By Anand M. Khandre 
Date :- 1/10/2014 
using system; 
delegateintarithop(intx,int y); 
classmathop 
{ 
public static int add(inta,int b) 
{ 
return(a+b); 
} 
public static intmul(inta,int b) 
{ 
return(a*b); 
} 
} 
classdelegatetest 
{ 
public static void Main() 
{ 
arithopo1=new arithop(mathop.add); 
arithop o2=new arithop(mathop.mul); 
int result1=o1(200,100); 
int result2=o2(22,20); 
Console.WriteLine(“Addition =”+result1); 
Console.WriteLine(“Multiplication=”+result2); 
Console.ReadKey(); 
} 
}
// Practical No. 19 
//Program Name :- WAP in C#, to implement the concept of nested tryblock. 
//Written By Anand M. Khandre 
Date :- 29/9/2014 
using system; 
classnestedtry 
{ 
staticint m=10; 
staticint n=0; 
static void division() 
{ 
try 
{ 
int k =m/n; 
} 
catch(Argument Exception e) 
{ 
Console.WriteLine(“Caught an expection ”); 
} 
} 
public static void Main() 
{ 
try 
{ 
division(); 
} 
catch(DivideByZeroException e) 
{ 
Console.WriteLine(“ Caught an exception”); 
} 
finally 
{ 
Console.Write(“Inside Main Method”) 
} 
Console.ReadKey(); 
} 
}
//// Practical No. 20 
//Program Name :- WAP in C#, to implement the concept of event handling. 
//Written By Anand M. Khandre 
Date :- 28/9/2014 
using System; 
using System.Collections.Generic; 
using System.Text; 
publicdelegatevoidEdelegate(string str); 
classEventclass 
{ 
publiceventEdelegate status; 
publicvoid Trigger() 
{ 
if (status!=null) 
{ 
status("Event triggered"); 
} 
} 
} 
classEventtest 
{ 
publicstaticvoid Main() 
{ 
Eventclass ec=newEventclass(); 
Eventtest et= newEventtest(); 
ec.status +=newEdelegate(et.Eventcatch); 
ec.Trigger(); 
} 
publicvoid Eventcatch(string str) 
{ 
Console.WriteLine(str); 
Console.ReadKey(); 
} 
} 
//output 
Event triggered 
// Practical No. 22 
//Program Name :- WAP in C#, to implement the multicast delegate. 
//Written By Anand M. Khandre 
Date :- 28/9/2014
using System; 
using System.Collections.Generic; 
using System.Text; 
delegatevoidMdelegate(); 
classDM 
{ 
staticpublicvoid display() 
{ 
Console.WriteLine("New Delhi"); 
} 
staticpublicvoid print() 
{ 
Console.WriteLine("New York"); 
} 
} 
classMtest 
{ 
publicstaticvoid Main() 
{ 
Mdelegate m1 = newMdelegate(DM.display); 
Mdelegate m2 = newMdelegate(DM.print); 
Mdelegate m3 = m1 + m2; 
Mdelegate m4 = m2 + m1; 
Mdelegate m5 = m3 - m2; 
m3(); 
m4(); 
m5(); 
Console.ReadKey(); 
} 
} 
//output 
New Delhi 
New York 
New York 
New Delhi 
New Delhi

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

C c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdoC c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdo
 
C lab programs
C lab programsC lab programs
C lab programs
 
C++ file
C++ fileC++ file
C++ file
 
MFC Message Handling
MFC Message HandlingMFC Message Handling
MFC Message Handling
 
MFC Cosinus
MFC CosinusMFC Cosinus
MFC Cosinus
 
Lambda Expressions in C++
Lambda Expressions in C++Lambda Expressions in C++
Lambda Expressions in C++
 
vbscript-reference book
vbscript-reference bookvbscript-reference book
vbscript-reference book
 
201801 CSE240 Lecture 13
201801 CSE240 Lecture 13201801 CSE240 Lecture 13
201801 CSE240 Lecture 13
 
Brief Introduction to Cython
Brief Introduction to CythonBrief Introduction to Cython
Brief Introduction to Cython
 
RxJS Evolved
RxJS EvolvedRxJS Evolved
RxJS Evolved
 
A.P.S.E PRACTICAL FILE, NIT KURUKSHETRA
A.P.S.E PRACTICAL FILE, NIT KURUKSHETRA A.P.S.E PRACTICAL FILE, NIT KURUKSHETRA
A.P.S.E PRACTICAL FILE, NIT KURUKSHETRA
 
When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)
 
C++
C++C++
C++
 
C-- Sample Programs and Screenshots
C-- Sample Programs and ScreenshotsC-- Sample Programs and Screenshots
C-- Sample Programs and Screenshots
 
Introduction to cython: example of GCoptimization
Introduction to cython: example of GCoptimizationIntroduction to cython: example of GCoptimization
Introduction to cython: example of GCoptimization
 
C programs
C programsC programs
C programs
 
Simple c program
Simple c programSimple c program
Simple c program
 
Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016
 
C programms
C programmsC programms
C programms
 
week-4x
week-4xweek-4x
week-4x
 

Ähnlich wie P2 (20)

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
 
Hems
HemsHems
Hems
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
Pro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScriptPro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScript
 
srgoc
srgocsrgoc
srgoc
 
C#
C#C#
C#
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
 
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
 
Android programming -_pushing_the_limits
Android programming -_pushing_the_limitsAndroid programming -_pushing_the_limits
Android programming -_pushing_the_limits
 
C++ manual Report Full
C++ manual Report FullC++ manual Report Full
C++ manual Report Full
 
Java and j2ee_lab-manual
Java and j2ee_lab-manualJava and j2ee_lab-manual
Java and j2ee_lab-manual
 
Java doc Pr ITM2
Java doc Pr ITM2Java doc Pr ITM2
Java doc Pr ITM2
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
C# Unit 2 notes
C# Unit 2 notesC# Unit 2 notes
C# Unit 2 notes
 
C# programs
C# programsC# programs
C# programs
 
Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++
 
Design patterns in javascript
Design patterns in javascriptDesign patterns in javascript
Design patterns in javascript
 
The C# programming laguage delegates notes Delegates.pptx
The C# programming laguage delegates notes Delegates.pptxThe C# programming laguage delegates notes Delegates.pptx
The C# programming laguage delegates notes Delegates.pptx
 

P2

  • 1. Practical No.11 Program Name :- WAP in c# , to design a class employee such that it will automatically emp no. and also keep total no. of employee by using the concept of static data member function. Date :- 12/9/2014 using System; using System.Collections.Generic; using System.Text; namespace demo { class employee { public static void Main() { static int i, empno, n, count = 0; static string name; Console.WriteLine("How many you want to require?n"); n = int.Parse(Console.ReadLine()); Console.WriteLine("Enter information of the employeen"); for (i = 1; i <= n; i++) { Console.WriteLine("Enter name of employeen"); name = Console.ReadLine(); Console.WriteLine("Employee no.ist10" + i); count++; } Console.WriteLine("Total no. of employee=" + count); Console.ReadKey(); } } } /*********OUTPUT How many you want to require? 3 Enter information of the employee Enter name of employee AAA Employee no.is 101 Enter name of employee BBB Employee no.is 102 Enter name of employee CCC Employee no.is 103 Total no. of employee=3 *************/
  • 2. Practical no 12 using System; classbook { pubicintbookno, bookname; public book(int x, string y) { get { Console.WriteLine(“Book No. :”+bookno”nBookName : ”+bookname); } set { bookno=value; bookname=value; } } classbooktest { public static void Main() { book b1=new book(1, “E. Balgurusamy”); } } // Practical No. 13 //Program Name :- WAP in C#, to find circumference of circle by using multilevel inheritance. //Written By Anand M. Khandre Date :- 22/9/2014 using System; using System.Collections.Generic; using System.Text; namespace program { classdemo { publicint r;
  • 3. public demo(int r) { this.r = r; } publicvirtualvoid display() { Console.WriteLine(" Radius of Circle =" + r); } } classdemo1 : demo { double c; public demo1(int r,double x): demo(r) { this.x=x; } publicoverridevoid display() { c = 2 * x * r; Console.WriteLine(" Cirumferene of Circle =" + c); } } classoverridetest { publicstaticvoid Main() { demo1 d = newdemo1(5,3.14); d.display(); Console.ReadKey(); } } } //Practical No. 14 //Program Name :- WAP, to find the simple interest by using multilevel inheritance. //Written By Anand M. Khandre //Date :- 20/9/2014 using System; using System.Collections.Generic; using System.Text; namespace demo { publicclass person { publicdouble SI,P,R,T; publicvoid fun1()
  • 4. { Console.WriteLine("nEnter the value of the total amountn"); P=double.Parse(Console.ReadLine()); Console.WriteLine("nEnter the rate of interestn"); R=double.Parse(Console.ReadLine()); Console.WriteLine("nEnter the time spann"); T=double.Parse(Console.ReadLine()); } } class p1: person { publicvoid fun2() { person.fun1(); SI=((P*R*T)/100); } } class p2: p1 { publicvoid fun3() { p1.fun2(); Console.WriteLine("nSimple interest="+SI); } } class display { publicstaticvoid Main() { p1 S=new p1(); S.fun2(); p2 I=new p2(); I.fun3(); Console.ReadLine(); Console.ReadKey(); } } } Practical no;-15 Multiple inheritance. using System; interface volume { double compute(double x); } class box : volume { public double compute(double x) { return(x*x*x);
  • 5. } } classcylender : volume { public double compute(double x) { public double h; h=6; return(3.14*x*x*h); } } class cone : volume { public double compute(double x) { return(0.33*3.14*x*x*h); } } classinttest { pubic static void Main() { box b=new box(); cylinder c=new cylinder(); cone c1=new cone() volume v; v=b as volume; Console.WriteLine(“Volume of box=”+v.compute(12)); v=c as volume; Console.WriteLine(“Volume of cylender=”+v.compute(10)); v=c1 as volume; Console.WriteLine(“Volume of cone=”+v.compute(14)); } }
  • 6. //Practical No. 16 //Program Name :- WAP, to find the area of trapezium and cube by using the concept of multiple implementation of interface. //Written By Anand M. Khandre //Date :- 22/9/2014 using System; using System.Collections.Generic; using System.Text; interfacetrap { double a1(); } interfacecube { double a2(); } classval : trap, cube { double a, b, h; public val(double a, double b, double h) { this.a = a; this.b = b; this.h = h; } publicint a1() { return (0.5*(a+b)*h); } publicint a2() { return (6 * a * a); } } classdisplay { publicstaticvoid Main() { val d=newval(10,20,30); trap t=(trap)d; Console.Write("Area of trapazium="+t.a1()); cube c=(cube)d; Console.Write("Surface area of cube="+c.a2()); Console.ReadKey(); } }
  • 7. // Practical No. 18 //Program Name :- WAP in C#, to add and multiply of two nos. by using concept of delegate. //Written By Anand M. Khandre Date :- 1/10/2014 using system; delegateintarithop(intx,int y); classmathop { public static int add(inta,int b) { return(a+b); } public static intmul(inta,int b) { return(a*b); } } classdelegatetest { public static void Main() { arithopo1=new arithop(mathop.add); arithop o2=new arithop(mathop.mul); int result1=o1(200,100); int result2=o2(22,20); Console.WriteLine(“Addition =”+result1); Console.WriteLine(“Multiplication=”+result2); Console.ReadKey(); } }
  • 8. // Practical No. 19 //Program Name :- WAP in C#, to implement the concept of nested tryblock. //Written By Anand M. Khandre Date :- 29/9/2014 using system; classnestedtry { staticint m=10; staticint n=0; static void division() { try { int k =m/n; } catch(Argument Exception e) { Console.WriteLine(“Caught an expection ”); } } public static void Main() { try { division(); } catch(DivideByZeroException e) { Console.WriteLine(“ Caught an exception”); } finally { Console.Write(“Inside Main Method”) } Console.ReadKey(); } }
  • 9. //// Practical No. 20 //Program Name :- WAP in C#, to implement the concept of event handling. //Written By Anand M. Khandre Date :- 28/9/2014 using System; using System.Collections.Generic; using System.Text; publicdelegatevoidEdelegate(string str); classEventclass { publiceventEdelegate status; publicvoid Trigger() { if (status!=null) { status("Event triggered"); } } } classEventtest { publicstaticvoid Main() { Eventclass ec=newEventclass(); Eventtest et= newEventtest(); ec.status +=newEdelegate(et.Eventcatch); ec.Trigger(); } publicvoid Eventcatch(string str) { Console.WriteLine(str); Console.ReadKey(); } } //output Event triggered // Practical No. 22 //Program Name :- WAP in C#, to implement the multicast delegate. //Written By Anand M. Khandre Date :- 28/9/2014
  • 10. using System; using System.Collections.Generic; using System.Text; delegatevoidMdelegate(); classDM { staticpublicvoid display() { Console.WriteLine("New Delhi"); } staticpublicvoid print() { Console.WriteLine("New York"); } } classMtest { publicstaticvoid Main() { Mdelegate m1 = newMdelegate(DM.display); Mdelegate m2 = newMdelegate(DM.print); Mdelegate m3 = m1 + m2; Mdelegate m4 = m2 + m1; Mdelegate m5 = m3 - m2; m3(); m4(); m5(); Console.ReadKey(); } } //output New Delhi New York New York New Delhi New Delhi