You are on page 1of 5

CS100 Computational Problem Solving

Fall 2021-2022
Ayan Tabassum

Section 2 Friday 24th Sept

Lab# 03: Exercise

Lab Guidelines

1. You are allowed to perform/submit the lab only during the lab timings
2. Make sure you do not leave the lab without submitting your work on LMS
3. Copying/sharing code is strictly prohibited. Using any unfair means will lead to immediate
disqualification
4. Put all cpp files into a folder YourRollNo_Lab3_TAname and submit it on LMS
(Assignments>Lab3)
5. Lab ends at 8:50 pm and the submission tab closes at the same time

Task1 Total
20

Task2 Total
30

Task3 Total
30

Total Marks: 100 (80 + 20 for Viva)


Task 1 - Using cin [20 marks]

Write a program that asks for this class’s course code in the form of two letters and
three integers, and shows the course code.

It then asks for the number of instructors, teaching assistants and students in this
section, and shows the total number of people in the section.

Finally, it asks for your expected CGPA and shows that you’ll hopefully get it.

<You’re only allowed to use int, double and char datatypes>

Sample output:

Input first letter:


C

Input second letter:


S

Input first number:


1

Input second number:


0

Input third number:


0

*****************************
Your course is: CS100
*****************************

How many instructors are in your section:


1
How many Teaching Assistants are in your section:
8

How many students are in your section:


92

*****************************
Total number of people in the roster are: 101
*****************************

What do you expect your CGPA at the end of this year:


3.80

Hopefully you will get your CGPA of 3.8 at the end of this year!

__________________________________________________________________

Task 2 - Arithmetic Operators [30 marks]

A couple of teachers brought a bag of candies to be distributed among the children in a


class. One bag contains x candies and one class has y children. Since the teachers
want to be fair in the distribution of candies, they ask you to write a program which
takes the number of candies and children as well as price of one candy as input
(using cin) and shows how many candies each child gets and how many are left
over. They also ask you to calculate the total amount spent on candies and the
amount lost due to the candies that are left.
<Hint: mod (%) can be used to find the remainder in a division. E.g 7 % 2 = 1>

Please follow the sample output format below:

How many candies did you buy?


98

How many children are in the class?


21
What is the price of one candy? (in PKR)
16

*****************************
Each child gets 4 candies
There are 14 candies left.
Total amount spent on candies: PKR 1568
Amount lost due to candies that are left: PKR 224
*****************************

________________________________________________________________

Task 3 - Evaluating expressions [30 marks]

The quadratic formula is a widely used formula that is used to find the roots of a
quadratic equation.

Write a program that takes input the values of a, b and c. It then finds both of the roots
of the quadratic equation and stores them in variables root1 and root2, and displays
them accordingly.
<Hint1: In root1, write the formula with only the plus sign ‘-b + sqrt(....)...’. In root2, write
the formula with only the minus sign ‘-b - sqrt(....)...’.>
<Hint2: Find the square root by using the sqrt function , e.g ‘sqrt(4)’ outputs 2. Include
the ‘cmath’ library>

Please follow the sample output format below:

Enter the value of a:


1
Enter the value of b:
-1
Enter the value of c:
-6
The roots of the equation are: 3 and -2

You might also like