Bahria University,: Karachi Campus
Bahria University,: Karachi Campus
2] [Computer Programming]
[Variable and Arithmetic
operation]
Bahria University,
Karachi Campus
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;
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]
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:
}
[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;
Output:
[Lab no.2] [Computer Programming]
[Variable and Arithmetic
operation]