Вы находитесь на странице: 1из 46

Department of CSE

Dot NET
Framework

(CSL0662)

Session: 2020-2021

Submitted By Submitted
To
MANJIT KUMAR Mr. RAHUL YADAV
(BETN1CS1703 ) Assistant Professor
0
Lab Report
INDEX

S. No. Title of Practical Date of Date of Remark


Conduction Submission

Write a C# Sharp program to print on screen


the output of adding, subtracting, multiplying
1.
and dividing of two numbers which will be
entered by the user.

Write a program to display student


information. Accept Student’s name, Roll No,
2. Age, class, and university name and marks of
subjects and calculate the total, percentage and
determine a student’s grade
Write a program of tax calculation. Accept
money as input from the user and calculate the
tax using following pattern. MONEY
3.
Percentage Less than 10,000 5 % 10,000 to
100,000 8% More than 100,000 8.5 %, Total
Tax

Write a C# program to reverse number and


4
compute the sum of the digits of number
Write a program in C# Sharp to make such a
pattern like right angle triangle with number
increased by 1.
5 1
23
456
7 8 9 10

Write a program that takes three points (x1,


y1), (x2, y2) and (x3, y3) from the user and the
6.
program will check whether or not all the three
points fall on one straight line.

(BETN1CS17030) Dot NET Framework (CSL0662)


In a company, worker efficiency is determined
on the basis of the time required for a worker to
complete a specific job. If the time taken by the
worker is between 2 - 3 hours, then the worker
is said to be highly efficient. If the time
required by the worker is 3 - 4 hours, then the
worker is ordered to increase their speed. If the
7.
time taken is 4 - 5 hours then the worker is
given training to improve his speed and if the
time taken by the worker is more than 5 hours
then the worker must leave the company. If the
time taken by the worker is input through the
keyboard then find the efficiency of the
worker.
Write a program in C# Sharp to create a
8. function to calculate the area & Perimeter of a
Circle using methods.
WAP that describes a class person. It should
have instance variables to record name, age and
9.
salary. Create a person object. Set and display
its instance variables.
Write a C# program to read students
10. information and print details using two classes
and simple inheritance.
Write a C# program to demonstrate example of
11. hierarchical inheritance to get square and cube
of a number.
Write a program to implement the concept of
12. Exception Handling by creating user defined
exceptions.
Create an abstract class shape. Let rectangle
13. and triangle inherit this shape class. Add
necessary functions.
Write a program using Virtual and Override
keyword that does the following tasks.
1. A virtual function Engine () that has
14. basic properties of engine like Power of
engine, RPM, no of Cylinder etc.
2. This function should be overridden in child
class according to function.
Design a Login form and validate it using
15.
windows based Application.

Create a Window based Application of


16.
Arithmetic Calculator in C#.net.

WAP for Tic Tack Toe game using C#


17.
Window Based Application.
WAP for Traffic Light Simulation in C# using
18.
Windows Application.
Create a Window based Application for Online
19.
Billing System.
WAP to create a Student Registration form and
20. Connect MS Access Database to C# Windows
Form Application
Q 1. Write a C# Sharp program to print on screen the output of
adding, subtracting, multiplying and dividing of two numbers which
will be entered by the user.

using System;

public class Exercise7

public static void Main()

Console.Write("Enter a number: ");

int num1= Convert.ToInt32(Console.ReadLine());

Console.Write("Enter another number: ");

int num2= Convert.ToInt32(Console.ReadLine());

Console.WriteLine("{0} + {1} = {2}", num1, num2, num1+num2);

Console.WriteLine("{0} - {1} = {2}", num1, num2, num1-num2);

Console.WriteLine("{0} x {1} = {2}", num1, num2, num1*num2);

Console.WriteLine("{0} / {1} = {2}", num1, num2, num1/num2);

Console.WriteLine("{0} mod {1} = {2}", num1, num2, num1%num2);

}
Output:-

Enter a number: 10

Enter another number: 2

10 + 2 = 12

10 - 2 = 8

10 x 2 = 20

10 / 2 = 5

10 mod 2 = 0
Q 2. Write a program to display student information. Accept
Student’s name, Roll No, Age, class, and university name and marks
of subjects and calculate the total, percentage and determine a
student’s grade

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

public class Exercise12

static void Main(string[] args)

double rl,phy,che,ca,total;

double per;

string nm,div;

Console.Write("\n\n");

Console.Write("Calculate the total, percentage and division to take marks of


three subjects:\n");

Console.Write("
");

Console.Write("\n\n");
Console.Write("Input the Roll Number of the student :");

rl = Convert.ToInt32(Console.ReadLine());

Console.Write("Input the Name of the Student :");

nm = Console.ReadLine();

Console.Write("Input the marks of Physics : ");

phy= Convert.ToInt32(Console.ReadLine());

Console.Write("Input the marks of Chemistry : ");

che = Convert.ToInt32(Console.ReadLine());

Console.Write("Input the marks of Computer Application : ");

ca = Convert.ToInt32(Console.ReadLine());

total = phy+che+ca;

per = total/3.0;

if (per>=60)

div="First";

else

if (per<60&&per>=48)

div="Second";

else

if (per<48&&per>=36)

div="Pass";

else
div="Fail";

Console.Write("\nRoll No : {0}\nName of Student : {1}\n",rl,nm);

Console.Write("Marks in Physics : {0}\nMarks in Chemistry : {1}\nMarks in


Computer Application : {2}\n",phy,che,ca);

Console.Write("Total Marks = {0}\nPercentage = {1}\nDivision =


{2}\n",total,per,div);

Output:-
Calculate the total, percentage and division to take marks of three subjects:

Input the Roll Number of the student :10

Input the Name of the Student :john smith

Input the marks of Physics : 50

Input the marks of Chemistry : 46

Input the marks of Computer Application : 64

Roll No : 10

Name of Student : john smith

Marks in Physics : 50

Marks in Chemistry : 46

Marks in Computer Application : 64

Total Marks = 160

Percentage = 53.3333333333333

Division = Second
Q3. Write a program of tax calculation. Accept money as input from
the user and calculate the tax using following pattern. MONEY
Percentage Total Tax Less than 10,000 5 % 10,000 to 100,000 8%
More than 100,000 8.5 %
using System;

class Program

static void Main()

Console.Write("Input money : ");

double money = double.Parse(Console.ReadLine());

double tax;

if (money < 10000)

tax = .05 * money;

else if (money <= 100000)

tax = .08 * money;

else

tax = .085 * money;

}
Console.WriteLine("Tax is {0:C}", tax);

Console.ReadKey();

Q4. Write a C# program to reverse number and compute the sum of


the digits of number
// C# program to reverse a number

using System;

class GFG

// Iterative function to

// reverse digits of num

static int reversDigits(int num)

int rev_num = 0;

while(num > 0)

rev_num = rev_num * 10 + num % 10;

num = num / 10;

return rev_num;

}
// Driver code

public static void Main()

int num = 4562;

Console.Write("Reverse of no. is "

+ reversDigits(num));

OUTPUT:-2654

Q5. Write a program in C# Sharp to make such a pattern like right


angle triangle with number increased by 1. 1 2 3 4 5 6 7 8 9 10

using System;
public class Exercise12

public static void Main()

int i,j,rows,k=1;

Console.Write("\n\n");

Console.Write("Display the pattern like right angle triangle with number


increased by 1:\n");

Console.Write(" ");
Console.Write("\n\n");

Console.Write("Input number of rows : ");

rows= Convert.ToInt32(Console.ReadLine());

for(i=1;i<=rows;i++)

for(j=1;j<=i;j++)

Console.Write("{0} ",k++);

Console.Write("\n");

Output:-
Display the pattern like right angle triangle with number increased by 1:

Input number of rows : 5

23

456

7 8 9 10

11 12 13 14 15
Q6. Write a program that takes three points (x1, y1), (x2, y2) and
(x3, y3) from the user and the program will check whether or not all
the three points fall on one straight line.
// C# program to check if

// three points are collinear

// or not using area of triangle.

using System;

class GFG

/* function to check if

point collinear or not */

static void collinear(int x1, int y1, int x2,

int y2, int x3, int y3)

/* Calculation the area of

triangle. We have skipped

multiplication with 0.5 to

avoid floating point computations */

int a = x1 * (y2 - y3) +

x2 * (y3 - y1) +

x3 * (y1 - y2);
if (a == 0)

Console.Write("Yes");

else

Console.Write("No");

// Driver code

public static void Main ()

int x1 = 1, x2 = 1, x3 = 1,

y1 = 1, y2 = 4, y3 = 5;

collinear(x1, y1, x2, y2, x3, y3);

Output:-

Yes
Q7. In a company, worker efficiency is determined on the basis of
the time required for a worker to complete a specific job. If the
time taken by the worker is between 2 - 3 hours, then the worker is
said to be highly efficient. If the time required by the worker is 3 - 4
hours, then the worker is ordered to increase their speed. If the
time taken is 4 - 5 hours then the worker is given training to
improve his speed and if the time taken by the worker is more than
5 hours then the worker must leave the company. If the time taken
by the worker is input through the keyboard then find the
efficiency of the worker.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Problem6
{
classProblem6
{
staticvoid Main(string[] args)
{
Console.WriteLine("\t\tName: Ehtesham Mehmood\n\t\tRoll No: 11014119-131\n\t\tSection:
AE\n \t\t UOG\n");

int time;
Console.WriteLine("Enter Time Required For A Worker To Complete A Particular Job In
Hours");
time = Convert.ToInt32(Console.ReadLine());
if (time >= 2 && time >=3)

Console.WriteLine("Worker Efficiency Is Highly Efficient.");


}

if (time >= 3 && time >=4)

{
Console.WriteLine("Worker Should Improve His Speed.");

if (time >= 4 && time >= 5)

Console.WriteLine("Worker Is Given Training To Improve His Speed.");

if (time > 5)

Console.WriteLine("Worker Should Leave The Company.");

Console.ReadKey();

OUTPUT:
Enter Time required for a worker to complete a particular job in hours
3
Worker Efficency is highle Efficient
Q8. Write a program in C# Sharp to create a function to calculate
the area & Perimeter of a Circle using methods.
using System;

public class Exercise5

public static void Main()

double r,per_cir;

double PI = 3.14;

Console.WriteLine("Input the radius of the circle : ");

r = Convert.ToDouble(Console.ReadLine());

per_cir = 2 * PI * r;

Console.WriteLine("Perimeter of Circle : {0}", per_cir);

Console.Read();

Output:-

Input the radius of the circle :


25

Perimeter of Circle : 157


Q9. WAP that describes a class person. It should have instance variables to
record name, age and salary. Create a person object. Set and display its
instance variables.

using System;

namespace ProgrammingGuide

// Class definition.

public class CustomClass

// Class members.

//

// Property.

public int Number { get; set; }

// Method.

public int Multiply(int num)

return num * Number;

// Instance Constructor.

public CustomClass()

Number = 0;

}
}

// Another class definition that contains Main, the program entry point.

class Program

static void Main(string[] args)

// Create an object of type CustomClass.

CustomClass custClass = new CustomClass();

// Set the value of the public property.

custClass.Number = 27;

// Call the public method.

int result = custClass.Multiply(4);

Console.WriteLine($"The result is {result}.");

output:

The result is 108.


Q10. Write a C# program to read students information and
print details using two classes and simple inheritance .
Ans:-
using System;
namespace ConsoleApp1
{
class student
{
int x;
public void display(int r)
{
x = r;
if (x == 1)
{
Console.WriteLine("name = Manjit");
Console.WriteLine("roll = 1");
Console.WriteLine("branch = cse");
Console.WriteLine("course = B.tech");
}
else if (x == 2)
{
Console.WriteLine("name = ranjit");
Console.WriteLine("roll = 2");
Console.WriteLine("branch = ce");
Console.WriteLine("course = B.tech");
}
else
{
Console.WriteLine("no details");
}
}
}
class driv : student
{
public void displayed()
{
Console.WriteLine("student details are in parent class");
}
static void Main(string[] args)
{
Console.WriteLine("enter roll no.");
int y = Convert.ToInt32(Console.ReadLine());
driv dr = new driv();
dr.displayed();
dr.display(y);
}
}
}
Q 11. Write a C# program to demonstrate example of
hierarchical inheritance to get square and cube of a number.
Ans:
using System;

namespace ConsoleApp2
{
public class A
{
public void num1(int x)
{
numb = x;
Console.WriteLine("number enter by you is : "+ numb);
}
protected static int numb;
}
public class B:A
{
public B()
{
int s = numb * numb;
Console.WriteLine("square of a given number is : "+ s);
}
}
class C:A
{
public C()
{
int c = numb * numb * numb;
Console.WriteLine("cube of a given number is : "+ c);
}
}
class D
{
static void Main(string[] args)
{
Console.WriteLine("enter the number to find sqaure and
cube");
int n = Convert.ToInt32(Console.ReadLine());
A ob1 = new A();
ob1.num1(n);

B ob2 = new B();


C ob3 = new C();
}
}
}
Q12. Write a program to implement the concept of Exception
Handling by creating user defined exceptions.
Ans:-
using System;
public class InvalidAgeException : Exception
{
public InvalidAgeException(String message): base(message)
{
}
}
public class TestUserDefinedException
{
static void validate(int age)
{
if (age < 18)
{
throw new InvalidAgeException("Sorry, Age must be greater th an 18");
}
}
public static void Main(string[] args)
{
try
{
validate(12);
}
catch (InvalidAgeException e)
{ Console.WriteLine(e); }
Console.WriteLine("Rest of the code");
}
}

Output:
InvalidAgeException: Sorry, Age must be greater than 18 Rest of the code
Q13:- Create an abstract class shape. Let rectangle and triangle inherit this
shape class. Add necessary functions.

Ans:-
using System;
public abstract class Shape
{
public abstract void draw();
}
public class Rectangle : Shape
{
public override void draw()
{
Console.WriteLine("drawing rectangle...");
}
}
public class Circle : Shape
{
public override void draw()
{
Console.WriteLine("drawing circle...");
}
}
public class TestAbstract
{
public static void Main()
{
Shape s;
s = new Rectangle();
s.draw();
s = new Circle();
s.draw();
}
}

Output:
drawing rectangle...

drawing circle...
Q 14. Write a program using Virtual and Override keyword that does the following
tasks.

1. A virtual function Engine() that has basic properties of engine like Power of
engine, RPM, no of Cylinder etc.
2. This function should be overridden in child class according to function.

ANS:-

using System;

namespace ConsoleApp3
{
class tvs_star_city
{
public void company()
{
Console.WriteLine("name:- Manjit kumar");
Console.WriteLine("rollno:- BETN1CS17030");
Console.WriteLine("tvs");
}
public virtual void engine()
{
Console.WriteLine("tvs star city model");
Console.WriteLine("Displacement 110 cc");
Console.WriteLine("Mileage 67 kmpl");
Console.WriteLine("no. of Cylinders 1");
Console.WriteLine("Max Power 8 bhp @ 7,500 rpm");
Console.WriteLine("Maximum Torque 8 Nm @ 5,000 rpm");
Console.WriteLine("Ignition CVTi");
Console.WriteLine("No. of Gears 4");
Console.WriteLine("Fuel Type Petrol");
Console.WriteLine();
}
}
class tvs_star_city_plus : tvs_star_city
{
public override void engine()
{
Console.WriteLine("tvs star city plus model");
Console.WriteLine("Displacement 109.7 cc");
Console.WriteLine("Mileage 80 kmpl");
Console.WriteLine("no. of Cylinders 1");
Console.WriteLine("Max Power 8.4 bhp @ 7,000 rpm");
Console.WriteLine("Maximum Torque 8.7 Nm @ 5,500 rpm");
Console.WriteLine("Ignition CVTi");
Console.WriteLine("No. of Gears 4");
Console.WriteLine("Fuel Type Petrol");
Console.WriteLine();
}
}
class tvs_star_city_plus_bs6 : tvs_star_city
{
public override void engine()
{
Console.WriteLine("tvs star city plus bs6 model");
Console.WriteLine("Displacement 109.7 cc");
Console.WriteLine("Mileage 88 kmpl");
Console.WriteLine("no. of Cylinders 1");
Console.WriteLine("Max Power 8.19 PS @ 7350 rpm");
Console.WriteLine("Maximum Torque 8.7 Nm @ 4,500 rpm");
Console.WriteLine("Ignition ECU");
Console.WriteLine("No. of Gears 4");
Console.WriteLine("Fuel Type Petrol");
Console.WriteLine();
}
}
class tvs_bike
{
static void Main(string[] args)
{
tvs_star_city ob1 = new tvs_star_city();
tvs_star_city_plus ob2 = new tvs_star_city_plus();
tvs_star_city_plus_bs6 ob3 = new
tvs_star_city_plus_bs6(); tvs_star_city ob4 = new
tvs_star_city_plus(); tvs_star_city ob5 = new
tvs_star_city_plus_bs6(); ob3.company();
ob1.engine();
ob2.engine();
ob3.engine();
ob4.engine();
ob5.engine();
}
}
}
Q15. Design a Login form and validate it using windows based Application.

private void button1_Click(object sender, EventArgs e)


{ String usr_name =
textBox1.Text;
String pass =
textBox2.Text;

if(usr_name == "admin" && pass == "password")


{
MessageBox.Show("Login Successfully");
}

if(usr_name != "admin" || pass != "password" )


{
MessageBox.Show("Invalied Username or Password");
}
}
private void Form1_Load(object sender, EventArgs e)
{
textBox2.PasswordChar = '*';
}

Output-
Q16. Create a Window based Application of Arithmetic Calculator in C#.net.

publicpartialclassForm1:Form
{
stringinput=string.Empty;//Stringstoringuserinput
Stringoperand1=string.Empty;//Stringstoringfirstoperand
Stringoperand2=string.Empty;//Stringstoringsecondoperand
charoperation;//Chartostoreoperator
double result = 0.0;
//Get result
publicForm1()
{
InitializeComponent();
}

privatevoidbutton1_Click(objectsender,EventArgse)
{
this.textBo
x1.Text =
""; input
+= "1";
this.textBo
x1.Text+=in
put;
}

privatevoidbutton2_Click(objectsender,EventArgse)
{
this.textBo
x1.Text =
""; input
+= "2";
this.textBo
x1.Text+=in
put;
}
privatevoidbutton3_Click(objectsender,EventArgse)
{
this.textBo
x1.Text =
""; input
+= "3";
this.textBo
x1.Text+=in
put;
}
privatevoidbutton4_Click(objectsender,EventArgse)
{
this.textBo
x1.Text =
""; input
+= "4";
this.textBo
x1.Text+=in
put;
}
privatevoidbutton5_Click(objectsender,EventArgse)
{
this.textBo
x1.Text =
""; input
+= "5";
this.textBo
x1.Text+=in
put;
}
privatevoidbutton6_Click(objectsender,EventArgse)
{
this.textBo
x1.Text =
""; input
+= "6";
this.textBo
x1.Text+=in
put;
}
privatevoidbutton7_Click(objectsender,EventArgse)
{
this.textBo
x1.Text =
""; input
+= "7";
this.textBo
x1.Text+=in
put;
}
privatevoidbutton8_Click(objectsender,EventArgse)
{
this.textBo
x1.Text =
""; input
+= "8";
this.textBo
x1.Text+=in
put;
}
privatevoidbutton9_Click(objectsender,EventArgse)
{
this.textBo
x1.Text =
""; input
+= "9";
this.textBo
x1.Text+=in
put;
}

privatevoidbutton10_Click(objectsender,EventArgse)
{
this.textBo
x1.Text =
""; input
+= "0";
this.textBo
x1.Text+=in
put;
}
privatevoidbutton11_Click(objectsender,EventArgse)
{
input+=".";
}
privatevoidbutton12_Click(objectsender,EventArgse)
{
operand1
= input;
operatio
n = '*';
input=st
ring.Emp
ty;
}
privatevoidbutton13_Click(objectsender,EventArgse)
{
operand1
= input;
operatio
n = '/';
input=st
ring.Emp
ty;
}
privatevoidbutton14_Click(objectsender,EventArgse)
{
operand1
= input;
operatio
n = '-';
input=st
ring.Emp
ty;
}
privatevoidbutton15_Click(objectsender,EventArgse)
{
operand1
= input;
operatio
n = '+';
input=st
ring.Emp
ty;
}
privatevoidbutton16_Click(objectsender,EventArgse)
{
operand2 =
input;
doublenum1,nu
m2;
double.TryParse(operan 1, out num1);
double.TryParse(operand 2,outnum2);

if(operation=='+')
{
result = num1 +
num2;
textBox1.Text=resu
lt.ToString();
}
elseif(operation=='-')
{
result = num1 -
num2;
textBox1.Text=resu
lt.ToString();
}
elseif(operation=='*')
{
result = num1 *
num2;
textBox1.Text=resu
lt.ToString();
}
elseif(operation=='/')
{
if(num2!=0)
{
result = num1 /
num2;
textBox1.Text=resu
lt.ToString();
}
else
{
textBox1.Text="ERRORDIVBYZERO";
}
}}

privatevoidbutton17_Click(objectsender,EventArgse)
{
this.textBox1.Text = "";
this.input =
string.Empty;
this.operand1 =
string.Empty;
this.operand2=string.Empt
y;
}
Q17. WAP for Tic Tack Toe game using C# Window Based Application.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Csharp_TIC_TAC_TOE :
Form {
public Csharp_TIC_TAC_TOE()
{
InitializeComponent();
}

private void Csharp_TIC_TAC_TOE_Load(object sender, EventArgs e)


{

add action to all buttons inside panel2 foreach(Control c in panel2.Controls)


{
if(c is Button)
{
c.Click += new System.EventHandler(btn_click);
}
}
}
int XorO = 0;
// create button action
public void btn_click(object sender, EventArgs e)
{
Button btn = (Button)sender;
if (btn.Text.Equals(""))// we will clear text from buttons later
{
if(XorO % 2 == 0)
{
btn.Text = "X";
btn.ForeColor = Color.Blue;
label1.Text = "O turn now";
getTheWinner();
}else
{
btn.Text = "O";
btn.ForeColor = Color.Red;
label1.Text = "X turn now";
getTheWinner();
} XorO+
+;
}
}
bool win = false;
get the winner function public void getTheWinner()
{
if(!button1.Text.Equals("") && button1.Text.Equals(button2.Text) &&
button1.Text.Equals(button3.Text))
{
winEffect(button1, button2, button3);

win = true;

if (!button4.Text.Equals("") && button4.Text.Equals(button5.Text) &&


button4.Text.Equals(button6.Text))

{
winEffect(button4, button5, button6);

win = true;

if (!button7.Text.Equals("") && button7.Text.Equals(button8.Text) &&


button7.Text.Equals(button9.Text))

winEffect(button7, button8, button9);

win = true;

if (!button1.Text.Equals("") && button1.Text.Equals(button4.Text) &&


button1.Text.Equals(button7.Text))

winEffect(button1, button4, button7);

win = true;

if (!button2.Text.Equals("") && button2.Text.Equals(button5.Text) &&


button2.Text.Equals(button8.Text))

winEffect(button2, button5, button8);

win = true;

if (!button3.Text.Equals("") && button3.Text.Equals(button6.Text) &&


button3.Text.Equals(button9.Text))

winEffect(button3, button6, button9);

win = true;

}
if (!button1.Text.Equals("") && button1.Text.Equals(button5.Text) &&
button1.Text.Equals(button9.Text))

winEffect(button1, button5, button9);

win = true;

if (!button3.Text.Equals("") && button3.Text.Equals(button5.Text) &&


button3.Text.Equals(button7.Text))

winEffect(button3, button5, button7);


win = true;

if no one win

if all buttons are not empty

we can but 1 char in a button "X or O"

we have 9 buttons

mean 9 char in length if(AllBtnLength() == 9 && win == false)

label1.Text = "No Winner";

get all button text length function -> return int public int AllBtnLength()

int allTextButtonsLength = 0; foreach (Control c in panel2.Controls)

if (c is Button)
{

allTextButtonsLength += c.Text.Length;

return allTextButtonsLength;

win effect function to change buttons

background color + foreColor when one player win public void winEffect(Button b1, Button b2,
Button b3)

b1.BackColor = Color.Green;

b2.BackColor = Color.Green;

b3.BackColor = Color.Green;

b1.ForeColor = Color.White;

b2.ForeColor = Color.White;

b3.ForeColor = Color.White;

label1.Text = b1.Text + " Win";

}
// new partie button

private void buttonPartie_Click(object sender, EventArgs e)

XorO = 0;

win = false;

label1.Text = "Play";

foreach (Control c in panel2.Controls)


{

if (c is Button)

c.Text = "";

c.BackColor = Color.White;

}
Q18.WAP for Traffic Light Simulation in C# using Windows Application.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace traffic_lights
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{
timer1.Interval = 1000; //1 sec

int counter = 0;
private void timer1_Tick(object sender, EventArgs e)
{
counter++;
if(counter<10)
{
pictureBox1.ImageLocation = "D:\\images\\green.png";
pictureBox2.ImageLocation = "D:\\images\\walker-red.png";
}
else if(counter<13)
{
pictureBox1.ImageLocation = "D:\\images\\yellow.png";
pictureBox2.ImageLocation = "D:\\images\\walker-red.png";
}
else if(counter<20)
{
pictureBox1.ImageLocation = "D:\\images\\red.png";
pictureBox2.ImageLocation = "D:\\images\\walker-green.png";
}

if(counter==20)
{
counter = 0;
}
}

private void button1_Click(object sender, EventArgs e)


{
timer1.Start();
}
}
}

Q19.Create a Window based Application for Online Billing


System.
ANS:-
Coding Form 1:
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 Suigas
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
if (textBox2.Text == "12345")
{
Form2 f2 = new Form2();
f2.Show();
Hide();
}

private void textBox1_TextChanged(object sender, EventArgs e)


{
}

private void Form1_Load(object sender, EventArgs e)


{

}
}
}

Coding Form 2:
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 Suigas
{
public partial class Form2 : Form
{
public static string name, type, address;
public static double cunit, punit, conUnit, prsUnit, ttlbill, mtrno, units;

public Form2()
{
InitializeComponent();
}

private void Form2_Load(object sender, EventArgs e)


{

private void button1_Click(object sender, EventArgs e)


{
name = textBox1.Text;
mtrno =
(Convert.ToDouble(textBox2.Text));
address = textBox3.Text;
punit =
(Convert.ToDouble(textBox4.Text)); cunit
= (Convert.ToDouble(textBox5.Text)); type
= textBox6.Text;
conUnit = punit - cunit;

if ((type == "commercial") || (type == "Commercial"))


{
prsUnit = 8.0;
conUnit = cunit - punit;
ttlbill = prsUnit * conUnit;
}
else
{
prsUnit = 4.0;
conUnit = cunit - punit;
ttlbill = prsUnit * conUnit;
}

Form3 f3 = new Form3();


f3.Show();
Hide();

private void textBox1_TextChanged(object sender, EventArgs e)


{
}
}
}

Coding Form 3:
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 Suigas
{
public partial class Form3 : Form
{
public static double m, pc, amt;
public static string t;
public static string nme, ad;

public Form3()
{
InitializeComponent();
}

private void Form3_Load(object sender, EventArgs e)


{

nme = Form2.name;
label1.Text = nme.ToString();

ad = Form2.address;
label2.Text = ad.ToString();

m = Form2.mtrno;
label3.Text = m.ToString
();

pc = Form2.conUnit;
label4.Text = pc.ToString();

t = Form2.type;
label5.Text =
t.ToString();

amt = Form2.ttlbill;
label6.Text = amt.ToString();
}

private void label1_Click(object sender, EventArgs e)


{

private void label12_Click(object sender, EventArgs e)


{

}
}
}
Q20.WAP to create a Student Registration form and Connect MS
Access Database to C# Windows Form Application
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.Sql;
using System.Data.OleDb;
using System.Data.SqlClient;

namespace login_form
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection();
public Form1()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=KRISHNA-PC\\SQLEXPRESS;Initial
Catalog=STUDENT;Integrated Security=True";

InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{
// TODO: This line of code loads data into the 'sTUDENTDataSet.login' table. You
can move, or remove it, as needed.
//this.loginTableAdapter.Fill(this.sTUDENTDataSet.login);
SqlConnection con = new SqlConnection("Data Source=KRISHNA-
PC\\SQLEXPRESS;Initial Catalog=STUDENT;Integrated Security=True");
con.Open();

{
}
}

private void button1_Click(object sender, EventArgs e)


{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=KRISHNA-PC\\SQLEXPRESS;Initial
Catalog=STUDENT;Integrated Security=True";
con.Open();
string userid = textBox1.Text;
string password = textBox2.Text;
SqlCommand cmd = new SqlCommand("select userid,password from login where
userid='" + textBox1.Text + "'and password='" + text Box2.Text + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
MessageBox.Show("Login sucess Welcome to Homepage
http://krishnasinghprogramming.nlogspot.com");

System.Diagnostics.Process.Start("http://krishnasinghprogramming.blogspot.com");
}
else
{
MessageBox.Show("Invalid Login please check username and password");
}
con.Close();
}

private void button2_Click(object sender, EventArgs e)


{
Application.Exit();

}
}
}

Вам также может понравиться