CS100 Computational Problem Solving
Fall 2020-21
Section 1 Wednesday, 21 Oct 2020
Lab# 05: 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_Lab5_TAname and submit it on LMS (Assignments>Lab5)
5. Lab ends at 5:50 pm and the submission tab closes at the same time
Task1 Total
15
Task2 Total
20
Task3 Total
30
Task4 Total
35
Total Marks: 100
Let’s Begin
Task 1: [15 marks]
Take an integer as input from the user and print “Its Even” in case the integer is even and “Its Odd”
in case the integer is odd as shown below:
________________________________________________________________________________
Task 2: [20 marks]
Write a program which asks the user to enter the grade that they got in any course and the
program will output the corresponding GPA for it as per the below standards. The GPA decreases
by 0.33 for each change.
A+ is equal to 4.0
A is also equal to 4.0
A- is equal to 3.67
B+ is equal to 3.33
B is equal to 3.0
B- is equal to 2.67
C+ is equal to 2.33
C is equal to 2.0
F is Course Failure
In case of F, output “You have failed”
Sample Output:
Enter the grade in your course: B
GPA: 2.67
Enter the grade in your course: F
You have failed
________________________________________________________________________________
Task 3: [30 marks]
You are going to the local grocery store to buy eggs and bread. The store offers a 10% discount on
your total bill if you are a student. Write a program that,
1. Takes in quantity and price of both eggs and bread.
2. Takes in the user’s budget.
3. Asks whether or not he/she is a student and applies discount accordingly.
4. Calculate the total cost.
5. Prints the budget, cost and whether the cost exceeds the budget or not.
Sample output:
________________________________________________________________________________
Task 4: [35 marks]
Suppose following are the rates of electricity set by the local supplier:
For first 50 units, Rs. 0.50/unit
For next 100 units, Rs. 0.75/unit
For next 100 units, Rs. 1.20/unit
For unit above 250, Rs. 1.50/unit
Write a program which
1. Takes the consumed units of electricity by a user as input.
2. Identifies the correct condition.
3. Calculates the bill given the above conditions.
4. Prints the units and total bill on the screen as below:
(NOTE: Nested if-statements are not allowed. Use “if, else-if, else” structure.)
________________________________________________________________________________