Академический Документы
Профессиональный Документы
Культура Документы
Dot NET
Framework
(CSL0662)
Session: 2020-2021
Submitted By Submitted
To
MANJIT KUMAR Mr. RAHUL YADAV
(BETN1CS1703 ) Assistant Professor
0
Lab Report
INDEX
using System;
}
Output:-
Enter a number: 10
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;
double rl,phy,che,ca,total;
double per;
string nm,div;
Console.Write("\n\n");
Console.Write("
");
Console.Write("\n\n");
Console.Write("Input the Roll Number of the student :");
rl = Convert.ToInt32(Console.ReadLine());
nm = Console.ReadLine();
phy= Convert.ToInt32(Console.ReadLine());
che = Convert.ToInt32(Console.ReadLine());
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";
Output:-
Calculate the total, percentage and division to take marks of three subjects:
Roll No : 10
Marks in Physics : 50
Marks in Chemistry : 46
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
double tax;
else
}
Console.WriteLine("Tax is {0:C}", tax);
Console.ReadKey();
using System;
class GFG
// Iterative function to
int rev_num = 0;
while(num > 0)
return rev_num;
}
// Driver code
+ reversDigits(num));
OUTPUT:-2654
using System;
public class Exercise12
int i,j,rows,k=1;
Console.Write("\n\n");
Console.Write(" ");
Console.Write("\n\n");
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:
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
using System;
class GFG
/* function to check if
x2 * (y3 - y1) +
x3 * (y1 - y2);
if (a == 0)
Console.Write("Yes");
else
Console.Write("No");
// Driver code
int x1 = 1, x2 = 1, x3 = 1,
y1 = 1, y2 = 4, y3 = 5;
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 Should Improve His Speed.");
if (time > 5)
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;
double r,per_cir;
double PI = 3.14;
r = Convert.ToDouble(Console.ReadLine());
per_cir = 2 * PI * r;
Console.Read();
Output:-
using System;
namespace ProgrammingGuide
// Class definition.
// Class members.
//
// Property.
// Method.
// Instance Constructor.
public CustomClass()
Number = 0;
}
}
// Another class definition that contains Main, the program entry point.
class Program
custClass.Number = 27;
output:
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);
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.
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();
}
win = true;
{
winEffect(button4, button5, button6);
win = true;
win = true;
win = true;
win = true;
win = true;
}
if (!button1.Text.Equals("") && button1.Text.Equals(button5.Text) &&
button1.Text.Equals(button9.Text))
win = true;
if no one win
we have 9 buttons
get all button text length function -> return int public int AllBtnLength()
if (c is Button)
{
allTextButtonsLength += c.Text.Length;
return allTextButtonsLength;
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;
}
// new partie button
XorO = 0;
win = false;
label1.Text = "Play";
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();
}
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;
}
}
namespace Suigas
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
}
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();
}
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();
}
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();
}
}
}
}
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();
}
{
}
}
System.Diagnostics.Process.Start("http://krishnasinghprogramming.blogspot.com");
}
else
{
MessageBox.Show("Invalid Login please check username and password");
}
con.Close();
}
}
}
}