C# Lab Ready For Print Out

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View C# Lab Ready For Print Out as PDF for free.

More details

  • Words: 1,486
  • Pages: 37
EXP NO : 1

USAGE OF STRUCTURES AIM: To write a program in C# Language to use structures. ALGORITHM: 1. Get number of students, say n. 2. Get the details for n students. 3. Compute their average marks of two subjects and show as a report.

1

Compute a-b Print the sub(a,b) Return value

Start

FLOWCHART:MULTILEVEL INHERITANCE Create a structure for student with required Addi(a,b) fields. Start

Create object of class div.

Addi(a,b)

Subt(a,b)

Input all the fields inside the student class using Int z; the method getdata(). Z=a+b;

Print the Display all the details value of z inside the student class using the method showdata(). Return

Mult(a,b)

Call the defined function using the object created subt(a,b) for student class inside the main class.

Div(a,b) Int z; Z=a-b;

Stop Stop

Print the value of z

Return

2

PROGRAM: using System; public class add { public void addi(int a ,int b) { int z; z=a+b; Console.WriteLine("after doing addition"+z); }} public class sub:add { public void subt(int a,int b) { int z; z=a-b; Console.WriteLine("after doing subtration"+z)}} public class mul:sub { public void mult(int a,int b) { int z; z=a*b; Console.WriteLine("after doing Multiplication"+z) }} public class div:mul { public void divi(int a,int b) { int z; z=a/b; Console.WriteLine("after doing divison"+z); } } public class calcution { public static void Main(String [ ]args) { int a,b; div x=new div(); Console.WriteLine ("Enter The A value"); a=Convert.ToInt32 (Console.ReadLine()); Console.WriteLine ("Enter The B value"); b=Convert.ToInt32 (Console.ReadLine()); x.addi (a,b); x.subt (a,b); x.mult (a,b); x.divi (a,b); } }

3

OUTPUT: Enter the value of A: 5 Enter the value of B: 5 After Addition : 10 After Subtraction: 0 After Multiplication : 25 After Division : 1

4

RESULT:

Thus the program was written & output was verified.

5

EXP NO.: 4

INTERFACES AIM: To write a program in C# Language to demonstrate Interfaces Start

Add(a,b)

ALGORITHM:

1. Create 4 interfaces. Create object of classthem trail1toand 2. Inherit a class & define the functions declared in those interfaces. call the function 3. In the main program, create an object of derived class and call all the Compute a+b usins defined. object functions

Add(a,b)

Print the value

Sub(a,b)

Return

Stop

6

FLOWCHART: INTERFACE

Start

Create 4 Interface and declare methods corresponding to it..

Create a class and define all the methods inside it.

Create a main class declare object of derived class

Call the defined function using the object created for the derived class inside the main class.

Stop

7

PROGRAM: using System; interface i1 { void add(); } interface i2 { void sub(); } interface i3 { void mul(); } interface i4 { void div(); } class xyz:i1,i2,i3,i4 { public int a,b; public void get() { Console.WriteLine("Enter The A value"); a=Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter The B value"); b=Convert.ToInt32(Console.ReadLine()); } public void add() { int z; z=a+b; Console.WriteLine("after doing addition"+z); } public void sub() { int z; z=a-b; Console.WriteLine("after doing subtraction"+z); } public void mul() { int z; 8

z=a*b; Console.WriteLine("after doing multiplication"+z); } public void div() { int z; z=a/b; Console.WriteLine("after doing division"+z); } } class multiple { public static void Main(String []args) { xyz obj=new xyz(); obj.get(); i1 obj1=(i1) obj; obj1.add(); i2 obj2=(i2) obj; obj2.sub(); i3 obj3=(i3) obj; obj3.mul(); i4 obj4=(i4) obj; obj4.div(); } }

9

OUTPUT: Enter the value of A: 5 Enter the value of B: 5 After Addition : 10 After Subtraction: 0 After Multiplication : 25 After Division : 1

10

RESULT:

Thus the program was written & output was verified.

11

EXP NO.: 5

DELEGATES AIM: To write a program in C# Language to demonstrate the usage of Delegates. ALGORITHM: 1. Declare a delegate. 2. Create a new class and define 2-3 methods with same signature as of the delegate. 3. Write the main program & create an object of delegate. 4. Pass the function names as arguments (parameter) to the delegate.

12

FLOWCHART: DELEGATES.

Start

Print1()

Create object of class b1

Create object of delegate and call the functions using object of b1 and delegate.

Print the satatement.

Print1()

Print2()

Print2()

Print the satatement.

Stop

13

PROGRAM: using system; public delegate void dell(); public class b1 { public void print1() { Console.WriteLine (“This is Function 1\n”); } public void print2() { Console.WriteLine (“This is Function 2\n”); } } class main { public static void Main() { b1 a = new b1(); dell x = new dell(a.print1); x+ = new dell(a.print2); x(); Console.ReadLine(); } }

14

OUTPUT: This is Function 1 This is Function 2

15

RESULT:

Thus the program was written & output was verified.

16

EXP NO.: 6

MOUSE EVENTS AIM: To write a program in C# Language to demonstrate the Mouse Events. ALGORITHM: 1. In the main class, inherit Form. 2. in the constructor of the class, define the EventHandlers for the MouseUp and MouseMove. 3. Write different functions to respond to the MouseUp & MouseMove events.

17

PROGRAM: using System; using System.Windows.Forms; class WinF:Form { public WinF() { Top=100; Left=75; Height=100; Width=500; this.MouseUp+=new MouseEventHandler(OnMo); this.MouseMove+=new MouseEventHandler(OnMM); } public void OnMo(object O,MouseEventArgs M) { string s=string.Format("CurrentPosition:{0},{1}",M.X,M.Y); MessageBox.Show(s); } public void OnMM(object O,MouseEventArgs M) { this.Text=string.Format("CurrentPosition:{0},{1}",M.X,M.Y); } public static void Main() { Application.Run(new WinF()); } }

18

OUTPUT:

19

RESULT:

Thus the program was written & output was verified.

20

EXP NO.: 7

MENUS AIM: To write a program in C# Language to demonstrate the creation of Menus. ALGORITHM: 1. 2. 3. 4.

In the main class, inherit Form. In the constructor of the class, define the Menus Write the various events for the Menu. Include the Menu in the Form

21

PROGRAM: using System; using System.Windows.Forms; class WinFF:Form { public WinFF() { MainMenu M=new MainMenu(); MenuItem M1=new MenuItem("file"); MenuItem M2=new MenuItem("open"); MenuItem M3=new MenuItem("save"); MenuItem M4=new MenuItem("exit"); MenuItem M5=new MenuItem("Edit"); M1.MenuItems.Add(M2); M1.MenuItems.Add(M3); M1.MenuItems.Add(M4); M.MenuItems.Add(M1); this.Menu = M; } public static void Main() { Application.Run(new WinFF()); } }

22

OUTPUT:

23

RESULT:

Thus the program was written & output was verified.

24

EXP NO.: 8

TEXT BOX AIM: To write a program in C# Language to demonstrate the usage of Text Boxes. ALGORITHM: 1. 2. 3. 4.

In the main class, inherit Form In the constructor of the class, define the properties of the text boxes. Write the various events for the Buttons. Include the Menu in the Form

25

PROGRAM: using System; using System.Windows.Forms; using System.Drawing; class teb:Form { TextBox T1=new TextBox(); TextBox T2=new TextBox(); TextBox T3=new TextBox(); Button B1=new Button(); Button B2=new Button(); Button B3=new Button(); public teb() { T1.Location=new System.Drawing.Point(10,10); T1.Size=new System.Drawing.Size(150,100); T1.Multiline=true; T1.ScrollBars=ScrollBars.Both; B1.Location=new System.Drawing.Point(180,10); B1.Text="Reveal"; T2.Location=new System.Drawing.Point(10,120); T2.Size=new System.Drawing.Size(150,20); T2.PasswordChar='*'; B2.Location=new System.Drawing.Point(180,120); B2.Text="Reveal"; T3.Location=new System.Drawing.Point(10,120); T3.Size=new System.Drawing.Size(50,10); T3.CharacterCasing=CharacterCasing.Upper; B3.Location=new System.Drawing.Point(110,34); B3.Text="Upper";

this.Click+=new EventHandler(Button_B1); this.Click+=new EventHandler(Button_B2); this.Click+=new EventHandler(Button_B3); this.Controls.Add(T1); this.Controls.Add(T2); this.Controls.Add(T3); this.Controls.Add(B1); this.Controls.Add(B2); this.Controls.Add(B3); } 26

public void Button_B1(object O, EventArgs M) { MessageBox.Show(T1.Text); } public void Button_B2(object O, EventArgs M) { MessageBox.Show(T2.Text); } public void Button_B3(object O, EventArgs M) { MessageBox.Show(T3.Text); } public static void Main() { Application.Run(new teb()); } }

27

OUTPUT: Sample Output

28

RESULT:

Thus the program was written & output was verified.

29

EXP NO.: 9

LIST BOX AIM: To write a program in C# Language to demonstrate the usage of List Boxes. ALGORITHM: 1. 2. 3. 4.

In the main class, inherit Form In the constructor of the class, define the properties of the List boxes. Write the various events for the List Box. Include the Menu in the Form.

PROGRAM: 30

using System; using System.Windows.Forms; using System.Drawing; public class Win1:Form { public ListBox lb1; public void myMClick (object O, MouseEventArgs M) { lb1.Items.Add (“LAST Mouse Click @ X:” +M.X ” Y:” +M.Y); } public void myMMove (object O, MouseEventArgs M) { lb1.Items.Add (“LAST Mouse Move @ X:” +M.X ” Y:” +M.Y); } public Win1( ) { Top = 0; Left = 0; Height = 300; Width = 300; MouseUp+ = new MouseEventHandler(OnMClick); MouseMove+ = new MouseEventHandler(OnMMove); lb1 = new ListBox(); lb1.Location = new System.Drawing.Point(2,2); lb1.Size = new System.Drawing.Size(250,250); lb1.Text = "lb1"; Controls.Add(lb1); } } public class main { public static void Main( ) { Application.Run (new Win1( )); } }

OUTPUT: 31

32

RESULT:

Thus the program was written & output was verified.

33

EXP NO.:10

SELECT BOXES & RADIO BUTTONS AIM: To write a program in C# Language to demonstrate the usage of Select Boxes. ALGORITHM: 1. In the main class, inherit Form 2. In the constructor of the class, define the properties of the Select boxes and Radio buttons. 3. Write the various events for them. 4. Include the Menu in the Form.

34

Program: using System; using System.Windows.Forms; class Win: Form { RadioButton r1 = new RadioButton(); RadioButton r2 = new RadioButton(); CheckBox cb1 = new CheckBox(); CheckBox cb2 = new CheckBox(); GroupBox gb = new GroupBox(); public Win() {

gb.Controls.Add(r2); this.Controls.Add(cb1); cb1.Location=new System.Drawing.Point(300,200); this.Controls.Add(cb2); cb2.Location=new System.Drawing.Point(200,300); gb.Controls.Add(r1); gb.Controls.Add(r2); this.Controls.Add(gb); gb.Enter+=new EventHandler(onEnter); } public void onEnter(Object o, EventArgs e) { MessageBox.Show("HELLO WELCOME"); } public static void Main() { Application.Run(new Win()); } }

35

OUTPUT

36

Result: -The program has been created and run successful

37

Related Documents