1043006

C# PRACTICAL
PRACTICAL NO: - 01 TITLE:- Write a program to perform following task a. Declare two variable x and y at float types variables. b. Declare m as an integer variable c. Assign the value 75.86 to x and 143.48 y d. Assign the sum of x and y to m e. Display the value of m f. Comment on the output CODING:using System; class edit { public static void Main() { float x,y; int m; x=75.86F; y=143.48F; m=(int)(x+y); Console.WriteLine("The sum of two float number is:"+m); } } OUTPUT:-

1

1043006 PRACTICAL NO: - 02 TITLE:- Write a program to demonstrate the use of concept of Boxing and Unboxing CODING:using System; class edit { public static void Main() { int m=100; object om=m; m=20; Console.WriteLine("The value of m is : "+m); Console.WriteLine("The value of om is : "+om); int n=(int)om; Console.WriteLine("The value of n is : "+n);//n=100 } } OUTPUT:-

PRACTICAL NO: - 03 TITLE:- Write a program to read interactively two integers using the method Console.ReadLine () and int.Parse and display their sum, difference, product, division and modulus division.

2

1043006 CODING: using System; class edit { public static void Main() { int x,y; Console.WriteLine("Enter the first number:"); x=(int.Parse)(Console.ReadLine()); Console.WriteLine("Enter the second number:"); y=(int.Parse)(Console.ReadLine()); int sum=x+y; Console.WriteLine("The Sum of two number is : "+ sum); int diff=x-y; Console.WriteLine("The difference of two number is:" +diff); int mul=x*y; Console.WriteLine("The Multiplication of two number is: "+mul); int div=x/y; Console.WriteLine("The Division of two number is : "+ div); int mod=x%y; Console.WriteLine("The Modulus of two number is : "+ mod); } } OUTPUT:-

PRACTICAL NO: - 04 TITLE :- State why the expression x-y=10 is invalid but the expression x-(y=100) execute the program to demonstrate the answer.

3

1043006 CODING: A) Expression x-y=10 using System; class edit { public static void Main() { int x=0; int y; int r; r=(x-y=100); Console.WriteLine("The value is :" +r); } } OUTPUT:

B) Expression x-(y=100) CODING: using System; class edit { public static void Main() { int x=0; int y; int r; r=x-(y=100);

4

1043006 Console.WriteLine("The value is :" +r); } } OUTPUT:

PRACTICAL NO: - 05 TITLE:- Given the radius of 12.5cm.Write a program to compute it’s circumference and area and gives its value. CODING: using System; class edit { public static void Main() { float rad=12.5F; double area,circum; area=(3.14)*(rad*rad); circum=2*3.14*rad; Console.WriteLine("The area of the circle is : " + area); Console.WriteLine("The circumfurance of the circle is:"+circum); } }

5

6 . Count=count+1. CODING: using System. ifgo: if(x<=20) { if(x%2!=0) { Sum=sum+x. int sum=0. int count=0.06 TITLE = Write a program to add all the odd numbers from 0 to 20 use a simple if and goto statements to form a loop of operations. } x=x+1. class usegotoloop { public static void Main() { int x=0.1043006 OUTPUT : PRACTICAL NO: . goto ifgo.

1043006 } Console.07 TITLE:. p=(int.Parse)(Console. 7 .ReadLine()).Admission for professional course is subject to the following condition a) Marks in mathematics >= 60 b) Marks in Physics >=50 c) Marks in chemistry >= 40 d) Marks in all subject >= 200 OR e) Total in mathematics and physics >=150.WriteLine ("The sum of odd numbers is:"+sum).WriteLine("Enter the marks of the physics:"). m=(int.WriteLine("Enter the marks of the maths:").p.Parse)(Console. Console. } } OUTPUT: PRACTICAL NO: . Console. CODING: using System. class edit { public static void Main() { int m. int at.WriteLine ("The total numbers of odd numberis:"+count).mpt. Console.ReadLine()).c.

int sum=0.i<200.1043006 Console.ReadLine()).08 TITLE:.Write a Program to find total number of and sum of integer greater than 100 and less than 200 that are divisible by 7. } } } OUTPUT:- PRACTICAL NO: . if((m>=60 && p>=50 && c>=40) && (at>=200 || mpt>=150)) { Console. class edit { public static void Main() { int count=1. mpt=(m+p). } else { Console.i++) { 8 .WriteLine("You are eligible for the professional course admission ").WriteLine("Enter the marks of the chemistry:"). at=(m+p+c).Parse)(Console..WriteLine("You are not eligible for the professional course admission "). for(int i=100. c=(int. CODING:using System.

y.09 TITLE = Write a Program to that will read the value of x and evaluates the function.WriteLine("The total numbers that are divisible by 7 are : " + count).conditional opearator. } } Console. } } OUTPUT:- PRACTICAL NO: . Y= {1if x>0} {0 if x=0} {-1 if x<0} Using nested if statement else if statement . class nestedif { public static void Main() { int x.1043006 if(i%7==0) { count=count+1. sum=sum+i. 9 . Console.WriteLine("The sum of numbers that are divisible by 7 is : "+sum). CODING: a) Using if statement using System. Console.WriteLine("Enter the value of x: ").

ReadLine()).WriteLine("The value of y is :" +y). } if(x==0) { y=0. Console. Console.Parse)(Console. if(x>0) { y=1.WriteLine("The value of y is :"+y).1043006 x=(int. if(x>0) Console. int x=int.ReadLine()).WriteLine("y= "+0). }} } OUTPUT:- Using else if statement: using System. class firstmat { public static void Main() { Console.WriteLine("y = "+1). else if(x==0) Console.Parse(Console.WriteLine("Enter the value of the x:"). Console.WriteLine("The value of y is :"+y). } if(x<0) { y=(-1). 10 .

} } OUTPUT:- Using conditional operator CODING: using System. y=x>1?1:-1.WriteLine("The value of y is : "+y). Console. class firstmat { public static void Main() { int y.WriteLine("y= "+(-1)). } } OUTPUT: 11 . Console.Parse(Console.ReadLine()).WriteLine("Enter the value of the x:"). if(x==0) y=0.1043006 else Console. int x=int.

int rem. Console.WriteLine("The addition of given digits of number is:" + sum).Parse)(Console. int sum = 0. class DigitSum { public static void Main() { int x. sum = sum + rem.1043006 PRACTICAL NO: . x = x / 10.ReadLine()). while (x > 0) { rem = x % 10. } Console.10 TITLE :-Write a Program to compute the sum of digits of a given integer. CODING: using System.WriteLine("Enter The Number: "). x = (int. } } OUTPUT: 12 .

b=c. int a=1. int b=1.WriteLine("The fibonacci series is as follow:"). Console. int i=0.Write(a+ " " + b + " "). a=b. CODING: using System. do { c=a+b.c=0.ReadLine()). Console. 13 .1043006 PRACTICAL NO: -11 TITLE:. Console.WriteLine("Enter The Number upto which you want to print the fibonacci number:" ).Write a Program using do while loop to calculate and print the first m Fibonacci numbers.Parse)(Console. class DigitSum { public static void Main() { int x. x=(int.

i++) { for(int j=1. class pattern { public static void Main() { int x.ReadLine()). x=(int. for(int i=1.j++) 14 .i<=x.Parse)(Console. Console.1043006 Console.j<=i.Write(c+ " "). i++. } while(i<(x-2)). } } OUTPUT: PRACTICAL NO: -12 TITLE:.Write("Enter The Number of rows : " ).Write a Program to print the following outputs using for loops a) 1 c) 1 b)$ $ $ $ 22 2 2 $$$ 333 3 3 3 $$ 4444 4 4 4 4 $ CODING:A)using System.

1043006 { Console.i++) { for(int j=x.Parse)(Console. class pattern { public static void Main() { int x.Write("Enter The Number of rows : " ).k<=i. } } } OUTPUT: B) CODING: using System.WriteLine(). } Console. x=(int.Write(i+ " ").i<=x. Console.ReadLine()). for(int i=1.j--) { Console.Write(" ").j>i. } for(int k=1.k++) { 15 .

} } } OUTPUT: C) using System. } Console.Write(" " + "$" + " ").i<=x. } Console.1043006 Console.WriteLine().WriteLine(). Console.Write(i+" ").Parse)(Console. class pattern { public static void Main() { int x. } } } 16 .ReadLine()).j>=i.i++) { for(int j=x.Write("Enter The Number of rows : " ). x=(int.j--) { Console. for(int i=1.

i<100.1043006 OUTPUT: PRACTICAL NO: -13 TITLE:. a) break b) continue c) goto CODING:using System. } 17 .j<100.j++) { Console. for(int j=1.WriteLine(" ").i++) { Console. if(j==i) goto loop1.Write("*"). if(i>=10) break. class GotoLabel { public static void Main() { for(int i=1.Demonstrate the typical use of the following jump statement.

while(num>0) { rem=num%10. CODING:using System.Write a program using while loop to reverse the digit of a number. int rev=0. } } OUTPUT: PRACTICAL NO: -14 TITLE:. rev=rev*10+rem. 18 . num=(int.WriteLine("Termination by BREAK").ReadLine()). class ContinueBreak { public static void Main() { int num. } Console.Parse)(Console.Write("Enter the number to reversed:").1043006 loop1:continue.rem. Console. num=num/10.

1043006 } Console. 19 ..WriteLine("The reverse of the number is :"+rev). 1 23 456 7 8 9 10 ………. } } OUTPUT: PRACTICAL NO: -15 TITLE:.91 CODING:using System. int k=1. class umat { public static void Main() { int num.Write a program to print the floyd’s triangle. 79…………….

Parse)(Console. k=k+1.i<=num. for(int i=1. num=(int.j<=i. 1 01 101 0101 10101 Ask the number of rows from the user.Write a program to print the following output.WriteLine().i++) { for(int j=1.ReadLine()). } Console.Write(k+" "). CODING: 20 .1043006 Console.Write("Enter the number of rows:").j++) { Console. } } } OUTPUT: PRACTICAL NO: -16 TITLE:.

} } } Console.i++) { Console.Parse)(Console. num=(int. for(int i=1.Write(0+" ").WriteLine().i<=num. } } else { if(j%2==0) { Console.Write(1+" ").1043006 using System.Write("Enter the number of rows:").j<=i.ReadLine()). } } } OUTPUT : 21 .j++) { if(i%2==0) { if(j%2==0) { Console. } else { Console. class floyd { public static void Main() { int num.Write(1+" "). for(int j=1. Console.Write(" ").Write(0+" "). } else { Console.

i++) { for(int j=1. CODING: using System.Parse)(Console.j++) 22 .ReadLine()). Console.i<=num.j<=(i-1). 100 010 001 Ask the number of rows from the user. int count=(num-1).1043006 PRACTICAL NO: -17 TITLE:.Write a program to print the following output. class umat { public static void Main() { int num.Write("Enter the number of rows:"). for(int i=1. num=(int.

} count=count-1. for(int k=count. } }} OUTPUT: PRACTICAL NO: -18 TITLE:.Write a program to calculate the standard deviation of an array of values. Console.k>0. 23 .Write(0+" "). class edit { public double mean(params int[] z) { int sum=0.Write(1+" "). Use methods “standard” and “mean” to calculate the standard deviation and mean of the values.k--) { Console. } Console.Write(0+" "). CODING: using System.1043006 { Console. .WriteLine().

for(i=0. double sd=(double)(Math. } double avg=sum/(double)(z.int b.i++) { x[i]=int.WriteLine("Enter the value of the frequency f:").Length.mean(x). int i.Sqrt(v)). Console. int[] f=new int[5].i++) { f[i]=int.double c) { double v=(double)((a/b)-(c*c)). } public static void Main() { edit obj=new edit().i<5.i<z.1043006 for(int i=0.Parse(Console. int n=0. n=n+f[i]. return avg. } double m=obj.Parse(Console.Length). for(i=0.ReadLine()).ReadLine()). } for(i=0.WriteLine("Enter the value of the variate x:"). Console.i++) { sum=sum+z[i]. } Console.i++) { fx=fx+(f[i]*(x[i]*x[i])). 24 . int fx=0. int[] x=new int[5]. } public void standard(int a.i<5.WriteLine("The standard deviation is : "+sd).i<5.

Write a program that uses to sort and array of integer ascending and descending order. for(int i=0.Length. Console.i++) { Console.standard(fx.89.Write("Given list:"). class umat { public static void Main() { int[] number={43. } 25 .1043006 Console. . } } OUTPUT: PRACTICAL NO: -19 TITLE:.WriteLine("The mean is :" +m).m). int n=number.i<n. CODING: using System.Write(" "+number[i]).n.56}.67. obj.43.90.

Write(" "+number[j]). for(int i=0.i<n.WriteLine().Write("Sorted list:").Write("Array sorted in ascending order:"). } } OUTPUT: 26 .j<n. } Console.1043006 Console. number[i]=number[j]. } } } Console. for(int i=0.WriteLine(). for(int j=n-1.Write(" "+number[i]).i<n.j++) { if(number[i]<number[j]) { int temp=number[i].Write("\n").i++) { Console.j>=0. number[j]=temp.i++) { for(int j=i+1. Console.j--) { Console. } Console.

Write(" "+num[i]). for(i=0. } Console.Parse(Console.WriteLine("Enter five element into the array:").WriteLine("The elements present in the array are:"). for(i=0.Length. int[] num=new int[5].1043006 PRACTICAL NO: -20 TITLE:.Develop the program that uses a method to find a largest and a smallest number from an array of integer.Length. CODING: using System. int i.i++) { Console. Console.i++) { num[i]=int.i<num. } 27 .ReadLine()).i<num. class umat { public static void Main() { umat obj=new umat().

i++) { if(max < num1[i]) max=num1[i].WriteLine().WriteLine("The minimum of the given number:"+min).Length. obj.find(num). for(i=1.Length.WriteLine("The maximum of the given numbers is:"+max). } Public void find(params int[] num1) { int max=num1[0].i<num1.1043006 Console.i<num1. } Console. } } OUTPUT: PRACTICAL NO: -21 28 . } Console.i++) { if(min > num1[i]) min=num1[i]. int min=num1[0]. for(i=1.

int n=int. else Console.i<num. int flag=1.WriteLine("The number is present in the array").WriteLine("The number is not present in the array"). Console. class umat { public static void Main() { int i.i++) { if(num[i]==n) { flag=0.ReadLine()).1043006 TITLE:.Develop the program to search the number from array of integer.Length. break. int[] num=new int[5]. CODING: using System.Length.i++) { num[i]=int. for(i=0.Parse(Console. for(i=0.ReadLine()). } } OUTPUT: 29 .i<num. } } if(flag==0) Console. } Console. } else { flag=1.Parse(Console.WriteLine("Enter five element into the array:").WriteLine("Enter the number you want to search in array").

i++) { if(x%i==0) { flag=1. break.Write a program that return a true if its argument is prime and return false otherwise. } 30 . for(int i=2. } else { flag=0. CODING: using System. class edit { public bool Prime(int x) { int flag=0.1043006 PRACTICAL NO: -22 TITLE:. bool r.i<x.

result=obj.ReadLine()). return r.1043006 } if(flag==0) r=true. edit obj=new edit().WriteLine("Enter the number:"). } public static void Main() { int i.Parse(Console. Console. i=int. Console.Prime(i). bool result. else r=false. } } OUTPUT: PRACTICAL NO: -23 31 .WriteLine(result).

Parse(Console. } public static void Main() { int a.WriteLine("Enter the first number:").ReadLine()). class edit { public void product(int x.int y. Console.WriteLine("The result of multiplication is:"+c). a=int. } } OUTPUT: PRACTICAL NO: -24 32 .out c).ReadLine()).1043006 TITLE:.Parse(Console.WriteLine("Enter the second number:"). CODING: using System. Console.c. Console. b=int.b. out int z) { z=(x*y).b.Write a void type method that takes two int type values parameters and 1 int type out parameter and return the product of two value parameter through the output parameter.product(a. edit obj=new edit(). obj.

ReadLine()). b=int.b. for(int i=1. CODING: using System. } return min.Parse(Console. edit obj=new edit().ReadLine()).WriteLine("Enter the second number:"). class edit { public int Compare(params int[] z) { int min=z[0]. c=int.1043006 TITLE:.WriteLine("Enter the first number:").c).i<z.Length.Compare(a. Console.Parse(Console.Parse(Console. a=int.WriteLine("The Smallest number is :"+result).c.WriteLine("Enter the third number:"). Console.ReadLine()). int result=obj. Console.Write a method that takes 3 values as input parameter and Returns the smallest of three values. } } OUTPUT: 33 . } public static void Main() { int a.b. Console.i++) { if(min > z[i]) min=z[i].

c.Parse(Console.ReadLine()).b. b=int.WriteLine("Enter the first number:"). class edit { public int Compare(params int[] z) { int max=z[0]. } return max.WriteLine("Enter the second number:"). } public static void Main() { int a. Console.i++) { if(max < z[i]) max=z[i].i<z.ReadLine()). CODING: using System.Length. for(int i=1. Console.Write a method that takes 3 values as input parameter and Returns the largest of three values.Parse(Console. a=int.1043006 PRACTICAL NO: -25 TITLE:. 34 .

WriteLine("Enter the third number:"). int result=obj. CODING: using System. Console. } } OUTPUT: PRACTICAL NO: -26 TITLE:.Compare(a.1043006 Console. 35 . class edit { public void avgmax(params int[] z) { int max=z[0].c). c=int.Parse(Console. edit obj=new edit().WriteLine("The Largest number is :"+result).b.Write a method that takes an array as an input parameter uses 2 methods a) To find largest array element b) To compute the average of array element.ReadLine()).

} } OUTPUT: 36 . Console. } public static void Main() { edit obj=new edit().Length).WriteLine("The avarage of the entered number is :"+avg).Length.WriteLine(). } Console.Length. for(int i=0. } sum=sum+z[i].Length. int avg=(sum)/(z. for(int i=0.avgmax(num).WriteLine().i<z.WriteLine("Enter the 10 numbers into the array : ").1043006 int sum=z[0].Write(" " +num[i]).i++) { Console.WriteLine("The element present in the array are: ").WriteLine("The maximum of the enter element is : "+max). Console.i<num.Parse)(Console.ReadLine()). } Console.i++) { if(max < z[i]) { max=z[i]. int[] num=new int[10]. obj. Console.i<num. for(int i=1.i++) { num[i]=(int. } Console.

} } else { Console.Length==5) { for(i=0.1043006 PRACTICAL NO: -27 TITLE:.i++) { str[i]=arg[i]. CODING: using System.WriteLine("You can enter only five element at a time!!"). class edit { public static void Main(String [] arg) { int i.i<5. if(arg. string[] str=new string[5]. } 37 .Write a program to accept a shopping list of five items from the command line and stored them in string type array and then print the list in alphabetical order.

CODING:CODING:using System.Length.-. Overload +.Create a class named Double.*./ operators so that they can be applied to the objects of the class Double. Console. for(i=0.Length. Write a c# program to test it.1043006 for(i=0.i<str.i<str. class Double { 38 .i++) { Console.Sort(str).WriteLine(" "+str[i]). } Array. This class contains three double numbers.i++) { Console.WriteLine("The elements arraange in the alphabetical order are as follow:").WriteLine(" "+str[i]). } } } OUTPUT: PRACTICAL NO: -28 TITLE:.

9. } public static Double operator /(Double r1.2).r1. s3. s3=s1 . } public static Double operator -(Double r1.16. s3. double d2) { this.WriteLine("The multiplication of the two numbers: ").i.j-r2.i-r2. Console.WriteLine("The sum of the two numbers: ").j*r2. } public void displayOutput() { Console.i.WriteLine(i+ " " +j).displayOutput().r1. Double(double d1.j+r2.j).1043006 double i. } } 39 .j).displayOutput().j). double j.s2.i. this. Double s2 = new Double(7.r1.i.9.i/r2.j/r2. } public static Double operator *(Double r1.j = d2.i = d1.i*r2.WriteLine("The subtraction of the two numbers: ").WriteLine("The division of the two numbers: "). } static void Main(string[] args) { Double s1 = new Double(5.r1. s3.j). Console.displayOutput().displayOutput().5). s3=s1 / s2.i+r2.Double r2) { return new Double(r1.Double r2) { return new Double(r1.Double r2) { return new Double(r1.Double r2) { return new Double(r1. s3=s1 * s2. Console. Console. } public static Double operator +(Double r1. Double s3 =s1 + s2.7. s3.

class example { int y.\n"). } void x() { Console.WriteLine("OBJECT DIES. Console. example(int c) { y=c.Create a class example to hold one integer value. Write a c# program to demonstrate the creation and destruction of objects of example class.WriteLine("\nOBJECT IS BORN. Console. CODING:using System.\n\n")."). 40 . Include a constructor to display the message “Object is created” and a destructor to display the message “Object is destroyed”. } static void Main(string[] args) { example z = new example(114).WriteLine("value is " +y). z. } ~example() { Console.1043006 OUTPUT:- PRACTICAL NO: -29 TITLE:.x().WriteLine("NOW X IS ALIVE.

WriteLine("Exception message " + noExcep.WriteLine("Exception is caught").Write a c# program that throws NumberNotInRange exception if number entered by user is not in the range 1 to 100. } } 41 . CODING:using System. class NumberNotInRange : System.Exception { public static void Main(string[] args) { int no = int. try { if(no<1 || no>100) { throw new NumberNotInRange(). Console.1043006 Console.Message). } } OUTPUT:- PRACTICAL NO: -30 TITLE:.Parse(args[0]).ReadLine(). } } catch(NumberNotInRange noExcep) { Console.

0.cel. cel).WriteLine("{0.1) to Celsius using the formula C=(F-32)/1.20}\t{1.5.8.5 to 102 in steps of 0.Write a program to convert the temperature in Fahrenheit(starting from 98.1043006 } OUTPUT:- PRACTICAL NO: -31 TITLE:. for(far = 98.far. Console.8 and display the values in a tabular form.WriteLine("Fahrenheit Celcius").20}".far <= 102.32) / 1. class FahrenCelcius { static void Main(string[] args) { double far.1) { cel = (far . } } } 42 . CODING:using System. Console.far = far+0.

1043006 OUTPUT:- PRACTICAL NO: -32 TITLE:.Write a program that Prints the following form * * * * * * * * * * * * * * * CODING:using system. class asterikprint { static void main(string[] args) { 43 .

write a program to compute and print the number of students who have obtained marks.Given a list of marks ranging from 0 to 100.--k) { console. } for(k=sp.u. u=5. for(i=0.1043006 int i.sp. } --u.--sp) { console. and (d) In the range 0 to 40 CODING:using System.writeline().k>0.++i) { for(sp=5. 44 . (a) In the range 81 to 100 (b) In the range 61 to 80 (c) In the range 41 to 60.write(" *"). console.write(" ").k. } } } OUTPUT:- PRACTICAL NO: -33 TITLE:.i<5.sp>u.

Console.WriteLine("No.WriteLine("No. 34. fail = 0. if (students[i] >= 41 && students[i] <= 60) third++.WriteLine("No. int first = 0.Read(). of students obt. Console. of students obt. 89.Length. } } OUTPUT:- 45 . mrks bet 81 and 100 are :" + first). mrks bet 41 and 60 are :" + third). } Console. of students obt. of students obt. 67.WriteLine("No. mrks bet 61 and 80 are :" + second). i++) { if (students[i] >= 81 && students[i] <= 100) first++. second = 0. 76. 95. Console.1043006 class StudMarksObt { public static void Main(string []args) { int[] students = { 45. 24 }. if (students[i] >= 0 && students[i] <= 40) fail++. 0. mrks bet 0 and 40 are :" + fail). 57. third = 0. if (students[i] >= 61 && students[i] <= 80) second++. for (int i = 0. Console. i < students.

a = x.b = y.Write a program to show the implementation of multiple interfaces. } class calculator : addition. } interface division { int divide(). subtraction. public calculator(int x. multiplication. } 46 .1043006 PRACTICAL NO: -34 TITLE:. this. b. division { int a. CODING:using system. int y) { this. interface addition { int add(). } interface multiplication { int multiply(). } interface subtraction { int sub().

b). } } class prac40 { public static void main() { calculator c = new calculator(8. 3). division div1 = (division)c. console.writeline("multiplication={0}".readline(). } public int sub() { return (a . subtraction sub1 = (subtraction)c. addition ad1 = (addition)c.1043006 public int add() { return (a + b). console.writeline("subtraction={0}".add()). sub1.divide()). div1.writeline("division={0}". console. } public int multiply() { return (a * b).writeline("addition={0}". console. mul1. } } OUTPUT:- 47 . ad1.multiply()). multiplication mul1 = (multiplication)c. } public int divide() { return (a / b). console.sub()).

public complex() { } public complex(int i. 48 .y=-c.Write a program to show the implementation of unary operator.1043006 PRACTICAL NO: -35 TITLE:.y. } public static complex operator-(complex c) { complex temp=new complex().int j) { x = i.x.y).x=-c. private int y. y = j. } public void showxy() { console. temp. return temp. CODING:using system.x. class complex { private int x.writeline("{0} {1}". temp.

showxy().showxy().showxy(). CODING:using System.readline(). using System.Write a program to show how to use the ArrayList class. class MainClass { public static void Main() { 49 . c2=-c1.Collections. } } OUTPUT:- PRACTICAL NO: -36 TITLE:. complex c2=new complex().1043006 } } class prac41 { public static void main() { complex c1=new complex(10. c2. 20). c1. console. c2.

DisplayArrayList("myArrayList". 50 .Count.AddRange(myStringArray). } } } OUTPUT:- PRACTICAL NO: -37 TITLE:.Count.Write a program to create a class which can hold a complex number (X+iY) and using operator overloading perform the addition and subtraction of two complex numbers. CODING:using System. "test" }. "more". myArrayList). Console.ReadLine(). "text" }. public struct Complex { public int real.WriteLine(arrayListName + "[" + i + "]=" + myArrayList[i]). string[] anotherStringArray = { "here's".1043006 ArrayList myArrayList = new ArrayList(). myArrayList.Add("is").Insert(1. myArrayList. myArrayList. public int imaginary. ArrayList myArrayList) { for (int i = 0.InsertRange(myArrayList. i < myArrayList. anotherStringArray). "some". i++) { Console. } public static void DisplayArrayList(string arrayListName. string[] myStringArray = { "a". myArrayList. "is").

Console.imaginary=imaginary.real.3).c). Console.WriteLine("Second complex number: {0}". Complex c=num1+num2.real.WriteLine("The sum of the two numbers:{0}".real=real. } public static Complex operator -(Complex c1. Console. } public static Complex operator +(Complex c1.imaginary).num1). Console.num2).real.c). } } class TestComplex { public static void Main() { Complex num1=new Complex(2.1043006 public Complex(int real.Complex c2) { return new Complex(c1.c1.imaginary+c2.real-c2. Console. this.real+c2.c1. } } OUTPUT:- 51 . c=num1-num2.4).Format("{0}+{1}i".imaginary).int imaginary) { this.imaginary)).Read().Complex c2) { return new Complex(c1.imaginary-c2.WriteLine("The subtraction of two numbers:{0}". } public override string ToString() { return (String. Complex num2=new Complex(3.WriteLine("First complex number: {0}".

Define a class Demo that implements this interface. (ii) to calculate cube of the given number. (iii) To calculate power ‘m’ raised to ‘n’. interface power { int square(int a).Define an interface that contains three methods (i) To calculate the square of the given number. int cube(int b). CODING:using System. } class Demo : power { public int square(int a) { return(a * a). } public int cube(int b) { return(b * b * b). int n). } public double pows(double g. int n) { 52 . Write a main method to check your code. double pows(double m.1043006 PRACTICAL NO: -38 TITLE:.

return(g).pows(2.Write a class Date that includes data members day. Console.00}" . power pow. } } class PowerInt { static void Main(string[] args) { Demo dem = new Demo().WriteLine("power of no = {0:0.7.WriteLine("Square of no.2)).WriteLine("cube of no = {0}". Console. (ii) Display a date (iii) Increment a date by one day. 53 . Write a main method to check your code. pow.i++) g=g *i. ={0}" . Console.square(3)). (i) Read a date from keyboard.pow. } } OUTPUT:- PRACTICAL NO: -39 TITLE:.1043006 for(int i=1.i<=n. pow = dem as power. month and year and methods that could implement the following tasks.cube(7)).pow. (iv) Compare two dates to see which is greater.

p). string p= Console.WriteLine("Second Date entered is {0}".1043006 CODING:using System. CODING:- 54 . Console.WriteLine("{0} is greater than {1} ". Write a program to merge them into a single sorted array ‘C’ that contains every item from arrays ‘A’ and ‘ B’ in ascending order. Console. p). class Date { static void Main(string[] args) { Console.WriteLine("First Date entered is {0}". Console.ReadLine().ReadLine().CompareTo(p)>0) Console. if(k. k).Given are two one dimensional arrays ‘A’ and ‘B’ which are in sorted order.WriteLine("Please enter the date dd/mm/yyyy").ReadLine(). else Console. p. k. } } OUTPUT:- PRACTICAL NO: -40 TITLE:. k).WriteLine("{0} is greater than {1} ". string k= Console.

Write a main program to implement class Integer and method Swap. class arrayMerge { static void Main(string[] args) { int i.k.Length).Length. int[] B={60.79. for(i=0.h<C. CODING:using System.j.k++) { C[j]=B[k].j<(i+B.114.32.67. int[] C=new int[10].i++) { C[i]=A[i].170}. class Integer1 { 55 . for(int h=0. } Array.k=0. } for(j=i. Design a method ‘Swap’ that could take two integer objects as parameters and swap their contents.Write(C[h] + " ").h++) Console.Sort(C).j++. int[] A={14.88.Length.Create a class named ‘Integer’ to hold two integer values.53.i<A.53}. } } OUTPUT:- PRACTICAL NO: -41 TITLE:.1043006 using System.

temp2 = x.h=temp2. } static void Main(string[] args) { Integer1 t1 = new Integer1(5.h.h. Integer1 y) { int temp1. } void display() { Console. Integer1 t2 = new Integer1(9. x. y. t2.display().12).WriteLine(g + " and " + h). x.g.h = i2.h=y. Integer1(int i1.g = i1. swap(t1. temp1 = x.display(). int h. temp2.display(). this. int i2) { this. t2.7). } static void swap(Integer1 x. t2).1043006 int g. } } OUTPUT:- 56 .g. t1. t1. y.display().g=temp1.g=y.

ReadLine(). class NoMatchException : System.WriteLine("Exception message"+noMExcep.str).Define an exception called “NoMatchException” that is thrown when a string is not equal to “TYBSCIT”. try { if(!(str. } else Console.Exception { public static void Main(string[] args) { string str = Console.1043006 PRACTICAL NO: -42 TITLE:. } } 57 .Equals("TYBSCIT"))) { throw new NoMatchException(). CODING:using System.WriteLine("Exception is caught").Message). } catch (NoMatchException noMExcep) { Console. Console. Write a program that uses this exception.WriteLine("Not entered TYBSCIT instead entered string{0}".str).WriteLine("You entered the string {0} ". { Console.

1043006 } } OUTPUT:- 58 .

Sign up to vote on this title
UsefulNot useful