C - Lab Manual
C - Lab Manual
C - Lab Manual
To write a c# program to perform the branching and looping operation. Algorithm: Step1: Step2: Step3: Step4: Step5: Step5: Step6: Start the process. Open the console application and create the class. Declare the variable Create an object for class Perform the branching and looping operation Print the result Stop the process.
Program: using System; class Sample { public static void Main() { int a,b,c; Console.WriteLine(); Console.WriteLine("Simple if Statement"); Console.Write("Enter the value for A : "); a=int.Parse(Console.ReadLine()); if(a>0) Console.WriteLine("A is greater"); Console.WriteLine(); Console.WriteLine("if...else Statement"); Console.Write("Enter the value for B : "); b=int.Parse(Console.ReadLine()); if(a>b) Console.WriteLine("A is greater"); else Console.WriteLine("B is greater"); Console.WriteLine(); Console.WriteLine("Nested if...else Statement"); Console.Write("Enter the value for C : "); c=int.Parse(Console.ReadLine()); if(a>b) { if(a>c) { Console.WriteLine ("A is greater : "+a); } else
{ Console.WriteLine ("B is greater : "+b); } } else { if(c>b) { Console.WriteLine ("C is greater : "+c); }
else { Console.WriteLine ("B is greater : "+b); } } Console.WriteLine(); Console.WriteLine("else if Ladder"); if(a>0) Console.WriteLine("A value is : "+a); else if(a>b) Console.WriteLine("A is Greater "); else if(b>c) Console.WriteLine("B is Greater "); else if(c>a) Console.WriteLine("C is Greater "); Console.WriteLine(); Console.WriteLine("Switch Statement"); Console.WriteLine("Select your choice"); Console.WriteLine("A"); Console.WriteLine("B"); Console.WriteLine("C"); Console.Write("Enter your choice : "); string ch=Console.ReadLine(); switch(ch) { case "A": Console.WriteLine("A value is "+a); break; case "B": Console.WriteLine("B value is "+b); break; case "C": Console.WriteLine("C value is "+c); break; default: Console.WriteLine("Invalid choice"); break; }
Console.WriteLine(); Console.WriteLine("For Loop"); int []d=new int[5]; Console.Write("Enter the value for N : "); int n=int.Parse(Console.ReadLine()); Console.WriteLine("Enter the values"); for(int i=0;i<n;i++) d[i]=int.Parse(Console.ReadLine()); Console.WriteLine(); Console.WriteLine("Foreach Statement"); Console.WriteLine("The array values are "); foreach(int e in d) Console.WriteLine(""+e); Console.WriteLine(); Console.WriteLine("While Loop"); Console.Write("Enter the value for K :"); int k=int.Parse(Console.ReadLine()); while(k<10) { Console.WriteLine(""+k); k++; } Console.WriteLine(); Console.WriteLine("Do...While Loop"); Console.Write("Enter the value for M : "); int m=int.Parse(Console.ReadLine()); do { Console.WriteLine(""+m); m++; }while(m<10); Console.ReadLine(); } }
Output Simple if Statement Enter the value for A : 0 if...else Statement Enter the value for B : 2 B is greater Nested if...else Statement Enter the value for C : 6
C is greater : 6 else if Ladder C is Greater Switch Statement Select your choice A B C Enter your choice : B B value is 2 For Loop Enter the value for N : 5 Enter the values 6 3 9 2 4 Foreach Statement The array values are 6 3 9 2 4 While Loop Enter the value for K :4 4 5 6 7 8 9 Do...While Loop Enter the value for M : 6 6 7 8 9 Result: Thus the program has been executed successfully and verified.
Exno: 2 A Aim:
Operators
To write a c# program to perform the operators Algorithm: Step1: Step2: Step3: Step4: Step5: Step6: Start the process. Declare the variable and initialize the values Perform the various operation using operators. Perform the operation Display the result. Stop the process.
Program: using System; class Sample { public static void Main() { int a=10,b=20; int x,y,z; Console.WriteLine("Addition value is : "+(a+b)); Console.WriteLine("Subtraction value is : "+(a-b)); Console.WriteLine("Multiplication value is : "+(a*b)); Console.WriteLine("Division Value is : "+(a/b)); Console.WriteLine("Modulo division value is : "+(a%b)); if(a>b) { Console.WriteLine("A is greater"); } else { Console.WriteLine("B is greater"); } if((a<b)&&(a<b)) { Console.WriteLine("TRUE"); } else { Console.WriteLine("FALSE"); } x=(a>b)?a:b; Console.WriteLine("X value is : "+x); y=++a; z=--b; Console.WriteLine("Y value is : "+y); Console.WriteLine("Z value is : "+z); Console.WriteLine("Bitwise AND is : "+(a&b));
Console.ReadLine(); } }
Output Addition value is : 30 Subtraction value is : -10 Multiplication value is : 200 Division Value is : 0 Modulo division value is : 10 B is greater TRUE X value is : 20 Y value is : 11 Z value is : 19 Bitwise AND is: 3
Result: Thus the program has been executed successfully and verified.
Exno: 2 B Aim:
Method parameters
To write a c# program to perform the method parameters Algorithm: Step1: Step2: Step3: Step4: Step5: Step6: Start the process. Declare the variable and initialize the values Perform the various by using different methods and parameters. Perform the operation Display the result. Stop the process.
Program: using System; class Sample { static void swap(ref int a,ref int b) { int t; t=a; a=b; b=t; } static void add(int p,int q,out int r) { r=p+q; } static void display(int o) { Console.WriteLine("Value Parameter:"+o); } static void arr(params int []a) { foreach(int i in a) Console.WriteLine(""+i); } public static void Main() { int m=10,n=20; int z; Console.WriteLine(); Console.WriteLine("Before Swapping"); Console.WriteLine("the value is:"+m); Console.WriteLine("the value is:"+n); Console.WriteLine(); Console.WriteLine("Reference Parameter"); Console.WriteLine("After Swapping"); swap(ref m,ref n);
Console.WriteLine("the value is:"+m); Console.WriteLine("the value is:"+n); Console.WriteLine(); Console.WriteLine("Output Parameter"); add(6,5,out z); Console.WriteLine("The Result is:"+z); Console.WriteLine(); display(3); Console.WriteLine(); Console.WriteLine("Parameter Array"); int []k={1,2,3}; arr(k); Console.ReadLine(); } } Output Before Swapping the value is:10 the value is:20 Reference Parameter After Swapping the value is:20 the value is:10 Output Parameter The Result is:11 Value Parameter:3 Parameter Array 1 2 3
Result: Thus the program has been executed successfully and verified.
Exno: 3 A Aim:
Array Class
To write a c# program to perform the array class. Algorithm: Step1: Step2: Step3: Step5: Step5: Step6: Start the process. Open the console application and create the class. Declare the variable and assign the values to the variable. Perform the array class methods using the operations. Print the result Stop the process.
Program: using System; class ArrayClass { public static void Main() { int []x={3,4,2,5}; Console.WriteLine("Get Length : "+x.GetLength(0)); Console.WriteLine(); Console.WriteLine("Get Values : "+x.GetValue(0)); Console.WriteLine(); Console.WriteLine("Length : "+x.Length); Console.WriteLine(); x.SetValue(1,3); foreach(int i in x) Console.WriteLine("Set Value : "+i); Console.WriteLine(); Array.Sort(x); foreach(int i in x) Console.WriteLine("Sort : "+i); Console.WriteLine(); Array.Reverse(x); foreach(int i in x) Console.WriteLine("Reverse : "+i); Console.WriteLine(); Console.ReadLine(); } }
Output Get Length : 4 Get Values : 3 Length : 4 SetValue Method 3 4 2 1 Sort Method 1 2 3 4 Reverse Method 4 3 2 1
Result: Thus the program has been executed successfully and verified.
Exno: 3 B Aim:
Array List
To write a c# program to perform the array list methods. Algorithm: Step1: Step2: Step3: Step5: Step5: Step6: Start the process. Open the console application and create the class. Declare the variable and assign the values to the variable. Perform the array list class methods using the operations. Print the result Stop the process.
Program: using System; using System.Collections; class Sample { public static void Main() { ArrayList a=new ArrayList(); a.Add("1"); a.Add("2"); a.Add("3"); a.Add("4"); a.Add("5"); a.Add("6"); a.Add("7"); for(int i=0;i<a.Count;i++) Console.WriteLine("Add : "+a[i]); Console.WriteLine(" "); Console.WriteLine("Capacity : "+a.Capacity); Console.WriteLine("Count : "+a.Count); a.Insert(0,99); for(int i=0;i<a.Count;i++) Console.WriteLine("Insert : "+a[i]); Console.WriteLine(""); a.Remove(99); for(int i=0;i<a.Count;i++) Console.WriteLine("Remove : "+a[i]); Console.WriteLine(""); a.RemoveAt(3); for(int i=0;i<a.Count;i++) Console.WriteLine("RemoveAt : "+a[i]); Console.WriteLine(""); a.RemoveRange(1,3); for(int i=0;i<a.Count;i++)
Console.WriteLine("RemoveRange : "+a[i]); Console.WriteLine(""); a.Sort(); for(int i=0;i<a.Count;i++) Console.WriteLine("Sort : "+a[i]); Console.WriteLine(""); a.Clear(); Console.WriteLine("Clear : "+a.Count); Console.WriteLine(""); if(a.Contains("1")) { Console.WriteLine("Contains"); } else { Console.WriteLine(" Not Contains"); } Console.ReadLine(); } } Output Add Method 1 2 3 4 5 6 7 Capacity : 16 Count : 7 Insert Method 99 1 2 3 4 5 6 7 Remove Method 1 2 3 4 5
6 7 RemoveAt : 1 RemoveAt : 2 RemoveAt : 3 RemoveAt : 5 RemoveAt : 6 RemoveAt : 7 Remove Range 1 6 7 Sort Method Sort : 1 Sort : 6 Sort : 7 Clear : 0 Not Contains
Result: Thus the program has been executed successfully and verified.
Ex No: 4 A Aim:
String
To write a C# program using String class methods. Algorithm: Step 1: Start the process. Step2: Declare the string variables. Step 3:Use the string class methods like compare(),concat(),compareto(),copy(),indexof(),etc. Step 4: Include the string class method for the operations which we need. Step 5: Build the program. Step 6: perform the operation. Step7: print the result Step 8: Stop the process. Program: using System; using System.Collections; using System.Text; class Sample { public static void Main() { string s1="abcd"; String s2="abcde"; int n=String.Compare(s2,s1); Console.WriteLine("1.Compare : "+n); int m=s1.CompareTo(s2); Console.WriteLine("2.CompareTo : "+m); String s3=String.Concat(s1,s2); Console.WriteLine("3.String Concat : "+s3); s1=String.Copy(s2); Console.WriteLine("4.String Copy : "+s1); String s4="New York"; String s6=s4.EndsWith("k").ToString(); Console.WriteLine("5.Endswith : "+s6); if(s1.Equals(s2)) { Console.WriteLine("6.Equal"); } else { Console.WriteLine("6.Not Equal"); } String s7="abc def"; String s8=s7.IndexOf("d").ToString(); Console.WriteLine("7.IndexOf : "+s8); String s9="def ghi";
String s10=s9.Insert(0,"A"); Console.WriteLine("8.Insert : "+s10); String s11="abcde fgh"; String s12=s11.LastIndexOf("f").ToString(); Console.WriteLine("9.LastIndex : "+s12); String s13=s11.PadLeft(50); Console.WriteLine("10.PadLeft : "+s13); String s14=s9.PadRight(1000); Console.WriteLine("11.PadRight : "+s14); String s15=s11.Remove(1,3); Console.WriteLine("12.Remove : "+s15); String s16=s11.Replace('a','b').ToString(); Console.WriteLine("13.Replace : "+s16); String s="I LOVE INDIA"; char []sep=new char[]{' ',' '}; foreach(String sub in s.Split(sep)) Console.WriteLine("14.Split : "+sub); String s17=s.StartsWith("I").ToString(); Console.WriteLine("15.StartWith : "+s17); String s18=s.Substring(4); Console.WriteLine("16.Substring : "+s18); String s19=s.ToLower(); Console.WriteLine("17.LowerCase : "+s19); String s20=s19.ToUpper(); Console.WriteLine("18.UpperCase : "+s20); String s21=s.Trim(); Console.WriteLine("19.Trim : "+s21); String s22=s.TrimEnd('A'); Console.WriteLine("20.TrimEnd : "+s22); String s23=s.TrimStart('I'); Console.WriteLine("21.TrimBegin : "+s23); Console.ReadLine(); } }
Output 1.Compare : 1 2.CompareTo : -1 3.String Concat : abcdabcde 4.String Copy : abcde 5.Endswith : True 6.Equal
7.IndexOf : 4 8.Insert : Adef ghi 9.LastIndex : 6 10.PadLeft : 11.PadRight : def ghi 12.Remove : ae fgh 13.Replace : bbcde fgh 14.Split : I 14.Split : LOVE 14.Split : INDIA 15.StartWith : True 16.Substring : VE INDIA 17.LowerCase : i love india 18.UpperCase : I LOVE INDIA 19.Trim : I LOVE INDIA 20.TrimEnd : I LOVE INDI 21.TrimBegin : LOVE INDIA
abcde fgh
Result: Thus the program has been executed successfully and verified.
Exno:4 B Aim:
String Builders
To write a C# program using String Builders. Algorithm: Step 1: start the process. Step2: Declare the string builder variables. Step 3: Use the string class methods like Append(),appendformat(),ensurecapacity,. Step 4: Include the string builder method for the operations which we need. Step 5: Build the program. Step 6: perform the operation. Step7: print the result Step 8: Stop the process. Program: using System; using System.Text; class Sample { public static void Main() { StringBuilder s=new StringBuilder("Object"); Console.WriteLine("String : "+s); s.Append("Language"); Console.WriteLine("Append Method : "+s); s.AppendFormat("*",s); Console.WriteLine("AppendFormat : "+s); Console.WriteLine("EnsureCapacity : "+s.EnsureCapacity(3)); s.Insert(6,"Oriented"); Console.WriteLine("Insert Method : "+s); s.Remove(6,8); Console.WriteLine("Remove Method : "+s); s.Replace("Language","ProgrammingLanguage"); Console.WriteLine("Replace Method : "+s); Console.WriteLine("Capacity : "+s.Capacity); Console.WriteLine("Length : "+s.Length); Console.WriteLine("MaxCapacity : "+s.MaxCapacity); Console.ReadLine(); } }
Output String : Object Append Method : ObjectLanguage AppendFormat : ObjectLanguage* EnsureCapacity : 16 Insert Method : ObjectOrientedLanguage* Remove Method : ObjectLanguage* Replace Method : ObjectProgrammingLanguage* Capacity : 32 Length : 26 MaxCapacity : 2147483647
Result: Thus the program has been executed successfully and verified.
Exno: 5A Aim:
Structures
To write a c# program to perform structure Algorithm: Step1: Step2: Step3: Step4: Step5: Step6: start the process. declare the variable initialize the values to the variables Perform structure operation perform the result stop the process.
Program: using System; struct student { public String name; public int rno; public struct mark { public int mark1; public int mark2; public int mark3; public int total; public int avg; } } class Sample { public static void Main() { student s=new student(); s.name="Anu"; s.rno=101; student.mark m=new student.mark(); m.mark1=80; m.mark2=90; m.mark3=85; m.total=m.mark1+m.mark2+m.mark3; m.avg=m.total/3; Console.WriteLine("Name : "+s.name); Console.WriteLine("RollNo : "+s.rno); Console.WriteLine("Mark1 : "+m.mark1); Console.WriteLine("Mark2 : "+m.mark2); Console.WriteLine("Mark3 : "+m.mark3); Console.WriteLine("Total : "+m.total); Console.WriteLine("Average : "+m.avg); Console.ReadLine();
} }
Output Name : Anu RollNo : 101 Mark1 : 80 Mark2 : 90 Mark3 : 85 Total : 255 Average : 85
Result: Thus the program has been executed successfully and verified.
Exno: 5 B Aim:
Enumerations
To write a c# program to perform enumeration Algorithm: Step1: Step2: Step3: Step4: Step5: Step6: start the process. declare the variable initialize the values to the variables Perform enumeration operation perform the result stop the process.
Program: using System; class Sample { enum val { a, b, c, d } public static void Main() { val v1=val.a; val v2=val.b; val v3=val.c; val v4=val.d; Console.WriteLine("A : "+(int)v1); Console.WriteLine("B : "+(int)v2); Console.WriteLine("C : "+(int)v3); Console.WriteLine("D : "+(int)v4); Console.ReadLine(); } }
Result: Thus the program has been executed successfully and verified.
Exno:6 A Aim:
Types of constructor
To write a c# program to perform the different types of constructors Algorithm: Step1: start the process. Step2: declare the variable.. Step3: Assign the values. Step4: create an object for constructor and perform the operation. Step5:display the result Step6: stop the process
Program using System; class staticconstruct { public static int a; static staticconstruct() { Console.Write("Enter the number:"); a = int.Parse(Console.ReadLine()); Console.WriteLine("\n\tSquare of " + a + " is:" + (a * a)); } } class copy { int Rno; string name; public copy() { Console.Write("Enter the Rno:"); Rno = int.Parse(Console.ReadLine()); Console.Write("Enter the Name:"); name = Console.ReadLine(); } public void Display() { Console.WriteLine("\n\tRNO\tNAME"); Console.WriteLine("\t---\t----"); Console.WriteLine("\t" + Rno + "\t" + name); } }
class basecons { public int length; public int breadth; public basecons(int x, int y) { length = x; breadth = y; }
public int area() { return (length * breadth); } } class sam : basecons { public sam(int x, int y): base(x, y) { Console.WriteLine(""); } } class PgmTest { public static void Main(string[] args) { int n; Console.WriteLine("\n\tTypes of Constructor"); Console.WriteLine("\t*******************"); Console.WriteLine("\n1:Static Constructor"); Console.WriteLine("2:Copy Constructor"); Console.WriteLine("3:Base class constructor"); do { Console.Write("\nEnter your choice:"); n = int.Parse(Console.ReadLine()); switch (n) { case 1: Console.WriteLine("\tStatic Constructor"); Console.WriteLine("\t------ -----------"); staticconstruct s = new staticconstruct(); break; case 2: Console.WriteLine("\tCopy Constructor");
Console.WriteLine("\t---- -----------"); copy c1 = new copy(); c1.Display(); copy c2 = c1; c2.Display(); break;
case 3: Console.WriteLine("\tBase class constructor"); Console.WriteLine("\t---- -----------"); basecons b1 = new basecons(4, 6); int a = b1.area (); Console.WriteLine(" Volume:"+a); break; default: Console.WriteLine("Invalid choice "); break; } } while (n < 4); Console.ReadLine(); } }
Output: Types of Constructor & Static Members 1:Static Constructor 2:Copy Constructor 3:Base class constructor Enter your choice:1 Static Constructor ------ ----------Enter the number:12 Square of 12 is:144
Enter your choice:2 Copy Constructor -------------Enter the Rno:112 Enter the Name:Shiva RNO NAME -----112 Shiva RNO NAME -----112 Shiva Enter your choice:3 Base class constructor ---- ----------Volume:24 Enter your choice:5 Invalid choice
Result: Thus the program has been executed successfully and verified.
Exno:6 B Aim:
STATIC MEMBERS
To write a c# program to perform static member function. Algorithm: Step1: Step2: Step3: Step4: Step5: Step6: start the process. declare the variable as static. calculate the variable as static. calculate the value for the modulo. create an object and call the function. stop the process
Program: using System; class student { static string n, a; static int x, y; public static string Concatenation(string str1, string str2) { n=str1 ; a=str2 ; Console.WriteLine("\nString1:"+n); Console.WriteLine("String2:"+a); return n+a; } public static int Concat(int m1, int m2) { x=m1; y=m2; Console.WriteLine("\nValue1:" + x); Console.WriteLine("Value2:" + y); return x+y; } } class StuDetails { public static void Main() { string s = student.Concatenation ("HELLO,", "FRIENDS"); Console.WriteLine("Concatenation of two strings:" + s); int i = student.Concat(78, 92); Console.WriteLine("Addition of two numbers:" + i);
Console.ReadLine(); } } Output: String1: HELLO, String2: FRIENDS Concatenation of two strings: HELLO, FRIENDS Value1:78 Value2:92 Addition of two numbers: 170
Result: Thus the program has been executed successfully and verified.
Exno: 7 A Aim:
Nested class
To write a c# program to perform the nested class Algorithm: Step1: Step2: Step3: Step4: Step5: Step6: start the process. create a another class declare the variable create an object for class perform the result stop the process.
Program: using System; using System.Collections.Generic; using System.Text; namespace nested_class { class A { class B { public string name = Console.ReadLine(); public int x = int.Parse(Console.ReadLine()); public int y = int.Parse(Console.ReadLine()); } static void Main(string[] args) { Console.WriteLine("\n\tNESTED CLASS"); Console.WriteLine("\t------ -----\n"); Console.WriteLine("Enter the name,mark1,mark2"); A.B a=new A.B(); Console.WriteLine("Name: "+a.name); Console.WriteLine("MARK1: "+a.x); Console.WriteLine("MARK2: "+a.y); int tot = a.x + a.y; Console.WriteLine("The total is: " + tot); int avg = tot / 2; Console.WriteLine("The average is: " +avg); Console.ReadLine(); } } }
Output:
NESTED CLASS ------------ --------Enter the name, mark1, mark2 arthi 89 90 Name: arthi MARK1: 89 MARK2: 90 The total is: 179 The average is: 89
Result: Thus the program has been executed successfully and verified.
Ex no: 7 B
This reference
Aim: To write a c# program to perform this reference Algorithm: Step1:start the process. Step2:create the function Step3: declare the this reference Step4:perform the operation. Step5:print the result Step6:stop the process. Program: using System; using System.Collections.Generic; using System.Text; namespace this_ref { class this1 { int a; public void dis(int a) { this.a = a; Console.WriteLine("\nValue of a is: " + a); Console.WriteLine("\nSquare: " + (a * a)); Console.WriteLine("\nCube: " + (a * a * a)); } static void Main(string[] args) { this1 b = new this1(); Console.WriteLine("\n\tTHIS REFERENCE"); Console.WriteLine("\t---- ---------"); Console.WriteLine("\nEnter the value: "); int c=int.Parse(Console.ReadLine()); b.dis(c); Console.ReadLine(); } } }
Output:
THIS REFERENCE ------- ------------------Enter the value: 78 Value of a is: 78 Square: 6084 Cube: 474552
Result: Thus the program has been executed successfully and verified.
Exno: 8 Aim:
Property
To write a c# program to perform the the property using class Algorithm: Step1: start the process. Step2: Declare the property in that to create a class string a. Step3: To get the value for B and set the value Step4: To create a class for property in that using class name and object. Step5:To print the string character and print the result Step6:stop the process. Program: using System; using System.Collections.Generic; using System.Text; namespace property1 { class numbersum { private int n, r,d; public int sum { get { while (n > 0) { d = n % 10; r = r * 10 + d; n = n / 10; } return r; } set { n = value; } } } class Program { static void Main(string[] args) { Console.WriteLine("\n\tPROPERTY"); Console.WriteLine("\t--------\n"); Console.WriteLine("\nEnter the input value:"); numbersum n1 = new numbersum(); int x = int.Parse(Console.ReadLine()); n1.sum = x;
Output:
PROPERTY ---------------Enter the input value: 5789 Reverse the digit: 9875
Result: Thus the program has been executed successfully and verified.
Exno: 9 Aim:
Indexers
To write a c# program to perform the Indexers using class Algorithm: Step1: Step2: Step3: Step4: Step5: Step6: start the process. Declare the variables. To use the word this and to declare the get and set the values. To create a class for indexers in that using class name and object. To print the result stop the process.
Program: using System; using System.Collections.Generic; using System.Collections; using System.Text; namespace indexer { class Program { private string[] techcom = new string[14]; public string this[int val] { get { if (val < 0 || val >= 11) return "Empty"; else return techcom[val]; } set { if (!(val < 0 || val >= 11)) techcom[val] = value; } } class sample { static void Main(string[] args) { Console.WriteLine("\tPROGRAM FOR INDEXERS"); Console.WriteLine("\t "); Program p = new Program(); p[0] = "Infosys"; p[5] = "TCS"; p[8] = "HCL"; p[10] = "L&T";
p[11] = "CTS"; p[14] = "Hexaware"; for (int i = 0; i <= 14; i++) { Console.WriteLine("Company name{0}:{1}", i, p[i]); } Console.ReadLine(); } } } } Output: PROGRAM FOR INDEXERS Company Company Company Company Company Company Company Company Company Company Company Company Company Company Company name0:Infosys name1: name2: name3: name4: name5:TCS name6: name7: name8:HCL name9: name10:L&T name11:Empty name12:Empty name13:Empty name14:Empty
Result: Thus the program has been executed successfully and verified.
Exno: 10 Aim:
To write a c# program to perform overriding & hiding operation in visual C#. Algorithm: Step1: Step2: Step3: Step4: Step5: Step6: Step7: Step8: start the process. declare the variables. To create the class for base and derived. Use the override & new keyword to hide & override the values . By using the keywords virtual in base class and override & new as derived. Save and Run the program. Display the Result. stop the process.
Program: using System; public class Base { public virtual void disp() { Console.WriteLine("Hello"); } public void show() { Console.WriteLine("Welcome"); } } public class Derived : Base { public override void disp() { Console.WriteLine("Sample program for overriding method"); } public new void show() { Console.WriteLine("Sample program for overhiding method"); } } class sample { public static void Main() { Derived d = new Derived();
Console.WriteLine("PROGRAM FOR OVERRIDING & HIDING METHODS"); Console.WriteLine("------- --- ---------- - ------ -------"); Console.WriteLine(); d.disp(); Console.WriteLine(); d.show(); Console.ReadLine(); } }
Output
PROGRAM FOR OVERRIDING & HIDING METHODS --------------- ------ ------------------ -- ----------- --------------Sample program for overriding method Sample program for overhiding method
Result: Thus the program has been executed successfully and verified.
Exno:11 A Aim:
Abstract Class
To write a c# program to perform abstract class in visual C#. Algorithm: Step1: Step2: Step3: Step4: Step5: Step6: Step7: start the process. declare the variables. To create the class for abstract. To display the override method for display the output. Save and Run the program. Display the Result. stop the process.
Program: using System; using System.Collections.Generic; using System.Text; abstract class a1 { public int x; public a1(int x) { this.x=x; } } class b:a1 { int y=8; public b(int x,int y):base(x) { this.y=y; } public void dis() { int z; z=x*y; Console.WriteLine("Multiplication: "+z); } } namespace abstract1 { class Program { static void Main(string[] args) { Console.WriteLine("Abstract Method\n");
Result: Thus the program has been executed successfully and verified.
Exno:11 B Aim:
Sealed Class
To write a c# program to perform sealed class in visual C#. Algorithm: Step1: Step2: Step3: Step4: Step5: Step6: Step7: start the process. declare the variables. To create the class for Sealed. Use the keywords as sealed perform the operation. Save and Run the program. Display the Result. stop the process.
Program: using System; using System.Collections.Generic; using System.Text; sealed class a { public int x; public a(int x) { this.x = x; } public void dis() { Console.WriteLine("SuperX=" + x); Console.WriteLine("Welcome"); } } namespace Sealed { class Program { static void Main(string[] args) { Console.WriteLine("Sealed Method\n\n"); a b1=new a(100); b1.dis(); Console.ReadLine(); } } }
Result: Thus the program has been executed successfully and verified.
ExNo: 12 Aim:
Inheritance
To write a c# program to perform Single, Hierarchical, Multilevel inheritance in visual C#. Algorithm: Step1: Step2: Step3: Step4: Step5: Step6: Step7: start the process. declare the variables. To create the class for base and derived1,derived2. To declare the variables and get the values from base class in derived class. Save and Run the program. Display the Result. stop the process.
Program: using System; public class Base { public int rno = 101; public string name = "Midhul"; } public class Derived : Base { public int m1, m2, m3; public void cal(int a, int b, int c) { m1 = a; m2 = b; m3 = c; } } public class Derived1 : Derived { public void show() { Console.WriteLine("RollNo:" + rno); Console.WriteLine("Name:" + name); Console.WriteLine("Mark1:" + m1); Console.WriteLine("Mark2:" + m2); Console.WriteLine("Mark3:" + m3); Console.WriteLine("Total:" + (m1 + m2 + m3)); } }
public class Derived2 : Base { public void view() { Console.WriteLine(); Console.WriteLine("RollNo:" + rno); Console.WriteLine("Name:" + name); } }
public class sample { public static void Main() { Derived1 d = new Derived1(); d.cal(80, 90, 85); d.show(); Derived2 d1 = new Derived2(); d1.view(); Console.ReadLine(); } } Output: RollNo:101 Name:Midhul Mark1:80 Mark2:90 Mark3:85 Total:255 RollNo:101 Name:Midhul
Result: Thus the program has been executed successfully and verified.
Ex.No:13 Aim
To write a c# program for polymorphism and typecasting. Algorithm Step1: Step2: Step3: Step4: Step5: Step6: Start the process. Create the class called run. Calculate the area of the circle. Create a class called square and inherit the base class in it. Calculate the area of square. In the main () function create objects for the two classes and access the Function area. Step7: Stop the process. Program using System; class runpoly { public virtual void area() { Console.WriteLine("\n\tArea"); Console.WriteLine("\t----"); } } class circle : runpoly { public override void area() { Console.WriteLine("\n\tCircle area"); Console.WriteLine("\t-----------"); Console.Write("Enter the value of X:"); double x = double.Parse(Console.ReadLine()); double a1 = Math.PI * x * x; Console.WriteLine("Result:" + a1); } } class square : runpoly { public override void area() { Console.WriteLine("\n\tSquare area"); Console.WriteLine("\t-----------"); Console.Write("Enter the value of Y:"); int y = int.Parse(Console.ReadLine()); int a2 = y * y; Console.WriteLine("Result:" + a2);
} } class Test { public static void Main() { runpoly rp = new runpoly(); rp = new circle(); rp.area(); rp = new square(); rp.area(); Console.ReadLine(); } } Output Circle area ----------Enter the value of X:12 Result:452.38934211693 Square area ----------Enter the value of Y:14 Result:196
Result Thus, the program has been successfully executed and verified.
Ex.No:14 Aim
Interface
To write a C# program for implementing the concept of interface. Algorithm Step1: Step2: Step3: Step4: Step5: Step6: Step7: Program using System; using System.Collections.Generic; using System.Text; namespace Interface { public interface Temp { void cal(); } public class Calculation : Temp { float cent,fahr; public void cal() { Console.WriteLine("\n\n\t\t Fahrenheit to Celsius "); Console.WriteLine("\t\t ------------------------ "); Console.WriteLine("\n\t\t Enter the Fahrenheit Value : "); fahr = float.Parse(Console.ReadLine()); cent=(fahr-32.0F)/1.8F; Console.WriteLine("\n\t\t The Celsius Value is : " +cent); } } class Program { public static void Main(string[] args) { Calculation c=new Calculation(); c.cal(); Console.WriteLine(); Console.ReadKey(); Start the process. Declare the cal () within the interface Temp. Create a class Calculation and implement the interface. Declare the variables and define the cal () function. Create a class Program and declare the object for Calculation class. Invoke the cal () function using Calculation class object. Stop the process.
} } }
Output Fahrenheit to Celsius --------------------------Enter the Fahrenheit Value : 102 The Celsius Value is : 38.88889
Result Thus, the program has been successfully executed and verified.
Ex.No:15 Aim
Operator Overloading
To write a c# program for operator overloading. Algorithm Step1: Step2: Step3: Step4: Step5: Step6: Program Using System; Using System.Collections.Generic; Using System.Text; namespace operator1 { class Program { public int a, b; public Program() { } public Program(int a1, int b1) { a = a1; b = b1; } public static Program operator +(Program p1,Program p2) { Program p3 = new Program(); p3.a = p1.a+p2.a; p3.b = p1.b+p1.b; return p3; } public void print() { Console.Write(a); Console.WriteLine("+i" + b); Console.WriteLine(); } } Start the process. Create class called program. Overload the operator using the addition operation. Access the overload function in main() method. Run the program and print the result Stop the process.
class Test { static void Main(string[] args) { Program r, s, t; r = new Program(10,20); s =new Program(16,2); t = r+ s; Console.Write("r="); r.print(); Console.Write("s="); s.print(); Console.Write("t="); t.print(); Console.ReadLine(); } } }
Result Thus, the program has been successfully executed and verified.
Ex.No:16a Aim
DELEGATES
To write a C# program using Delegates. Algorithm Step1: Start the process. Step2: Declare a delegate called Sample. Step3: Perform the operations sum, product, division, difference. Step4: Create an object for delegate. Step5: Using that delegate object access the functions. Step6: Run the program and print the result. Step7: Stop the process. Program using System; delegate void Sample(); class Example { public static int x; public static void sum() { x = 100 + 200; Console.WriteLine("Sum value: " + x); } public void difference() { int s; s = 100 - 67; Console.WriteLine("Difference value : " + s); } public void product() { int a = 15 * 34; Console.WriteLine("Product value : " + a); } public void divide() { int r = 50 / 5; Console.WriteLine("Division value : " + r); } } class Samplepgm { public static void Main() { Sample s = new Sample(Example.sum); Example g = new Example(); Sample n = new Sample(g.difference);
Sample k = new Sample(g.product); Sample l = new Sample(g.divide); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Unicast Delegate"); Console.WriteLine("----------------"); s(); n(); k(); l(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Multicast Delegate"); Console.WriteLine("-----------------"); Sample j; j = k + l; j(); Console.ReadLine(); } } Output Unicast Delegate --------------------Sum value: 300 Difference value : 33 Product value : 510 Division value : 10 Multicast Delegate ----------------------Product value : 510 Division value : 10
Result Thus, the program has been successfully executed and verified.
Ex.No:16b Aim
EVENTS
To write a program in C# for events. Algorithm Step1: Start the process. Step2: Declare a delegate event. Step3: Get the two variables and perform addition operation. Step4: Mention the event has occurred. Step5: Run the program. Step6: Print the result. Step7: Stop the process. Program using System; public delegate void delevent(String s); public class Sample { public event delevent status; public void display() { if (status == null) { status("Event Triggered"); } else { Console.WriteLine(); Console.WriteLine("Enter the values for x and y:"); int x = int.Parse(Console.ReadLine()); int y = int.Parse(Console.ReadLine()); Console.WriteLine("Result : " + (x+y)); Console.WriteLine(); status("Event Occurred"); } } public void process() { onstatus("welcome to our class"); } public void onstatus(String message) { if (status != null) { status(message); } }
class Example { public static void Main() { Sample s= new Sample(); Example e= new Example(); s.status += new delevent(e.eventcatch); s.display(); Console.WriteLine(); s.process(); Console.ReadLine(); } public void eventcatch(String str) { Console.WriteLine(str); } } }
Output Enter the values for x and y 23 43 Result : 66 Event Occurred welcome to our class
Result Thus, the program has been successfully executed and verified.
Ex.No:17 Aim
To write a program for errors and exception in C#. Algorithm Step1: Start the process. Step2: Declare an array variable a. Step3: Create the error and using try, catch block handle the exception. Step4: Run the program and print the result Step5: Stop the process. Program using System; using System.Collections.Generic; using System.Text; class error { public static void Main(string[] args) { int[] a ={ 20, 25, 30 }; int y = a[2] / a[0]; Console.WriteLine("y=" + y); try { int y1 = a[1] / a[0]; try { int x = a[2] / a[3]; }
catch (IndexOutOfRangeException e) { Console.WriteLine("exception" + e); } } catch (ArithmeticException e) { Console.WriteLine("EXCEPTION:" + e); } finally { int x = a[0] * a[1] * a[2];
Output y=1 exceptionSystem.IndexOutOfRangeException: Index was outside the bounds of the array. at error.Main(String[] args) n1=20 n2=25 n3=30 RESULT:15000
Result Thus, the program has been successfully executed and verified.
Ex.No:18 Aim
BANK OPERATION
To create the C# program for the Bank Operation Algorithm Step1: Start the process. Step2: Declare the variables. Step3: Create a form by using the labels, textboxes and buttons. Step4: Perform the operation. Step5: Print the result. Step6: Stop the process. Program using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.OleDb; namespace BankOperation { public partial class Form1 : Form { OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + ("C:/Documents and Settings/suvendran/Desktop/BankDetails.mdb")); public Form1() { InitializeComponent(); } private void btnSelect_Click(object sender, EventArgs e) { try { con.Open(); OleDbDataReader rdr; OleDbCommand cmd = new OleDbCommand("select Name,CurrentBalance from BankDetails where AccountNo='" + txtAccNo.Text + "'", con); rdr = cmd.ExecuteReader(); rdr.Read(); txtName.Text = rdr.GetString(0).ToString(); txtCurrentBalance.Text = rdr.GetString(1).ToString();
rdr.Close(); con.Close(); } catch (OleDbException ex) { throw ex; } } private void btnDeposit_Click(object sender, EventArgs e) { try { con.Open(); int a = int.Parse(txtCurrentBalance.Text); int b = int.Parse(txtAmount.Text); int c = a + b; OleDbDataAdapter da = new OleDbDataAdapter("update BankDetails set CurrentBalance='" + c.ToString() + "' where AccountNo='" + txtAccNo.Text + "'", con); DataSet ds = new DataSet(); da.Fill(ds, "BankDetails"); MessageBox.Show("Amount Deposited Successfully"); } catch (OleDbException ex) { throw ex; } } private void btnWithDraw_Click(object sender, EventArgs e) { try { con.Open(); int a = int.Parse(txtCurrentBalance.Text); int b = int.Parse(txtAmount.Text); if ((b > a )) { MessageBox.Show("Amount is Too Large to WithDraw"); } else { int c = a - b; OleDbDataAdapter da = new OleDbDataAdapter("update BankDetails set CurrentBalance='" + c.ToString() + "' where AccountNo='" + txtAccNo.Text + "'", con);
DataSet ds = new DataSet(); da.Fill(ds, "BankDetails"); MessageBox.Show("Amount WithDrawn Successfully"); } } catch (OleDbException ex) { throw ex; } } private void btnDelete_Click(object sender, EventArgs e) { try { con.Open(); OleDbDataAdapter da = new OleDbDataAdapter("delete from BankDetails where AccountNo='" + txtAccNo.Text + "'", con); DataSet ds = new DataSet(); da.Fill(ds, "BankDetails"); MessageBox.Show("Records Deleted Successfully"); } catch (OleDbException ex) { throw ex; } } } }
Output
Deposit:
With Drawn
Record Delete
Database Record
Result Thus, the program has been successfully executed and verified.
Ex.No:19 Aim
CALCULATOR WIDGET
To write a program for the calculator widget using windows application. Algorithm Step1: Start the process. Step2: Design the Calculator by placing required buttons. Step3: Perform the arithmetic operations such as add, sub, div, mul. Step4: Run the source code and display the calculator. Step5: Stop the process. Program using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace calculator { public partial class Form1 : Form { double sum,prevno,curno,bspace; int ch; public Form1() { InitializeComponent(); } private void c0_Click(object sender, EventArgs e) { textBox1.Text += c0.Text; } private void c1_Click(object sender, EventArgs e) { textBox1.Text += c1.Text; } private void ca_Click(object sender, EventArgs e) { prevno = long.Parse(textBox1.Text); textBox1.Text = ""; ch = 1; } private void csu_Click(object sender, EventArgs e) {
prevno = long.Parse(textBox1.Text); textBox1.Text = ""; ch = 2; } private void cdi_Click(object sender, EventArgs e) { prevno = long.Parse(textBox1.Text); textBox1.Text = ""; ch = 4; } private void cm_Click(object sender, EventArgs e) { prevno = long.Parse(textBox1.Text); textBox1.Text = ""; ch = 3; } private void ce_Click(object sender, EventArgs e) { curno = long.Parse(textBox1.Text); switch(ch) { case 1: sum = (prevno + curno); break; case 2: sum = (prevno - curno); break; case 3: sum = (prevno * curno); break; case 4: sum = (prevno / curno); break; } textBox1.Text = Convert.ToString(sum); } private void BS_Click(object sender, EventArgs e) { bspace = long.Parse(textBox1.Text); textBox1.Text = Convert.ToString((bspace / 10)); } private void C_Click(object sender, EventArgs e) { textBox1.Text = ""; prevno = curno = 0; }
private void cmo_Click(object sender, EventArgs e) { long sign = long.Parse(textBox1.Text); textBox1.Text = Convert.ToString(-sign); } private void c2_Click(object sender, EventArgs e) { textBox1.Text += c2.Text; } private void c3_Click(object sender, EventArgs e) { textBox1.Text += c3.Text; } private void c4_Click(object sender, EventArgs e) { textBox1.Text += c4.Text; } private void c5_Click(object sender, EventArgs e) { textBox1.Text += c5.Text; } private void c6_Click(object sender, EventArgs e) { textBox1.Text += c6.Text; } private void c7_Click(object sender, EventArgs e) { textBox1.Text += c7.Text; } private void c8_Click(object sender, EventArgs e) { textBox1.Text += c8.Text; }
Output
Result Thus, the program has been successfully executed and verified.
Ex.No:20 Aim
To write a program for Calculator using web services. Algorithm Step1: Start the process. Step2: Using web services create a calculator. Step3: Create the arithmetic operations. Step4: Perform the operations. Step5: Stop the process. Program App_code/Service.cs using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class Service : System.Web.Services.WebService { public Service () { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod] public double Add(double x, double y) { return x + y; } [WebMethod] public double Sub(double x, double y) { return x - y; }
[WebMethod] public double Div(double x, double y) { return x / y; } [WebMethod] public double Pow(double x, double y) { double retVal = x; for (int i = 0; i < y - 1; i++) { retVal *= x; } return retVal; } } WSDL <wsdl:definitions targetNamespace="http://tempuri.org/"> <wsdl:types> <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/"> <s:element name="Add"> <s:complexType> <s:sequence> <s:element minOccurs="1" maxOccurs="1" name="x" type="s:double"/> <s:element minOccurs="1" maxOccurs="1" name="y" type="s:double"/> </s:sequence> </s:complexType> </s:element> <s:element name="AddResponse"> <s:complexType> <s:sequence> <s:element minOccurs="1" maxOccurs="1" name="AddResult" type="s:double"/> </s:sequence> </s:complexType> </s:element> <s:element name="Sub">
<s:complexType> <s:sequence> <s:element minOccurs="1" maxOccurs="1" name="x" type="s:double"/> <s:element minOccurs="1" maxOccurs="1" name="y" type="s:double"/> </s:sequence> </s:complexType> </s:element> <s:element name="SubResponse"> <s:complexType> <s:sequence> <s:element minOccurs="1" maxOccurs="1" name="SubResult" type="s:double"/> </s:sequence> </s:complexType> </s:element> <s:element name="Mul"> <s:complexType> <s:sequence> <s:element minOccurs="1" maxOccurs="1" name="x" type="s:double"/> <s:element minOccurs="1" maxOccurs="1" name="y" type="s:double"/> </s:sequence> </s:complexType> </s:element> <s:element name="MulResponse"> <s:complexType> <s:sequence> <s:element minOccurs="1" maxOccurs="1" name="MulResult" type="s:double"/> </s:sequence> </s:complexType> </s:element> <s:element name="Div"> <s:complexType> <s:sequence> <s:element minOccurs="1" maxOccurs="1" name="x" type="s:double"/> <s:element minOccurs="1" maxOccurs="1" name="y" type="s:double"/> </s:sequence> </s:complexType> </s:element>
<s:element name="DivResponse"> <s:complexType> <s:sequence> <s:element minOccurs="1" maxOccurs="1" name="DivResult" type="s:double"/> </s:sequence> </s:complexType> </s:element> <s:element name="Pow"> <s:complexType> <s:sequence> <s:element minOccurs="1" maxOccurs="1" name="x" type="s:double"/> <s:element minOccurs="1" maxOccurs="1" name="y" type="s:double"/> </s:sequence> </s:complexType> </s:element> <s:element name="PowResponse"> <s:complexType> <s:sequence> <s:element minOccurs="1" maxOccurs="1" name="PowResult" type="s:double"/> </s:sequence> </s:complexType> </s:element> </s:schema> </wsdl:types> <wsdl:message name="AddSoapIn"> <wsdl:part name="parameters" element="tns:Add"/> </wsdl:message> <wsdl:message name="AddSoapOut"> <wsdl:part name="parameters" element="tns:AddResponse"/> </wsdl:message> <wsdl:message name="SubSoapIn"> <wsdl:part name="parameters" element="tns:Sub"/> </wsdl:message> <wsdl:message name="SubSoapOut"> <wsdl:part name="parameters" element="tns:SubResponse"/> </wsdl:message> <wsdl:message name="MulSoapIn"> <wsdl:part name="parameters" element="tns:Mul"/>
</wsdl:message> <wsdl:message name="MulSoapOut"> <wsdl:part name="parameters" element="tns:MulResponse"/> </wsdl:message> <wsdl:message name="DivSoapIn"> <wsdl:part name="parameters" element="tns:Div"/> </wsdl:message> <wsdl:message name="DivSoapOut"> <wsdl:part name="parameters" element="tns:DivResponse"/> </wsdl:message> <wsdl:message name="PowSoapIn"> <wsdl:part name="parameters" element="tns:Pow"/> </wsdl:message> <wsdl:message name="PowSoapOut"> <wsdl:part name="parameters" element="tns:PowResponse"/> </wsdl:message> <wsdl:portType name="ServiceSoap"> <wsdl:operation name="Add"> <wsdl:input message="tns:AddSoapIn"/> <wsdl:output message="tns:AddSoapOut"/> </wsdl:operation> <wsdl:operation name="Sub"> <wsdl:input message="tns:SubSoapIn"/> <wsdl:output message="tns:SubSoapOut"/> </wsdl:operation> <wsdl:operation name="Mul"> <wsdl:input message="tns:MulSoapIn"/> <wsdl:output message="tns:MulSoapOut"/> </wsdl:operation> <wsdl:operation name="Div"> <wsdl:input message="tns:DivSoapIn"/> <wsdl:output message="tns:DivSoapOut"/> </wsdl:operation> <wsdl:operation name="Pow"> <wsdl:input message="tns:PowSoapIn"/> <wsdl:output message="tns:PowSoapOut"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="ServiceSoap" type="tns:ServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="Add"> <soap:operation soapAction="http://tempuri.org/Add" style="document"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="Sub"> <soap:operation soapAction="http://tempuri.org/Sub" style="document"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="Mul"> <soap:operation soapAction="http://tempuri.org/Mul" style="document"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="Div"> <soap:operation soapAction="http://tempuri.org/Div" style="document"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="Pow">
<soap:operation soapAction="http://tempuri.org/Pow" style="document"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:binding name="ServiceSoap12" type="tns:ServiceSoap"> <soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="Add"> <soap12:operation soapAction="http://tempuri.org/Add" style="document"/> <wsdl:input> <soap12:body use="literal"/> </wsdl:input> <wsdl:output> <soap12:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="Sub"> <soap12:operation soapAction="http://tempuri.org/Sub" style="document"/> <wsdl:input> <soap12:body use="literal"/> </wsdl:input> <wsdl:output> <soap12:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="Mul"> <soap12:operation soapAction="http://tempuri.org/Mul" style="document"/> <wsdl:input> <soap12:body use="literal"/> </wsdl:input> <wsdl:output> <soap12:body use="literal"/> </wsdl:output> </wsdl:operation>
<wsdl:operation name="Div"> <soap12:operation soapAction="http://tempuri.org/Div" style="document"/> <wsdl:input> <soap12:body use="literal"/> </wsdl:input> <wsdl:output> <soap12:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="Pow"> <soap12:operation soapAction="http://tempuri.org/Pow" style="document"/> <wsdl:input> <soap12:body use="literal"/> </wsdl:input> <wsdl:output> <soap12:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="Service"> <wsdl:port name="ServiceSoap" binding="tns:ServiceSoap"> <soap:address location="http://localhost:1387/Ravi%20WS/Service.asmx"/> </wsdl:port> <wsdl:port name="ServiceSoap12" binding="tns:ServiceSoap12"> <soap12:address location="http://localhost:1387/Ravi%20WS/Service.asmx"/> </wsdl:port> </wsdl:service> </wsdl:definitions>
Output
Solution Explorer:
Result Thus, the program has been successfully executed and verified.
Ex.No:21 Aim
To write a program for creating a new email account using web application. Algorithm Step1: Start the process. Step2: Create a new style for the labels, buttons, link buttons. Step3: Create a web page for the login, new user login and welcome page. Step4: Perform the operations. Step5: Print the result. Step6: Stop the process. Program Login Page.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="LoginPage.aspx.cs" Inherits="LoginPage" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Login Page</title> <link href="CSS/RMailCSS.css" rel="stylesheet" type="text/css" /> </head> <body bottommargin="0" leftmargin="0" topmargin="0" rightmargin="0"> <form id="form1" runat="server"> <div> <table style="z-index: 100; left: 0px; width: 100%; position: relative; top: 0px; height: 650px; background-color: #ff9900"> <tr> <td colspan="4"> </td> </tr> <tr> <td colspan="4"> <asp:Image ID="Image1" runat="server" ImageUrl="~/Images/dj1.jpg" Style="z-index: 100; left: 0px; position: relative; top: 0px" /> </td> </tr> <tr> <td colspan="4"> </td> </tr> <tr>
<td style="width: 100px"> </td> <td colspan="3" rowspan="15"> <table border="0" cellpadding="0" cellspacing="0" style="z-index: 100; left: 0px; width: 890px; position: relative; top: 0px; height: 234px; backgroundcolor: #ffffff;"> <tr> <td style="text-align: center;" colspan="4"> <asp:Label ID="Label2" runat="server" Style="z-index: 100; left: 0px; position: relative; top: 0px" Text="RMail Account" CssClass="lblAccount"></asp:Label></td> </tr> <tr> <td style="width: 28px"> </td> <td style="width: 100px"> <asp:Label ID="lblUserId" runat="server" Style="z-index: 100; left: 0px; position: relative; top: 0px" Text="UserId" CssClass="lblAccountInformation"></asp:Label></td> <td style="width: 71px"> <asp:TextBox ID="txtUserId" runat="server" Style="z-index: 100; left: 0px; position: relative; top: 0px"></asp:TextBox></td> <td style="width: 100px"> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtUserId" ErrorMessage="UserId Should Not be Empty" Style="z-index: 100; left: 0px; position: relative; top: 0px" Width="195px"></asp:RequiredFieldValidator> </td> </tr> <tr> <td style="width: 28px"> </td> <td style="width: 100px"> <asp:Label ID="lblPassword" runat="server" Style="z-index: 100; left: 0px; position: relative; top: 0px" Text="Password" CssClass="lblAccountInformation"></asp:Label></td> <td style="width: 71px"> <asp:TextBox ID="txtPassword" runat="server" Style="z-index: 100; left: 0px; position: relative; top: 0px" TextMode="Password"></asp:TextBox></td> <td style="width: 100px"> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtPassword" ErrorMessage="Password should Not be empty" Style="z-index: 100; left: 0px; position: relative; top: 0px"></asp:RequiredFieldValidator></td>
</tr> <tr> <td style="width: 28px"> </td> <td style="width: 100px"> </td> <td style="width: 71px"> <asp:Button ID="btnSignin" runat="server" CssClass="btnStyle" Style="z-index: 100 left: 0px; position: relative; top: 0px" Text="SignIn" OnClick="btnSignin_Click" /></td> <td style="width: 100px"> </td> </tr> <tr> <td style="width: 28px"> </td> <td style="width: 100px"> </td> <td style="width: 71px"> <asp:LinkButton ID="lbtnNewUser" runat="server" CssClass="linkbtnstyle" Style="z-index: 100; left: 0px; position: relative; top: 0px" OnClick="lbtnNewUser_Click" Width="205px">New User Sign Up</asp:LinkButton></td> <td style="width: 100px"> </td> </tr> </table> </td> </tr> </table> </div> </form> </body></html>
Login Page.aspx.cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.OleDb;
public partial class LoginPage : System.Web.UI.Page { OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + ("C:/Documents and Settings/suvendran/Desktop/BankDetails.mdb")); protected void Page_Load(object sender, EventArgs e) { } protected void lbtnNewUser_Click(object sender, EventArgs e) { Response.Redirect("NewUserSignUpPage.aspx"); } protected void btnSignin_Click(object sender, EventArgs e) { try { Response.Redirect("WelcomePage.aspx"); } catch (OleDbException ex) { throw ex; } } } NewUserSignUpPage.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="NewUserSignUpPage.aspx.cs" Inherits="NewUserSignUpPage" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>New User SignUp</title> <link href="CSS/RMailCSS.css" rel="stylesheet" type="text/css" /> </head> <body> <form id="form1" runat="server"> <div> <table border="0" cellpadding="0" cellspacing="0" style="z-index: 100; left: 0px; width: 100%; position: absolute; top: 0px; height: 700px"> <tr> <td colspan="5" style="text-align: center; background-color: #cccc99;"> <asp:Label ID="Label1" runat="server" Style="z-index: 100; left: 0px; position: relative; top: 0px" Text="New User Sign Up" CssClass="lblAccount"></asp:Label></td>
</tr> <tr> <td rowspan="1" style="width: 93px; background-color: #ff9966"> </td> <td colspan="3"> <span style="color: #ff0033">*</span> Feilds marked with <span style="color: #ff0000"> *</span> are Mandatory</td> <td rowspan="1" style="width: 100px; background-color: #ff9966"> </td> </tr> <tr> <td style="width: 93px; background-color: #ff9966;" rowspan="8"> </td> <td style="width: 133px"> <span style="color: #ff0000">*</span> <asp:Label ID="Label2" runat="server" CssClass="lblAccountInformation" Style="z-index: 100; left: 0px; position: relative; top: 0px" Text="Enter FirstName"></asp:Label></td> <td style="width: 88px"> <asp:TextBox ID="txtFirstNAme" runat="server" Style="z-index: 100; left: 0px; position: relative; top: 0px"></asp:TextBox></td> <td style="width: 279px"> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtFirstNAme" ErrorMessage="First Name Should not be Empty" Style="z-index: 100; left: 0px; position: relative; top: 0px"></asp:RequiredFieldValidator></td> <td style="width: 100px; background-color: #ff9966;" rowspan="8"> </td> </tr> <tr> <td style="width: 133px"> <asp:Label ID="Label3" runat="server" CssClass="lblAccountInformation" Style="z-index: 100; left: 0px; position: relative; top: 0px" Text="Enter Last Name"></asp:Label></td> <td style="width: 88px"> <asp:TextBox ID="TextBox2" runat="server" Style="z-index: 100; left: 0px; position: relative; top: 0px"></asp:TextBox></td> <td style="width: 279px"> </td> </tr> <tr> <td style="width: 133px; height: 20px;"> <span style="color: #ff0000">*</span> <asp:Label ID="Label4" runat="server" CssClass="lblAccountInformation" Style="z-index: 100; left: 0px; position: relative; top: 0px" Text="Gender"></asp:Label></td>
<td style="width: 88px; height: 20px;"> <asp:RadioButtonList ID="rblGender" runat="server" Style="z-index: 100; left: 0px; position: relative; top: -24px"> <asp:ListItem Selected="True">Male</asp:ListItem> <asp:ListItem>Female</asp:ListItem> </asp:RadioButtonList></td> <td style="width: 279px; height: 20px"> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="rblGender" ErrorMessage="Select Any Gender. Gender Feild Should Not be Empty" Style="z-index: 100; left: 0px; position: relative; top: 0px"></asp:RequiredFieldValidator></td> </tr> <tr> <td style="width: 133px"> <span style="color: #ff0000">*</span><asp:Label ID="Label5" runat="server" CssClass="lblAccountInformation" Style="z-index: 100; left: 0px; position: relative; top: 0px" Text="Enter User Id"></asp:Label></td> <td style="width: 88px"> <asp:TextBox ID="txtuserId" runat="server" Style="z-index: 100; left: 0px; position: relative; top: 0px"></asp:TextBox></td> <td style="width: 279px"> <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtuserId" ErrorMessage="User Id Should Not Be Empty" Style="z-index: 100; left: 0px; position: relative; top: 0px"></asp:RequiredFieldValidator> </td> </tr> <tr> <td style="width: 133px"> <span style="color: #ff0000">*</span><asp:Label ID="Label6" runat="server" CssClass="lblAccountInformation" Style="z-index: 100; left: 0px; position: relative; top: 0px" Text="Enter Password"></asp:Label></td> <td style="width: 88px"> <asp:TextBox ID="txtPwd" runat="server" Style="z-index: 100; left: 0px; position: relative; top: 0px" TextMode="Password"></asp:TextBox></td> <td style="width: 279px"> <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtPwd" ErrorMessage="Password Should Not Be empty" Style="z-index: 100; left: 0px; position: relative; top: 0px"></asp:RequiredFieldValidator> </td> </tr> <tr>
<td style="width: 133px"> <span style="color: #ff0000">*</span><asp:Label ID="Label7" runat="server" CssClass="lblAccountInformation" Style="z-index: 100; left: 0px; position: relative; top: 0px" Text="Re-Type Password"></asp:Label></td> <td style="width: 88px"> <asp:TextBox ID="txtRePwd" runat="server" Style="z-index: 100; left: 0px; position: relative; top: 0px" TextMode="Password"></asp:TextBox></td> <td style="width: 279px"> <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txtRePwd" ErrorMessage="Re-Enter Password Should Not Be Empty" Style="zindex: 100; left: 0px; position: relative; top: 0px"></asp:RequiredFieldValidator> <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="txtPwd" ControlToValidate="txtRePwd" ErrorMessage="Password do not match" Style="z-index: 102; left: 0px; position: relative; top: 0px"></asp:CompareValidator></td> </tr> <tr> <td style="width: 133px"> <span style="color: #ff0000">*</span><asp:Label ID="Label8" runat="server" CssClass="lblAccountInformation" Style="z-index: 100; left: 0px; position: relative; top: 0px" Text="Date of Birth"></asp:Label></td> <td style="width: 88px"> <asp:TextBox ID="txtDOB" runat="server" Style="z-index: 100; left: 0px; position: relative; top: 0px"></asp:TextBox></td> <td style="width: 279px"> <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="txtDOB" ErrorMessage="DOB Should not be Empty" Style="z-index: 100; left: 0px; position: relative; top: 0px"></asp:RequiredFieldValidator> </td> </tr> <tr> <td style="width: 133px"> </td> <td style="width: 88px"> <asp:Button ID="btnSubmit" runat="server" CssClass="btnStyle" OnClick="btnSubmit_Click" Style="z-index: 100; left: 0px; position: relative; top: 0px" Text="Submit" /> <asp:Button ID="btnCancel" runat="server" CssClass="btnStyle" OnClick="btnCancel_Click" Style="z-index: 102; left: 0px; position: relative; top: 0px" Text="Cancel" /></td>
<td style="width: 279px"> </td> </tr> </table> </div> </form> </body> </html> NewUserSignUpPage.aspx.cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class NewUserSignUpPage : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnSubmit_Click(object sender, EventArgs e) { Response.Write("New account Created Successfully"); } protected void btnCancel_Click(object sender, EventArgs e) { Response.Redirect("LoginPage.aspx"); } } WelcomePage.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="WelcomePage.aspx.cs" Inherits="WelcomePage" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head>
<body> <form id="form1" runat="server"> <div> <table border="0" cellpadding="0" cellspacing="0" style="z-index: 100; left: 0px; width: 100%; position: absolute; top: 0px"> <tr> <td style="width: 100px"> <asp:Image ID="Image1" runat="server" ImageUrl="~/Images/dj2.JPG" Style="zindex:100; left: 0px; position: relative; top: 0px" /></td> </tr> </table> </div> </form> </body></html> WelcomePage.aspx.cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class NewUserSignUpPage : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnSubmit_Click(object sender, EventArgs e) { Response.Write("New account Created Successfully"); } protected void btnCancel_Click(object sender, EventArgs e) { Response.Redirect("LoginPage.aspx"); } }
Solution Explorer:
Style Sheet:
Result Thus, the program has been successfully executed and verified.