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

CPL Assignment 1

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

CPL Assignment 1

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

ASSIGNMENT # 01

COMPUTER PROGRAMMING LAB

NAME: MUHAMMAD ANAS


ENROLLMENT NO: 02-134242-068
BSCS 1-B

SUBMITTED TO: MISS MEHWISH SALEEM


CPL: ASSIGNMENT # 01 | Muhammad Anas

COMPUTER PROGRAMMING LAB


ASSIGNMENT # 01
TASK 1:-
Install Visual C++ and attach proper screenshots to Lab File.

Solution:-
1. Run the setup file. You will see the following GUI:

To change the download location

Check Desktop development with C++ and click on Install. Make sure you have enough
space in hard disk, if not then click on Change and then change the location.
2. After installation is completed, you will see the following window:

Click on Create a new project.

1
CPL: ASSIGNMENT # 01 | Muhammad Anas

3. After clicking on Create a new project, you will see the recent projects and a list of
templates for the languages you have installed in the beginning.

Click on Empty Project with C++ label on it and click Next.

4. Now you will see the following window for setting up the name and location for
your new Project.

For now, we are creating our Project with the name LAB. After entering the name, click on
Create.

2
CPL: ASSIGNMENT # 01 | Muhammad Anas

5. Now the blank project file will appear on your screen like this:

6. Now to create a new source file, right click on Source Files in Solution Explorer tab,
then hover on Add and then click on New Item…

3
CPL: ASSIGNMENT # 01 | Muhammad Anas

7. Now enter the name for your source file. For now, we are entering the name LAB.
Then click on Add.

8. Now an editor will appear on your screen. Write code in it and then click on
Local Windows Debugger to run the code.

4
CPL: ASSIGNMENT # 01 | Muhammad Anas

9. You will now see the output like this:

TASK 2:-
Draw a flowchart & write a C++ program to store statement record such as (Name,
Age, Grade and CGPA).

Solution:-
• Flowchart:-

Start

Input
Name, Age,
Grade,
CGPA

Store the Data

Output the
stored data

Stop

5
CPL: ASSIGNMENT # 01 | Muhammad Anas

• Program:-

• Output:-

• Explanation:-
We solved this task by taking user’s name, age, CGPA and grade as input and
storing the information in variables of the specified data type. We used following
data types for the specified purposes:

string Name, Grade


int Age
float CGPA

6
CPL: ASSIGNMENT # 01 | Muhammad Anas

We used the built-in function cin to take input and cout to give output. We
also used the function getline because it helps us to store multiple words in a
string. Furthermore, we used manipulator endl which purpose is to move to the
next line and it helps to make the output prettier.
We added header file <iostream> which contains the functions cin and cout,
and <string> which allow us to use strings. We also used namespace std which
contains all the standard functions of C++, so we may not need to write std:: with
each function.

TASK 3:-
Draw a flowchart and write a C++ program to read student’s three grade, calculate
the average of the grade, and then display the average grade.

Solution:-
• Flowchart:-

Start

Input Grade
1, Grade 2,
Grade 3

Calculate Average
(Grade 1 + Grade
2 + Grade 3)/3

Display
Average

Stop

7
CPL: ASSIGNMENT # 01 | Muhammad Anas

• Program:-

• Output:-

8
CPL: ASSIGNMENT # 01 | Muhammad Anas

• Explanation:-
We solved this task by taking three grades as input from the user, calculating
their average, and displaying the result. We used the following data types for the
specified purposes:
double: Used for grade1, grade2, grade3, and average to handle decimal
values accurately, especially when calculating the average.
We used the built-in function cin to take input and cout to give output. The
cin function was used to read the grades entered by the user, and cout was used
to display the calculated average grade.
The average was calculated using the formula (grade1 + grade2 + grade3) /
3, which adds the three grades and divides the sum by 3 to find the mean value.
Additionally, we used the manipulator endl, which moves the cursor to the
next line, helping to format the output neatly.
We included the header file <iostream>, which provides the functionality of
cin and cout. We also used namespace std to avoid writing std:: before every
standard function, making the code cleaner and easier to read.

TASK 4:-
Write program & draw a flowchart that reads the height, length, and width of the
rectangular box, Calculates and displays the volume.

Solution:-
• Flowchart:-

Start

Input
Height,
Length,
Width

Volume = Height *
Length * Width

Display
Volume

9
Stop
CPL: ASSIGNMENT # 01 | Muhammad Anas

• Program:-

• Output:-

• Explanation:-
We solved this task by taking three sides of a rectangular box as input from
the user, calculating their volume, and displaying the result. We used double data
type to handle decimal values accurately, especially when calculating the volume.
The formula used for volume is height * length * width. Rest of the components of
code are same as used earlier.

10
CPL: ASSIGNMENT # 01 | Muhammad Anas

TASK 5:-
Write a program to read the salary of an employee and prints particular designation
of the concern person for example Manager salary = 200k, Supervisor = 150k and
Technician = 80k.
Solution:-
• Flowchart:-

Start

Input Salary

Print
If Salary >=
Yes Designation
200000
: Manager

No

Print
If Salary >=
Yes Designation
150000
: Supervisor

No

Print
If Salary >=
Yes Designation
80000
: Technician

No

Print
Designation
: Unknown

Stop

11
CPL: ASSIGNMENT # 01 | Muhammad Anas

• Program:-

• Output:-

• Explanation:-
In the given output, the salary being input is falling in the category of
Technician, so Technician is being print based on the if else conditional statements.

Basically, we have taken salary as an input from the user through double
data type and then we used if else conditional statements to make decision if the
salary lies in any of the given categories.

THE END

12

You might also like