You are on page 1of 18

UIT-RGPV BHOPAL

Department of Information Technology


Session-2012-13 CIVIL IV SEMESTER LAB MANUAL

COMPUTER PROGRAMMING- II
Submitted to:
.

Submitted by:
..

.1 Write about .Net framework. Answer: The .Net framework is a software network framework developed by Microsoft that runs primarily on Microsoft Windows. It includes a large library and provides language interoperability across several programming languages. Programs written for the .Net framework executes in software environment as contrasted to hardware environment known as Common Language Runtime [CLR], an application virtual machine that provides services such as security, memory management and exception handling. The class library and CLR together constitute the .Net framework. The .Net frameworks is base class is library provides user interface data access, database connectivity, cryptography, web application development, numeric algorithms and network communication. Programmers produce software by combining their own source code with the .Net framework and other libraries. The .Net framework is intended to be used by most new applications created for the Windows platform. Microsoft also produces an integrated development environment largely for internet software called Visual Studio. The .Net framework introduces a common type system [CTS]. The CTS specification defines are possible data types and programming constructs supported by CLR. Design Features 1. 2. 3. 4. 5. 6. 7. Interoperability Common language Runtime engine Language independent Base class library Simplified Development Security Portability

Q.2 WAP to find sum of two numbers using systems; Answer: Using systems.collections.generic; Namespace sum { class sum 1 { static void main(string []args) { int a,b,sum; Console.write line (enter 2 numbers); A=int.parse (console.read line ()); B= int.parse (console.read line ()); Sum=A+B; Console.write line(sum of {0}and {1} is {2},a,b,sum); Console:readkey(); } } }

Output Enter 2 numbers 2 3 Sum of 2 and 3 is 5

Q.3 WAP to find fibonacic series Answer: Using system ; Using system.collections.generic; Namespace test {class series {static void main(string [] args} { Int a=0,b=1,c=0,I; For (i=1;i<=100;i++) { a=b; b=c; c=a+b; console.write line(c); } Console.read key(); } } }

Q.4 WAP to find a number is even or odd.

Answer:

Using system: Using system Collections Generic; Namespace odd or even { Class odd or even { Static void main (string [] args) { System console Write (enter no.); int n=0; n=int.Pause (console Read Line() ); if (n%2==0) console write line ({0} is even, n); else console write line ({0} is odd,); } } OUTPUT } enter no. 2 enter 2 is even

Q.5 WAP in c# to accept an array of integers and sort them in ascending order Answer: Using system; Using system.collections.generic; Using system.text; Namespace array {class program {static void print array(int[]arr) {console.writeline(/n elements are); For each (int i in arr) {console.write(/t{0},i);}} Static void main(string []args) {int [] arr =new int [10]; Int I; For (i=0;i<10;i++) {console.write(enter number:/t); Arr[i]=convert.To Int 32(console.read())}; Program.print array(arr); Array.sort(arr); Program.print array(arr);

Console.readline(); } } }

Que-6 WAP to print table of a number ? Answer: Using System ; Using System.Collections.Generic; namespace table { class table1 { Static void Main(String[]args) { int a; Console .WriteLine(Enter a no.); a=int.parse(Console.ReadLine()); for (int i=0;i<10;i++) { Console.WriteLine({0}*{1}={2},a,i,a*i); } Console.ReadLine(); } } } OUTPUT Enter a no. 2 2*8=16 2*1=2 2*9=18 2*2=4 2*10=20 2*3=6 2*4=8 2*5=10 2*6=12 2*7=14

Que-7 WAP that access from second class in main function of first

class? Answer: Using system; Namespace test { Public class calculator [private int ioutval; Public calculator() { ioutval=0; } Public calculator (int ival1) { ioutval=1 val1;} Public void display ioutval) {console write line(ioutval={0}; ioutval);} Public void add(int ival1,int ival2) {ioutval=ival1-ival2;} }

Class start {public static void main() {calculator c = new calculator (50); c.add (12,23); c.display ioutval (); c.subtract (24,4); display ioutval1); console . readkey (); } } } OUTPUT ioutval1=35 ioutval=20

Q.8 WAP in c# to find area of the circle and square Using system; Answer:

Using system.collections.generic; Namespace area {class area 1 {static area void main(string []) Int a,c; Console.writeline(enter your choice /n 1.circle 2.square); C=int.parse(console.readline(0)); Switch (c) {case1: Console.writeline(area of circle={0},3.14*a*a); Break ; Case2: Console.writeline(area of square={0},a*a); Break}; Console.readkey(); } }}

Q. 9 WAP to demonstrate operator overloading Answer Using system Class square { private double side; Public square (int s) { console.writeline (etor with argument) Side = (double s) ; } Public square (double s) { console.writeline {etor with double argument} Side = s ; } Public override string to string ( ) {console.writeline (override object class s string)\ Return this side to string( ) ; } Public static square operator+ (square x square y) {console.writeline(overloading+with square, square) ; Return new square ( x side + y side); } Public static square operator + (square x, double y) {return new square (x side + y); Public static square operator + ( square x. int y); {return x+(double)y};

Public static implicit operator square(double i) {console.write line(overloading =); Return new square ((double)j)}; Public static boot operator= = (square x,square y); {console.writeline(overloading ==); Return x.side ==y.sides}; Public static boot operator!=(square x.square y) {return!(x==y)}; Public override boot=(object o) {return(int)side }; Public double area { get {return 2*side}; } Public static void main(string[]args) {square s 1=new square (10); Square s 2=new square(20); Square s 3=s1+s2; } Console.write line(j3); Console.writeline(j3+i5);

Console.writeline (j3+i.5); j3=10; console.writeline(j3); square s4=10; console.writeline(s1==s4); console.writeline(s1!=j4); console.readkey(); } }

Q. 10 WAP to check whether the two entered srings are equal or not. Find the length of each stream Answer: Using system ; Using system.convection.genric; Using system.text;

Namesapce console application; { Class program { Static void main (string [ ] args) { Console.writeline (enter first stream); String fstring = console.readline ( ) ; Console.writeline (enter second stream); String sstring = console.readline ( ) ; If (fstring.equals(string)) Console.writeline (strings are equal); Else Console.writeline (strings are not equal); Console.writeline (length of string 1 is:) Console.writeline (fstring.length( ));

Console.writeline (length of string 2 is:) Console.writeline(sstring.legth ( ) ); Console.readkey ( );

OUTPUT

Enter first string ABC Enter second stream XYZE Streams are not equal Length of string 1 is: 3 Length of string is: 4

Q.11 WAP to find the second largest element in a single dimensional array. Answer: Using System; Using System.Collections.Generic; Using Linq; Namespace Test; { class Array { static void main(String[]args) { int array[]={250,12,34,54,73,260,232,234,235,300}; int max,smax; max=array[0]; smax=0; Console.WriteLine(Initial Value+max); for(int i=0;i<=array.length;i++) { if(array[i]>max){ smax=max; max=array[i];} else if(array[i]>smax){ smax=array[i]; }} Console.WriteLine(Max element is {0},max); Console.WriteLine(second max element is{0},smax); } }}

Q.12 WAP to reverse a string.

Answer: Using System; namespace programcode { class stringreverse { static void main(String[]args) { String str,revstr= ; Console.WriteLine(Enter a String); Str=Console.ReadLine(); for(int i=str.length-1;i>=0;i--) { revstr=revstr+str[i]; } Console.WriteLine(Reverse string is {0},revstr); Console.ReadLine(); }} } Output Enter a string RICHA Reverse string is AHCIR

You might also like