0% found this document useful (0 votes)
67 views

Bahria University,: Karachi Campus

1) The document describes 6 tasks for a lab experiment on variables and arithmetic operations in C# programming. 2) The tasks include writing programs to display personal information, a marks sheet, calculate expressions, temperature conversion, area of a circle, and evaluating a complex expression. 3) For each task, the document provides the objective, sample code solutions, and expected output.

Uploaded by

Zain Rizvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views

Bahria University,: Karachi Campus

1) The document describes 6 tasks for a lab experiment on variables and arithmetic operations in C# programming. 2) The tasks include writing programs to display personal information, a marks sheet, calculate expressions, temperature conversion, area of a circle, and evaluating a complex expression. 3) For each task, the document provides the objective, sample code solutions, and expected output.

Uploaded by

Zain Rizvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

[Lab no.

2] [Computer Programming]
[Variable and Arithmetic
operation]

Bahria University,
Karachi Campus

LAB EXPERIMENT NO.


02
LIST OF TASKS
TASK NO OBJECTIVE
1 Write a program to display your personal information. (Name, age, address,
father’s name, college name, NIC, phone number etc. ) and display your
marks sheet. ((Use Escape Sequences to create a formatted Output according
to the given image).
2 Write a program to display your inter/ matric marks sheet
3 Write a C# program that displays the results of the expressions:
4 Calculate the temperature in Celsius using integer values.
5 Calculate the area of Circle.
6 Display the result of the expression: ((( a + b) * (c * e *d)) – e)/f

Submitted On:
03/10/2020
(Date: DD/MM/YY)
[Lab no.2] [Computer Programming]
[Variable and Arithmetic
operation]

Task No. 1: Write a program to display your personal information. (Name, age, address,
father’s name, college name, NIC, phone number etc. ) and display your marks sheet.
((Use Escape Sequences to create a formatted Output according to the given image).
Solution:
public void t1() {
String name, lname, Fname, email, edu;
int age, Phone;

Console.Write("First Name :");


name = Console.ReadLine();
Console.Write("Last Name: ");
lname = Console.ReadLine();
Console.Write("Father Name: ");
Fname = Console.ReadLine();
Console.Write("Age: ");
age = int.Parse(Console.ReadLine());
Console.Write("Email: ");
email = Console.ReadLine();
Console.Write("Education: ");
edu = Console.ReadLine();
Console.WriteLine("\n\n\n");
Console.WriteLine("___________________________________________");
Console.WriteLine("First Name :" + name);
Console.WriteLine("Last Name: " + lname);
// lname = Console.ReadLine();
Console.WriteLine("Father Name: " + Fname);
//Fname = Console.ReadLine();
Console.WriteLine("Age: " + age);
//age = int.Parse(Console.ReadLine());
Console.WriteLine("Email: " + email);
//email = Console.ReadLine();
Console.WriteLine("Education: " + edu);
//edu = Console.ReadLine();
Console.ReadLine();

Output:
[Lab no.2] [Computer Programming]
[Variable and Arithmetic
operation]

Task No. 2: Write a program to display your inter/ matric marks sheet

Solution:
class task2
{
public void t2()
{
Console.WriteLine("***********MARK SHEET***********");
Console.WriteLine("\n\n\n Enter Marks Subject wise \n");
double e, u, c, p, m, com;
Console.WriteLine("English Marks:");
e = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Urdu Marks:");
u = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Chemistry Marks:");
c = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Physics Marks:");
p = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Maths Marks");
m = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Computer Marks");
com= Convert.ToDouble(Console.ReadLine());
double sum = e + u + c + p + m + com;
double per = (sum / 600.0) * 100.0;
Console.WriteLine("-------------------------------MARKSHEET---------------------------");
Console.WriteLine("English Marks:" +e);
Console.WriteLine("Urdu Marks: "+u);
Console.WriteLine("Chemistry Marks: "+c);
Console.WriteLine("Physics Marks: "+p);
Console.WriteLine("Maths Marks "+m);
Console.WriteLine("Computer Marks: "+com);
Console.WriteLine("------------------------------------------------------------------");
Console.WriteLine("\n\n Total Marks: " +sum);
Console.WriteLine("Percentage: " + per + "%");
Console.WriteLine("------------------------------------------------------------------");
}}

Output:
[Lab no.2] [Computer Programming]
[Variable and Arithmetic
operation]

2. Task No. 3: Write a C# program that displays the results of the expressions:

 3.0*5.0
 7.1*8.3-2.2
 3.2/ (6.1*5)
 15/4
 15%4
 5*3-(6*4).

Solution:
public void t3()
{
double eq1 = 3.0 * 5.0;
double eq2 = (7.1 * 8.3) - 2.2;
double eq3 = 3.2 / (6.1 * 5);
double eq4 = 15 / 4;
double eq5 = 15 % 4;
double eq6 = 5 * 3 - (6 * 4);
Console.WriteLine("3.0 * 5.0=" +eq1);
Console.WriteLine("(7.1 * 8.3) - 2.2=" + eq2);
Console.WriteLine("3.2 / (6.1 * 5) =" + eq3);
Console.WriteLine("15 / 4 ="+eq4);
Console.WriteLine("15 % 4 =" + eq5);
Console.WriteLine("5 * 3 - (6 * 4) =" + eq6);
}

Output:
[Lab no.2] [Computer Programming]
[Variable and Arithmetic
operation]

Task No. 4: Calculate the temperature in Celsius using integer values.


C = 5/9 * (F – 32)

Solution:
class Task4
{
public void task4() {
Console.WriteLine("*************Temperature Calculator*************");
Console.Write("Enter Temperature in Farhenheit :");
double f, c;
f = Convert.ToDouble(Console.ReadLine());
c = 5.0 / 9.0 * (f - 32.0);
Console.WriteLine("\n\n\n\n");
Console.WriteLine("************************************************");
Console.WriteLine("The Calculated Temperature is :" +c);
Console.WriteLine("************************************************");
}
}

Output:

Task No. 5: Calculate the area of Circle.


Solution:
class Task5
{
public void t5()
{

Console.Write("Enter radius to Calculate :");


double r = Convert.ToDouble(Console.ReadLine());
double area = 3.14 * r * r;
Console.WriteLine("Area Of Circle is :" + area);

}
[Lab no.2] [Computer Programming]
[Variable and Arithmetic
operation]

Output:

Task No. 6: Display the result of the expression: ((( a + b) * (c * e * d)) – e)/f

Solution:
class Task6
{
public void t6()
{
double a, b, c, d, e, f;
Console.Write("Enter Value of a:");
a = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter Value of b:");
b = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter Value of c:");
c = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter Value of d:");
d = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter Value of e:");
e = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter Value of f:");
f = Convert.ToDouble(Console.ReadLine());

double x = a + b, y = c * d * e;
double mul = x * y;
double sub = mul - e;

double result= sub/f;


Console.Write("((a+b)*(c*d*e)-e)/f= "+result);
}
}

Output:
[Lab no.2] [Computer Programming]
[Variable and Arithmetic
operation]

You might also like