Upload
anand-khandare
View
18
Download
0
Embed Size (px)
Citation preview
Practical No.11Program 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 employee\n"); for (i = 1; i <= n; i++) { Console.WriteLine("Enter name of employee\n"); name = Console.ReadLine(); Console.WriteLine("Employee no.is\t10" + i); count++; } Console.WriteLine("Total no. of employee=" + count); Console.ReadKey(); } }}/*********OUTPUTHow many you want to require?3Enter information of the employeeEnter name of employeeAAAEmployee no.is 101Enter name of employeeBBBEmployee no.is 102Enter name of employeeCCCEmployee 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. KhandreDate :- 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 amount\n"); P=double.Parse(Console.ReadLine());
Console.WriteLine("\nEnter the rate of interest\n"); R=double.Parse(Console.ReadLine());Console.WriteLine("\nEnter the time span\n"); 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. KhandreDate :- 1/10/2014using 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. KhandreDate :- 29/9/2014using 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/2014using 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(); }}
//outputEvent triggered
// Practical No. 22//Program Name :- WAP in C#, to implement the multicast delegate.//Written By Anand M. KhandreDate :- 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(); }}//outputNew DelhiNew YorkNew YorkNew DelhiNew Delhi