C# Lab Report VTU
C# Lab Report VTU
C# Lab Report VTU
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Square root of "+args[0]+" given number is: " +
Math.Sqrt(Convert.ToDouble(args[0])));
Console.Read();
}
}
}
OUTPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace sumaverage
{
class Program
{
static void Main(string[] args)
{
float sum = 0;
int i = 0;
while (i < 3)
{
sum += Convert.ToInt64(args[i]);
i = i + 1;
}
Console.WriteLine("sum of all the numbers:" + sum + "\naverage of those numbers:" + sum / 3);
Console.Read();
}
}
}
OUTPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
ArrayList a = new ArrayList();
a.Add(10);
a.Add(10.4);
a.Add(false);
int x = (int)a[0];
double y = (double)a[1];
bool z = (bool)a[2];
Console.WriteLine("value of x is:" + x);
Console.WriteLine("value of Y is:" + y);
Console.WriteLine("value of z is:" + z);
Console.ReadLine();
}
}
}
OUTPUT:
b) Invalid Unboxing.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
int i = 143;
object o = i;
try
{
int j = (short)o;
Console.WriteLine("unboxing");
}
catch (System.InvalidCastException e)
{
Console.WriteLine("{0} Error: Incorrect unboxing", e.Message);
}
Console.ReadLine();
}
}
}
OUTPUT:
namespace sab3
{
class Program
{
public struct Complex
{
public int real;
public int img;
public Complex(int r, int img)
{
this.real = r;
this.img = img;
}
public static Complex operator +(Complex c1, Complex c2)
{
return new Complex(c1.real + c2.real, c1.img + c2.img);
}
public override string ToString()
{
return (String.Format("{0}+{1}i",real,img));
}
}
}
}
}
OUTPUT:
4. Write a Program in C# to find the sum of each row of given jagged array of 3
inner arrays.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int[][] jag = new int[3][];
int sum = 0;
jag[0] = new int[] { 1, 1, 1, 6, 7 };
jag[1] = new int[] { 1, 1, 1};
jag[2] = new int[] { 1, 1, 1};
for (int i = 0; i<jag.Length; i++)
{
sum = 0;
for (int j = 0; j < jag[i].Length; j++)
{
sum = sum + jag[i][j];
}
Console.WriteLine("Sum of rows:" + sum);
}
Console.ReadLine();
}
}
}
OUTPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace lab5
{
class Program
{
static void Main(string[] args)
{
int a,b,c;
Console.WriteLine("Enter a and b : ");
a = int.Parse(Console.ReadLine());
b = int.Parse(Console.ReadLine());
try
{
c = a / b;
Console.WriteLine("C="+c);
}
catch (DivideByZeroException e)
{
Console.WriteLine("Cannot divide by zero");
}
catch (ArithmeticException e)
{
Console.WriteLine("Error in arithmetic exception");
}
finally
{
Console.WriteLine("Program Ends");
}
Console.ReadLine();
}
}
}
OUTPUT:
6. Demonstrate Use of Virtual and override key words in C# with a simple program.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication6
{
class shape
{
public virtual void Draw()
{
Console.WriteLine("Drawing shape .... ");
}
}
class Program
{
static void Main(string[] args)
{
shape tshape = new shape();
tshape = new circle();
tshape.Draw();
tshape = new Rectangle();
tshape.Draw();
Console.ReadLine();
}
}
}
OUTPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
}
}
}
OUTPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
abstract class Department
{
string HOD;
int no_of_faculty;
public string hod_name
{
get
{
return HOD;
}
set
{
HOD = value;
}
}
public int nfaculty
{
get
{
return no_of_faculty;
}
set
{
no_of_faculty = value;
}
}
public abstract void getdetail();
public abstract void displaydetail();
}
hod_name = Console.ReadLine();
Console.WriteLine("Enter number of faculties in MCA");
nfaculty = int.Parse(Console.ReadLine());
}
public override void displaydetail()
{
Console.WriteLine("MCA hod name={0}", hod_name);
Console.WriteLine("Number of faculties={0}", nfaculty);
}
}
class Program
{
static void Main(string[] args)
{
MCA mc = new MCA();
MBA mb = new MBA();
mc.getdetail();
mb.getdetail();
mc.displaydetail();
mb.displaydetail();
Console.ReadLine();
}
}
}
OUTPUT:
9. Write a program to Set & Get the Name & Age of a person using
Properties of C# to illustrate the use of different properties in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class person
{
string name;
int age;
class Program
{
static void Main(string[] args)
{
person obj = new person();
Console.WriteLine("enter your name");
obj.pname = Console.ReadLine();
Console.WriteLine("enter your age");
obj.page = int.Parse(Console.ReadLine());
Console.WriteLine(" ------ ");
Console.WriteLine("name={0} age={1}", obj.pname, obj.page);
Console.ReadLine();
}
}
}
OUTPUT:
namespace ConsoleApplication5
{
public interface Ishape
{ double Area(double x); }
class Program
{
static void Main(string[] args)
{
Ishape[] sh = { new Square(), new Circle() };
for (int i = 0; i<sh.Length; i++)
{
if (sh[i] is Ishape)
{
Ishape iss = (Ishape)sh[i];
Console.WriteLine(iss.Area(20.2));
}
}
Console.ReadLine();
}
}
}
OUTPUT:
PART - B
1 Project Manager
2 Project Leader
3 Engineer
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Partb1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
frm.Show();
this.Hide();
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Partb1
{
public partial class Form5 : Form
{
OUTPUT:
2. Display all the Project Leaders (In a Grid) reporting to selected Project Managers
(In a Combo box).
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Partb1
{
public partial class Form2 : Form
{
SqlConnection scon = new SqlConnection(@"Data
Source=.\SQLEXPRESS;AttachDbFilename=E:\Partb1\Partb1\db_EMS.mdf;Integ
rated Security=True;User Instance=True");
SqlDataAdapter da;
DataTable dt;
public Form2()
{
InitializeComponent();
scon.Open();
FillcomboBox1();
}
public void FillcomboBox1()
{
da = new SqlDataAdapter("Select
ed.IdEmployee,ed.EmployeeName from tbl_EmployeeDetails ed where
ed.IdDesignation=1", scon);
dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "EmployeeName";
comboBox1.ValueMember = "IdEmployee";
}
}
private void button1_Click(object sender, EventArgs e)
{
da = new SqlDataAdapter("SELECT EmployeeName,ContactNumber
FROM tbl_EmployeeDetails WHERE IdDesignation=2 and
IdReportingTo="+comboBox1.SelectedValue, scon);
dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count >=1)
dataGridView1.DataSource = dt;
else
{
dataGridView1.DataSource = null;
MessageBox.Show("Not availabe for s...!");
}
}
private void button2_Click(object sender, EventArgs e)
{
Form1 f3 = new Form1();
f3.Show();
this.Hide();
}
}
}
OUTPUT:
3. Display all the Engineers (In a Grid) reporting to selected Project Leader (In a
Combo box).
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Partb1
{
public partial class Form3 : Form
{
SqlConnection scon = new SqlConnection(@"Data
Source=.\SQLEXPRESS;AttachDbFilename=E:\Partb1\Partb1\db_EMS.mdf;Integ
rated Security=True;User Instance=True");
SqlDataAdapter da;
DataTable dt;
public Form3()
{
InitializeComponent();
FillcomboBox1();
}
public void FillcomboBox1()
{
da = new SqlDataAdapter("Select
ed.IdEmployee,ed.EmployeeName from tbl_EmployeeDetails ed where
ed.IdDesignation=2", scon);
dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "EmployeeName";
comboBox1.ValueMember = "IdEmployee";
}
}
private void button1_Click(object sender, EventArgs e)
{
da = new SqlDataAdapter("SELECT EmployeeName,ContactNumber
FROM tbl_EmployeeDetails WHERE IdDesignation=3 and IdReportingTo=" +
comboBox1.SelectedValue, scon);
dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count >= 1)
dataGridView1.DataSource = dt;
else
{
dataGridView1.DataSource = null;
MessageBox.Show("Not availabe for s...!");
}
}
private void Form3_MouseDoubleClick(object sender,
MouseEventArgs e)
{
Form4 f4 = new Form4();
f4.Show();
this.Hide();
}
private void button2_Click(object sender, EventArgs e)
{
Form1 f4 = new Form1();
f4.Show();
this.Hide();
}
}
}
OUTPUT:
4. Display all the Employees (In a Grid) with their reporting Manager (No Value for
PM).
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Partb1
{
public partial class Form4 : Form
{
SqlConnection scon = new SqlConnection(@"Data
Source=.\SQLEXPRESS;AttachDbFilename=E:\Partb1\Partb1\db_EMS.mdf;Integ
rated Security=True;User Instance=True");
SqlDataAdapter da;
DataTable dt;
public Form4()
{
InitializeComponent();
scon.Open();
}
}
private void button1_Click_1(object sender, EventArgs e)
{
Form1 f4 = new Form1();
f4.Show();
this.Hide();
}
}
}
OUTPUT:
II. Consider the Database db_LSA (Lecturer Subject Allocation) consisting of the following
tables:
tbl_Subjects(IdSubject: int, SubjectCode: string, SubjectName: string)
tbl_Lecturers(IdLecturer: int, LecturerName: string, ContactNumber: string)
tbl_LecturerSubjects(IdSubject: int, SubjectCode: string, IdLecturer: int)
namespace PartBII
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace PartBII
{
public partial class Form2 : Form
{
//intialize connection
SqlConnection con = new SqlConnection(@"Data
Source=.\SQLEXPRESS;AttachDbFilename=c:\users\temp\documents\visual
studio 2010\Projects\PartBII\PartBII\Database1.mdf;Integrated
Security=True;User Instance=True");
public Form2()
{
InitializeComponent();
}
}
}
}
OUTPUT:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
//intialize connection
SqlConnection con = new SqlConnection(@"Data
Source=.\SQLEXPRESS;AttachDbFilename=c:\users\temp\documents\visual
studio 2010\Projects\PartBII\PartBII\Database1.mdf;Integrated
Security=True;User Instance=True");
public Form3()
{
InitializeComponent();
}
//intialize connection
SqlConnection con = new SqlConnection(@"Data
Source=.\SQLEXPRESS;AttachDbFilename=c:\users\temp\documents\visual
studio 2010\Projects\PartBII\PartBII\Database1.mdf;Integrated
Security=True;User Instance=True");
public Form4()
{
InitializeComponent();
fill_comboBox1();
}
OUTPUT:
4. Display all the subjects allocated (In a Grid) to the selected Lecturer (In a Combo
Box).
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
public Form5()
{
InitializeComponent();
fill_comboBox1();
}
}
}
}
}
OUTPUT:
III. Consider the database db_VSS (Vehicle Service Station) consisting of the
following tables:
tbl_VehicleTypes(IdVehicleType: int, VehicleType: string, ServiceCharge:
int)
tbl_ServiceDetails(IdService: int, VehicleNumber: string, ServiceDetails:
string, IdVehicleType: int)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace PartBIII
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
}
1. Enter new Service Details for the Selected Vehicle Type (In a Combo
Box).
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace PartBIII
{
public partial class Form2 : Form
{
SqlConnection con = new SqlConnection(@"Data
Source=.\SQLEXPRESS;AttachDbFilename=c:\users\temp\documents\visual
studio 2010\Projects\PartBIII\PartBIII\Database1.mdf;Integrated
Security=True;User Instance=True");
public Form2()
{
InitializeComponent();
con.Open();
FillCombox1();
//comboBox1.SelectedIndexChanged
+=comboBox1_SelectedIndexChanged;
}
}
OUTPUT:
public Form3()
{
InitializeComponent();
con.Open();
FillComboBox1();
}
}
}
}
OUTPUT:
3. Total Service Charges Collected for the Selected Vehicle (In a Combo
box) with total amount displayed in a text box.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
Dept. of MCA, BIT
.NET LABORATORY (18MCA56)
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace PartBIII
{
public partial class Form4 : Form
{
SqlConnection con = new SqlConnection(@"Data
Source=.\SQLEXPRESS;AttachDbFilename=c:\users\temp\documents\visual
studio 2010\Projects\PartBIII\PartBIII\Database1.mdf;Integrated
Security=True;User Instance=True");
public Form4()
{
InitializeComponent();
con.Open();
FillComboBox1();
}
}
}
}
OUTPUT:
IV. Develop a web application using C#.NET and ASP.NET for the Postal
System Management. The master page should contain the hyperlinks for
adding Area Details, Postman details, Letter distributions and View Letters.
Consider the database db_PSM (Postal System Management) consisting of
the following tables:
tbl_AreaDetails(IdArea: int, AreaName: string)
tbl_PostmanDetails(IdPostman: int, PostmanName: string, ContactNumber:
string, IdArea: int)
tbl_AreaLetters(IdLetter: int, LetterAddress: string, IdArea: int)
Develop the suitable content pages for the above created 4 hyper links with
the following details:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
}
OUTPUT:
2. Enter New Postman Details with the Area he/she is in-charge of (display
Area in a Combo box).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
try
{
SqlDataAdapter da = new SqlDataAdapter("INSERT INTO
PostmanDetails(IdPostman,PostmanName,ContactNumber,IdArea) VALUES ('"
+ TextBox1.Text + "', '" + TextBox2.Text + "','" + TextBox2.Text +
"'," + DropDownList1.SelectedValue + ")", con);
DataTable dt = new DataTable();
da.Fill(dt);
Label3.Text = "postmandetails Saved Successfully..!";
}
catch (Exception ex)
{
Label3.Text = ex.Message.ToString();
}
}
}
OUTPUT:
3. Enter all the Letters distributed to the selected Area (display Area in a
Combo box).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
OUTPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
else
{
GridView1.DataBind();
Label3.Text = "No Records Found..!!!!";
}
}
}
catch (Exception ex)
{
Label3.Text = ex.Message.ToString();
}
}
}
OUTPUT:
V. Develop a web application using C#.NET and ASP.NET for the Complaint
Management System. The master page should contain the hyper links for
Add Engineer, Complaint Registration, Complaint Allocation, View
Complaints.
Consider the database db_CMS (Complaint Management System) consisting
of the following tables:
tbl_Departments(IdDepartment: int, DepartmentName: string).
tbl_Engineers(IdEngineer: int, EngineerName: string, ContactNumber:
string, IdDepartment: int).
tbl_RegisteredComplaints(IdComplaint: int, ComplaintDescription: string).
tbl_DepartmentComplaints(IdDepartment: int, IdComplaint: int).
NOTE: Consider the table tbl_Departments as a static table containing some pre-
entered departments, which are displayed in all the remaining modules.
Develop the suitable content pages for the above created 4 hyper links with
the following details:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
try
{
string query = "INSERT INTO
Engineers(IdEngineer,EngineerName,ContactNumber,idDepartment)
VALUES('" + TextBox1.Text + "','" + TextBox2.Text + "','" +
TextBox3.Text + "'," + DropDownList1.SelectedValue + ")";
SqlDataAdapter sda = new SqlDataAdapter(query, con);
DataTable dt = new DataTable();
sda.Fill(dt);
Label3.Text = "Engineers details Inserted
Successfully...!";
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
}
catch (Exception ex)
{
Label3.Text = ex.Message.ToString();
}
}
}
OUTPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
}
}
OUTPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
OUTPUT:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
OUTPUT: