BRANCHING AND LOOPING EX.NO:1 Date : AIM: To write a C# program using Branching and Looping statements. ALGORITHM: Steps: 1. Start the program. 2. Declare the required variables. 3. Using for loop print i values. 4. Check the condition using if. 5. If the condition is true exit the loop and print the result. 6. If the condition is false check the for loop using “continue”. 7. Stop the process. PROGRAM: using System; using System.Collections.Generic; using System.Text; namespace branch { class Program { static void Main(string[] args) { int i; for(i=1;i<10;i++)
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
BRANCHING AND LOOPING
EX.NO:1
Date :
AIM: To write a C# program using Branching and Looping statements.
ALGORITHM:Steps:
1. Start the program.2. Declare the required variables.
3. Using for loop print i values.4. Check the condition using if.
5. If the condition is true exit the loop and print the result.6. If the condition is false check the for loop using “continue”. 7. Stop the process.
PROGRAM:
using System;using System.Collections.Generic;using System.Text;
RESULT:Thus the program is compiled and executed successfully and the results are obtained.
ARRAY, STRINGS & METHODS
EX.NO:2
Date :
AIM: To write a C# program using Arrays and Strings methods. ALGORITHM:
Steps:1. Start the program.2. Declare the array and string variables.3. Create a method named getnames()4. Get the input from user .5. Create another method named shownames() 6. Using for loop display all names.7. Create an object.8. Using the object call all the methods.9. Print the result.10. Stop the process.
PROGRAM:
using System; using System.Collections.Generic;
using System.Text;
namespace array1{
class Program { private string[] names = new string[5];
void getnames() { for (int i = 0; i < names.Length; i++) { Console.Write("enter name[{0}]:", i); names[i] = Console.ReadLine(); } } void shownames() {
for (int i = 0; i < names.Length; i++) {
Console.WriteLine("names[{0}]={1}" , i, names[i]);
} }
static void Main(string[] args) { Program obj = new Program ();
obj.getnames(); obj.shownames(); Console.Read();
} } }
OUTPUT:
Enter name[0]:gopi Enter name[1]:logu Enter name[2]:ravi Enter name[3]:ragu Enter name[4]:aravindhan
RESULT:Thus the program is compiled and executed successfully and the results are obtained.
STRUCTURES & ENUMERATIONS
EX.NO:3
Date :
AIM:To write a C# program using Structures and enumerations
ALGORITHM:
Steps:1. Start the program.2. Declare the required data types and declare enumeration as months.3. Declare the constructor.4. Create an object for class.5. Create the structure and call the enumeration.6. Display the result.7. Stop the process
} struct examplestruct { public int i; public examplestruct(int j) { i=j; } public void trial() { Console.WriteLine("Inside Trial Method"); } } }
OUTPUT:
20 28 10 Inside Trial Method february
RESULT:Thus the program is compiled and executed successfully and the results are obtained.
INHERITANCE
EX.NO:4
Date :
AIM:To write a C# program using inheritance concepts.
ALGORITHM:
Steps:1. Start the program.2. Create a class named room and declare the required variables and
methods.3. Create a sub class named bed and declare the required variables .4. Create an object for the sub class.5. Using the object call the methods and functions.6. Display the result.7. Stop the program
class room{ public int length; public int breadth; public room(int x,int y) { length=x; breadth=y; } public int area() { return(length*breadth); }}class br:room{ int height; public br(int x,int y,int z):base(x,y) { height=z; } public int volume() { return(length*breadth*height);
}}class ex4{ public static void Main() { br r1=new br(14,12,10); int area1=r1.area(); int volume1=r1.volume(); Console.WriteLine("Area : "+area1); Console.WriteLine("Volume : "+volume1); }}
OUTPUT:
Area:168 Volume:1680
RESULT:Thus the program is compiled and executed successfully and the results are obtained.
POLYMORPHISM
EX.NO:5
Date :
AIM:To write a C# program using Polymorphism.
ALGORITHM: Steps: 1. Start the program.
2. Create a base class named vehicle and declare the variables. 3. Create a derived class named automobile and perform the calculations.
4. Create a class and create an object for the derived class. 5. Call the methods using objects.
class ex5 { static void Main(string[] args) { Automobile a= new Automobile(); a.PowerSource="100 H.P"; a.IncreaseVelocity(60); BMW car=new BMW(); car.Color("Black"); Console.WriteLine("press enter to exit..."); Console.ReadLine(); } } class vehicle { string VehiclePower=" "; public string PowerSource { set { VehiclePower=value;
Console.WriteLine("power of engine is set to \"{0}\" ",val ue.ToString());
}
get { return VehiclePower; } } public virtual void IncreaseVelocity(int i) {
Console.WriteLine("The Speed Increases To " "+i.ToString()+"m.p.h");
} } class Automobile:vehicle { public override void IncreaseVelocity(int i) { if(i>120) { i=120; }
Console.WriteLine("Increasing Its Speed To "+i.ToString()+ " m.p.h"); } public virtual void Color(string col) { col="Blue"; Console.WriteLine("The Color Of BMW is: "); Console.WriteLine(col); } } class BMW:Automobile { public override void Color(string col) { col="navy"; Console.WriteLine("The Color Of BMW is: "); Console.WriteLine(col); } } }
OUTPUT:Power of engine is set to “100 H.P”
Increasing Its Speed To 60 m.p.h The color of BMW is: Navy Press enter to exit..
RESULT: Thus the program is compiled and executed successfully and the results
are obtained.
INTERFACES
EX.NO:6
Date :
AIM:To write a c# program using interfaces.
ALGORITHM:
Steps: 1. Start the program 2. Create two interfaces and declare the required variables. 3. Create the class and implement the two interfaces.
4. Create objects for both class and interfaces. 5. Call the methods using objects. 6. Display the result.
RESULT:Thus the program is compiled and executed successfully and the results are obtained.
OPERATOR OVERLOADING
EX.NO:7
Date :
AIM: To write a C# program by using operator overloading.
ALGORITHM: Steps:
1. Start the program. 2. Create a class named complex and declare the variables.
3. Create a constructor and assign the values to variables. 4. Write a function to implement operator overloading concept. 5. Create a class and create an object for the class complex. 6. Perform the calculations.
7. Display the result. 8. Stop the program.
PROGRAM:using System;
using System.Collections.Generic;using System.Text;
namespace overload1{ class complex { double x; double y; public complex() { }
public complex(double real, double imag) { x = real; y = imag; } public static complex operator +(complex c1, complex c2) { complex c3 = new complex(); c3.x = c1.x + c2.x; c3.y = c1.y + c2.y;
class Program { static void Main(string[] args) { complex a, b, c; a = new complex(2.5, 3.5); b = new complex(1.6, 2.7); c = a + b; Console.Write("a ="); a.display(); Console.Write("b="); b.display(); Console.Write("c="); c.display(); Console.Read(); } }}
OUTPUT:
a=2.5 3.5 b=1.6 2.7 c=4.1 6.2
RESULT:Thus the program is compiled and executed successfully and the results are obtained.
DELEGATES, EVENTS, ERRORS AND EXCEPTIONS
EX.NO:8(a)
Date :
AIM:To write a C# program using delegates, events, errors and exceptions.
ALGORITHM:
Steps:1. Start the program.
2. Create a namespace and declare a delegate function. 3. Create a class named event class and declare the variables. 4. Create a function and check the status. 5. Create a class named event test and create object for both classes. 6. Call the methods using that objects. 7. Display the result. 8. Stop the program.
namespace dele2{ public delegate void EDelegate(String str); class eventclass { public event EDelegate status; public void TriggerEvent() { if(status!=null) status("event triggered"); } } class ex8 { public static void Main() { eventclass ec=new eventclass(); ex8 et=new ex8(); ec.status+=new EDelegate(et.EventCatch); ec.TriggerEvent(); Console.Read(); } public void EventCatch(string str) {
Console.WriteLine(str); } } }
OUTPUT:
Event triggered
EX.NO:8. (b)
AIM:
To write a C# program using Errors and Exceptions. ALGORITHM:
Steps:
1. Start the program. 2. Create a namespace and declare Exception function. 3. Create a class name Exception class and declare the variables. 4. Create a try, catch, finally blocks functions. 5. Display the result. 6. Stop the program.
PROGRAM: using System;
using System.Collections.Generic;using System.Text;
namespace ConsoleApplication2 {
class Program { static void Main(string[] args) { try { Decimal dresult = Decimal.Divide(5, 0); Console.WriteLine("Result is :{0}", dresult); }
RESULT:Thus the program is compiled and executed successfully and the results are obtained.
MULTI MODULE ASSEMBLY
EX.NO:10
Date :
AIM: To write a C# program using multi module Assembly. ALGORITHM:
Step 1 — Compiling Files with Namespaces Referenced by Other Files
csc /t:module Stringer.cs
Specifying the module parameter with the /t: compiler option indicates that the file should be compiled as a module rather than as an assembly. The compiler produces a module called Stringer.netmodule, which can be added to an assembly
Step 2 — Compiling Modules with References to Other Modules
Specify the /t:module option because this module will be added to an assembly in a future step. Specify the /addmodule option because the code in Client references a namespace created by the code in Stringer.netmodule. The compiler produces a module called Client.netmodule that contains a reference to another module, Stringer.netmodule.
Step 3 — Creating a Multifile Assembly Using the Assembly Linker
al Client.netmodule Stringer.netmodule /main:MainClientApp.Main /out:myAssembly.exe /target:exe
You can use the MSIL Disassembler (Ildasm.exe) to examine the contents of an assembly, or determine whether a file is an assembly or a module.
RESULT:Thus the program is compiled and executed successfully and the results are obtained.
WEB APPLICATIONS
EX.NO:12
Date :
AIM: ALGORITHM:
Steps:
1. Enter into the Microsoft Visual studio 2005.2. Create a new project based on ASP.NET website.[File->New- >Website->ASP.NET Website].3. Enter into the design of the page.4. Type the text in the design page.5. Double click on “access data source” icon under the data toolbox.6. Click on configure data source.7. Type the specified database path and finally click finish.8. Place the control data grid view from the data toolbox.9. Set accessdatasource1 to the data source property of the data grid view.10. Save and run the website.
PROGRAM:
using System;using System.Data;using System.Configuration;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 _Default : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){