You are on page 1of 24

Bahria University,

Karachi Campus

COURSE: CSC-113 COMPUTER PROGRAMMING


TERM: FALL 2019, CLASS: BSE- 1 (A)

Submitted By:

_____Zain Rizvi________________________46064________
(Name) (Reg. No.)
Submitted To:

Engr. Adnan ur rehman/ Engr. Ramsha Mashood


Signed Remarks: Score:

INDEX
SNO DATE LAB LAB OBJECTIVE SIGN
NO

1 03/oct/2020 1 Programming Basic

2 11/oct/2020 2 Variable and Arithmetic operation

3 18/oct/2020 3 input and output


SNO DATE LAB LAB OBJECTIVE SIGN
NO
Bahria University,
Karachi Campus

LAB EXPERIMENT NO.


___01___
LIST OF TASKS
TASK NO OBJECTIVE
1 Write step how to install visual studio
2 Show the output of all examples mention in the lab
3 Debug the following program and write the values of n, sum and
m while debugging

Submitted On:
__3/10/2020__
(Date: DD/MM/YY)
[Lab no.1] [Computer Programming]
[Programming Basic]

Task No. 1: Write step how to install visual studio.


Solution:

The steps to download and install visual studio are as follows

1. Go to this link
https://www.visualstudio.com/downloads/
2. Download the visual studio exe file.
3. After the download finishes , you can click on the downloaded file to install. Visual
studio download some files.
4. In next screen,

5. Select ".Net desktop development"


6. Click install
7. Installation will start and installation will be completed.
[Lab no.1] [Computer Programming]
[Programming Basic]

Task No. 2: Show the output of all examples mention in the lab.
Solution:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lab_01_Examples
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}

Output:

Task No. 3.1: Debug the following program and write the values of n, sum and m while debugging

Solution:
using System;
public class SumExample
{
public static void Main(string[] args)
{
int n,sum=0,m;
Console.Write("Enter a number: ");
n= int.Parse(Console.ReadLine());
while(n>0)
[Lab no.1] [Computer Programming]
[Programming Basic]

m=n%10;
sum=sum+m;
n=n/10;
}
Console.Write("Sum is= "+sum);
}
}

Output:

Task No. 3.2: Debug the following program and write the values of n, sum and m while debugging

Solution:
using System;

public class SumExample

public static void Main(string[] args)

int age;
string name;
Console.WriteLine("Enter your name");
name = Console.ReadLine();
Console.WriteLine("Enter your age");
age = Convert.ToInt32(Console.ReadLine());
if (age >= 18)
{
Console.WriteLine("Hello " + name + "!" + "You can vote");
[Lab no.1] [Computer Programming]
[Programming Basic]

}
else {
Console.WriteLine("Hello " + name + "!" + " Sorry you can't vote");
}
Console.Read();
}

}
Output:
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:
11/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]

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:
Bahria University,
Karachi Campus

LAB EXPERIMENT NO.


____03___
LIST OF TASKS
TASK NO OBJECTIVE
1 Write a program which take two integer values from user and perform mathematical
operations(Addition, Subtraction, Multiplication and Division) on these two values.
2 Write a program to take personal information from user and display it.
3 Calculate the quadratic equation by using three user given integer variables.
4 Display the following results and take value of a, b, c, d, e, and f from user. ( ( ( b + 3 ) ^
( 4 a c) ) / d ) * ( ( ( a * c ) + ( b * d ) ) * f )
5 Write a program and print the output of first equation of the motion. For values take
input from user. (vf=vi+at)

Submitted On:
18/ oct /2020
(Date: DD/MM/YY)
[Lab no.3] [Computer Programming]
[input and output]
[Lab no.3] [Computer Programming]
[input and output]
[Lab no.3] [Computer Programming]
[input and output]
Task No. 1: Write a program which take two integer values from user and perform mathematical
operations(Addition, Subtraction, Multiplication and Division) on these two values.

Solution:
class Task1
{
public void t1() {
int num1, num2;
Console.WriteLine("**********TASK 1**********");
Console.WriteLine("Enter First number: ");
num1 =Convert.ToInt16( Console.ReadLine());
Console.WriteLine("Enter Second number: ");
num2 = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("**************************");
int add, sub, mul;
double div;
add = num1 + num2;
sub = num1 - num2;
mul = num2 * num1;
div = Convert.ToDouble(num1) / Convert.ToDouble(num2);
Console.WriteLine("**************************");
Console.WriteLine("Add = " + add);
Console.WriteLine("Subtract= "+sub);
Console.WriteLine("Multiply=" + mul);
Console.WriteLine("Divide=" + div);
Console.WriteLine("**************************");
}

Output:
[Lab no.3] [Computer Programming]
[input and output]
Task No. 2: Write a program to take personal information from user and display it.

Solution: class Task2


{
public void t2() {
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.3] [Computer Programming]
[input and output]
[Lab no.3] [Computer Programming]
[input and output]

Task No. 3: Calculate the quadratic equation by using three user given integer variables.

Solution:
public void t3() {
int a1, b1, c1;
Console.WriteLine("===============Task 3===============");
Console.WriteLine("Program To Calculate Quadratic Equation\n\n\n");
Console.WriteLine("Enter first num: ");
a1 = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Enter second num: ");
b1 = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Enter third num: ");
c1 = Convert.ToInt16(Console.ReadLine());

double a=a1, b=b1, c=c1;


double sol1;
sol1 = Math.Sqrt((b * b) - 4 * (a) * (c));
sol1 = -b + sol1;
sol1 = sol1 / (2 * a);

double sol2;
sol2 = Math.Sqrt((b * b) - 4 * (a) * (c));
sol2 = -b - sol2;
sol2 = sol2 / (2 * a);
Console.WriteLine("x=( " + sol2 +" , "+sol1+")");
Console.ReadKey();

// Console.WriteLine("Ans : " + sol1);


//Console.ReadKey();
}
}
}
Output:
[Lab no.3] [Computer Programming]
[input and output]
Task No. 4: Display the following results and take value of a, b, c, d, e, and f from user. ( (
( b + 3 ) ^ ( 4 a c) ) / d ) * ( ( ( a * c ) + ( b * d ) ) * f )

Solution:
public void t4() {
Console.WriteLine("=========Task 4=========");
double a, b, c, d, f,e;
Console.Write("Enter a Value:");
a = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter b Value:");
b = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter c Value:");
c = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter d Value:");
d = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter e Value:");
e = Convert.ToDouble(Console.ReadLine());

Console.Write("Enter f Value:");
f = Convert.ToDouble(Console.ReadLine());
double result1,result2;
result1 = b + 3;
result2 = 4 * a * c;
result1 = Math.Pow(result1, result2);
result1 = result1 / d;
double result3,result4;
result3 = a * c;
result4 = b * d;
result3 = result3 + result4;
result3 = result3 * f;
result1 = result1 + result3;
Console.Write("Calculated result is :" + result1);
}
}
}

Output:
[Lab no.3] [Computer Programming]
[input and output]
Task No. 5: Write a program and print the output of first equation of the motion. For
values take input from user. (vf=vi+at)

Solution:

class Task_5
{
public void t5() {

Console.WriteLine("************Code To control Final Velocity************\n\n\n");


double vi, a, t;
// Console.Write("*");
Console.Write("Enter Vi :");
vi = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter a :");
a = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter t :");
t = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("*******************************************************");
double Vf;
Vf = a * t;
Vf = Vf + vi;
Console.WriteLine("The caculated value of vf is : " + Vf);
Console.WriteLine("*******************************************************");

}
}
}

Output:

You might also like