Top Banner
STAR ACADEMY OF TECHNOLOGY AND MANAGEMENT INDORE COMPUTER SCIENCE & ENGINEERING DOTNET TECNOLOGY(CS-406) LAB MANUAL Submitted By : Name : RANJIT KUMAR NAHAK Session : Jan 2014-Jun 2014 Dept. : CSE, SATM
41
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Dotnet 18

STAR ACADEMY OF TECHNOLOGY AND MANAGEMENTINDORE

COMPUTER SCIENCE & ENGINEERINGDOTNET TECNOLOGY(CS-406)

LAB MANUAL

Submitted By :

Name : RANJIT KUMAR NAHAKSession : Jan 2014-Jun 2014Dept. : CSE, SATM

Page 2: Dotnet 18

1) W.A.P to perform basic arithmetic calculation.

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace add{

class Program{

static void Main(string[] args){

int a, b;

Console.WriteLine("Enter first nos.");a = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter second no.");b = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("add is :{0}", a + b); Console.WriteLine("sub is :{0}",a-b); Console.WriteLine("multi is :{0}",a*b); Console.WriteLine("devi is :{0}",a/b); Console.ReadLine();

}}

}

Page 3: Dotnet 18

OUTPUT

Page 4: Dotnet 18

2) W.A.P to interchange the value of 2 variables without using third variable.

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace swap{

class Program{

static void Main(string[] args)

int a = 6;int b = 7;

Console.WriteLine("the numbers before swapping a={0} and b={1}",a,b);a = a + b;b = a - b;a = a - b;Console.WriteLine("the numbers after swapping a={0} and b={1}", a, b); Console.Read();

}}

}

Page 5: Dotnet 18

OUTPUT

Page 6: Dotnet 18

3) W.A.P to display array elements & their sum.

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace array{

class Program{

static void Main(string[] args){

int[] num = { 10, 20, 30, 40 }; int n = num.Length; Console.WriteLine("array elements"); for (int i = 0; i < n; i++){ Console.WriteLine(num[i]);}int sum = 0;for (int i = 0; i < n; i++){ sum = sum + num[i];} Console.WriteLine("sum"+sum);Console.Read();

}}

}

Page 7: Dotnet 18

OUTPUT

Page 8: Dotnet 18

4) W.A.P to input array elements & sort them.

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace arrayip{

class Program{

static void Main(string[] args)

int i, j, temp;int[] ar = new int[5];Console.WriteLine("Enter the elements of array");for (i = 0; i < ar.Length; i++){

ar[i] = Convert.ToInt32(Console.ReadLine());}Console.WriteLine("Sorted array is: ");{

for (i = 0; i < ar.Length; i++){

for (j = i + 1; j < ar.Length; j++){

if (ar[i] > ar[j]){

temp = ar[i]; ar[i] = ar[j]; ar[j] = temp;

}}

}for (i = 0; i < ar.Length; i++){

Console.Write(ar[i]); Console.ReadLine();

}

}}

}}

Page 9: Dotnet 18

OUTPUT

Page 10: Dotnet 18

5) W.A.P using c lass.

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace{

class Program{

class student{

String nm, dep, gen;public void setdata()

{Console.WriteLine("Eter Name"); nm = Console.ReadLine(); Console.WriteLine("Enter Dept"); dep = Console.ReadLine(); Console.WriteLine("Enter gender"); gen = Console.ReadLine();

}public void putdata(){

Console.WriteLine("Name " +nm); Console.WriteLine("DEPT " +dep); Console.WriteLine("Gender " +gen);

}}

static void Main(string[] args){

student stu = new student();stu.setdata(); stu.putdata(); Console.ReadLine();

}}

}

Page 11: Dotnet 18

OUTPUT

Page 12: Dotnet 18

6) W.A.P to print fibonacci series.

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace fibonic_series{

class Program{

static void Main(string[] args){

int a, b, c,n;a=0;b=1;Console.WriteLine("Enter Limit: ");n = Convert.ToInt32(Console.ReadLine()); Console.WriteLine( a);Console.WriteLine( b);for(int i=3;i<=n;i++)

{c = a + b;a = b; b = c; Console.WriteLine(c);

}Console.ReadLine();

}}

}

Page 13: Dotnet 18

OUTPUT

Page 14: Dotnet 18

7) W.A.P using function overloading.

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace funover{

class Program{

class worker

{public void salary(int a, int b){

int total, bonus; Console.Write("Enter first bonus: ");bonus = Convert.ToInt32(Console.ReadLine());total = bonus + a + b; Console.WriteLine(); Console.WriteLine("Total salary is: "+total); Console.WriteLine();

}public void salary(int a){

int total, bonus;Console.Write("Enter second bonus: ");bonus = Convert.ToInt32(Console.ReadLine());total = bonus + a; Console.WriteLine(); Console.WriteLine("Total salary is: "+total);

}}static void Main(string[] args){

worker w = new worker(); w.salary(5000,6000);

Page 15: Dotnet 18

w.salary(10000); Console.ReadLine();

}}

}

OUTPUT

Page 16: Dotnet 18

8) W.A.P to show multilevel inheritance.

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace multiinhrit{

class Area{

public int l, b;public void cal_area(){

Console.WriteLine();Console.WriteLine("The area is:(l*b) " + (l * b));

}}class volume : Area{

public int h;public void cal_volume(){

Console.WriteLine();Console.WriteLine("The volume is: " + (l * b * h));

}

}class density : volume{

int m;public density(int ll, int bb, int hh, int mm){

l = ll;b = bb;h = hh;m = mm;

}public void cal_density(){

int d;

Page 17: Dotnet 18

d = m / (l * b * h); Console.WriteLine(); Console.WriteLine("The density is: " + d);

}

public void showdata(){

Console.WriteLine("The length is: " + l); Console.WriteLine(); Console.WriteLine("The breadth is: " + b); Console.WriteLine(); Console.WriteLine("The height is: " + h); Console.WriteLine(); Console.WriteLine("The mass is: " + m);

}}class Program{

static void Main(string[] args)

density dense = new density(12,10,5,4000);dense.showdata();

dense.cal_volume();dense.cal_area();dense.cal_density(); Console.Read();

}}

}

Page 18: Dotnet 18

OUTPUT

Page 19: Dotnet 18

9) W.A.P to print star pyramid.

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace star{

class Program{

static void Main(string[] args){

int i,j;

Console.WriteLine("pyramid of star:");for (i = 0; i <= 5; i++){

for (j = 0; j < i; j++){

Console.Write("*");}Console.WriteLine();

}Console.ReadLine();

}}

}

Page 20: Dotnet 18

OUTPUT

WINDOWS PROGRAMMING

Page 21: Dotnet 18

10) W.a.P to print the factorial of a given no.

using System;using System.Collections.Generic;using System.ComponentModel;

using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;

namespace fact{

public partial class Form1 : Form{

public Form1(){

InitializeComponent();}

private void button1_Click(object sender, EventArgs e){

int n,i,fact=1;n = Convert.ToInt32(textBox1.Text);for (i = 1; i <= n; i++){

fact = fact * i;}textBox2.Text = Convert.ToString(fact);

}

Page 22: Dotnet 18

OUTPUT

Page 23: Dotnet 18

11) W.A.P to find the greatest of three nos.

using System;using System.Collections.Generic; using System.ComponentModel; using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;

namespace greatest{

public partial class Form1 : Form{

public Form1(){

InitializeComponent();}

private void button1_Click(object sender, EventArgs e){

int a, b, c;a = Convert.ToInt32(textBox1.Text);b = Convert.ToInt32(textBox2.Text);

c = Convert.ToInt32(textBox3.Text);if (a > b && a > c){

MessageBox.Show("A is Greatest");}else{

if (b > c){

MessageBox.Show("B is Gratest");}else{

MessageBox.Show("C is Greatest");}

}textBox1.Text

Page 24: Dotnet 18

= ""; textBox2.Text = ""; textBox3.Text = "";

}}

}

Page 25: Dotnet 18

OUTPUT

Page 26: Dotnet 18

12) W.A.P to display calculator.

using System;using System.Collections.Generic; using System.ComponentModel; using System.Data;using System.Drawing; using System.Linq; using System.Text;using System.Windows.Forms;

namespace calc{

public partial class Form1 : Form{

String str = "";//globallyString str1 = ""; Double i, j, k,flag=0; public Form1(){

InitializeComponent();}

private void button16_Click(object sender, EventArgs e){

textBox1.Text = " ";textBox2.Text = " ";

str = "";

}

private void button1_Click(object sender, EventArgs e){

textBox1.Text =str+ "1";str = textBox1.Text;

}

private void button2_Click(object sender, EventArgs e){

Page 27: Dotnet 18

textBox1.Text =str+ "2";str = textBox1.Text;

}

private void button3_Click(object sender, EventArgs e){

textBox1.Text = str+"3";str = textBox1.Text;

}

private void button4_Click(object sender, EventArgs e){

textBox1.Text = str+"4";str = textBox1.Text;

}

private void button5_Click(object sender, EventArgs e){

textBox1.Text = str+"5";str = textBox1.Text;

}

private void button6_Click(object sender, EventArgs e){

textBox1.Text = str+"6";str = textBox1.Text;

}

private void button7_Click(object sender, EventArgs e){

textBox1.Text = str+"7";str = textBox1.Text;

}

private void button8_Click(object sender, EventArgs e){

textBox1.Text = str+"8";str = textBox1.Text;

}

Page 28: Dotnet 18

private void button9_Click(object sender, EventArgs e){

textBox1.Text = str+"9";str = textBox1.Text;

}

private void button10_Click(object sender, EventArgs e){

textBox1.Text = str+"0";str = textBox1.Text;

}

private void Form1_Load(object sender, EventArgs e){

}

private void button11_Click(object sender, EventArgs e)

{textBox2.Text = textBox1.Text;textBox1.Text = "";str = "";str1 = "+";

}

private void button15_Click(object sender, EventArgs e){

i = Convert.ToDouble(textBox2.Text); j = Convert.ToDouble(textBox1.Text); if (str1 == "+")

k = i + j;if (str1 == "-")

k = i - j;if (str1 == "*")

k = i * j;if (str1 == "/")

k = i / j;if (str1 == "%")

k = i % j;

Page 29: Dotnet 18

textBox1.Text = k.ToString();}

private void button12_Click(object sender, EventArgs e){

textBox2.Text = textBox1.Text;textBox1.Text = "";str = "";str1 = "-";

}

private void button13_Click(object sender, EventArgs e)

textBox2.Text = textBox1.Text;

str = "";str1 = "*";

}

private void button14_Click(object sender, EventArgs e){

textBox2.Text = textBox1.Text;textBox1.Text = "";str = "";str1 = "/";

}

private void button20_Click(object sender, EventArgs e){

textBox2.Text = textBox1.Text;textBox1.Text = "";str = "";str1 = "%";

}

private void button18_Click(object sender, EventArgs e){

this.Close();}

private void button17_Click(object sender, EventArgs e){

if (flag == 0)

Page 30: Dotnet 18

{textBox1.Text = str + ".";str = textBox1.Text;flag = 1;

}else

{ str = textBox1.Text;}}

Page 31: Dotnet 18
Page 32: Dotnet 18

13) W.A.P. for Notepad.

using System;using System.Collections.Generic; using System.ComponentModel; using System.Data;using System.Drawing; using System.Linq; using System.Text;using System.Windows.Forms;

namespace notepad

public partial class Form1 : Form

){

public Form1(){

InitializeComponent();}

private void openToolStripMenuItem_Click(object sender, EventArgs e){

//Shows the openFileDialog openFileDialog1.ShowDialog();//Reads the text fileSystem.IO.StreamReader OpenFile = new

System.IO.StreamReader(openFileDialog1.FileName);//Displays the text file in the textBox txtMain.Text = OpenFile.ReadToEnd();//Closes the proccessOpenFile.Close();

}

private void saveToolStripMenuItem_Click(object sender, EventArgs e){

//Determines the text file to save to

Page 33: Dotnet 18

System.IO.StreamWriter SaveFile = newSystem.IO.StreamWriter(openFileDialog1.FileName);

//Writes the text to the fileSaveFile.WriteLine(txtMain.Text);//Closes the proccessSaveFile.Close();

}

private void saveAsToolStripMenuItem_Click(object sender, EventArgs e){

//Open the saveFileDialog saveFileDialog1.ShowDialog();//Determines the text file to save toSystem.IO.StreamWriter SaveFile = new

System.IO.StreamWriter(saveFileDialog1.FileName);//Writes the text to the fileSaveFile.WriteLine(txtMain.Text);//Closes the process

txtMain.Undo();}

private void redoToolStripMenuItem_Click(object sender, EventArgs e){

txtMain.Undo();}

private void newToolStripMenuItem_Click(object sender, EventArgs

SaveFile.Close();}

private void printToolStripMenuItem_Click(object sender, EventArgs e){

//Declare prntDoc as a new PrintDocument printDialog1.ShowDialog(); System.Drawing.Printing.PrintDocument prntDoc = new

System.Drawing.Printing.PrintDocument();

}

Page 34: Dotnet 18

private void printPreviewToolStripMenuItem_Click(object sender, EventArgs e){

printPreviewDialog1.ShowDialog();

}

private void exitToolStripMenuItem_Click(object sender, EventArgs e){

Application.Exit();}

private void undoToolStripMenuItem_Click(object sender, EventArgs e){ e){

txtMain.Clear();}

private void cutToolStripMenuItem_Click(object sender, EventArgs e){}

private void copyToolStripMenuItem_Click(object sender, EventArgs e){

txtMain.Copy();}

private void pasteToolStripMenuItem_Click(object sender, EventArgs e){

txtMain.Paste();}

private void selectAllToolStripMenuItem_Click(object sender, EventArgs e){

txtMain.SelectAll();}

}}

Page 35: Dotnet 18
Page 36: Dotnet 18