CS 115 Lab 5 Grade Point Average
100 Points
Due Date: Monday March 1 by the end of the lab session
Educational goals of this lab - verify that every student can
- understand and write if statements
- understand for loops
- use a boolean operator
- use an accumulator
Use the Canvas link to submit your work.
INSTRUCTIONS:
(100 points) Description of the Problem:
- You want to calculate a student's GPA (grade point average) for
a semester's worth of classes.
The user input is:
first how many classes they took for the semester (integer of course),
then the letter grade and number of credit hours for each class they took.
Sample:
How many classes: 4
Grade? A
Credit hours? 5
Grade? B
Credit hours? 3.0
Grade? A
Credit hours? 3
Grade? C
Credit hours? 4.0
Total Quality Points 49.00
Total Credit Hours 15.00
Grade Point Average = 3.27
Another Sample:
How many classes: 3
Grade? A
Credit hours? 4
Grade? A
Credit hours? 4
Grade? A
Credit hours? 5
Total Quality Points 52.00
Total Credit Hours 13.00
Grade Point Average = 4.00
Dean's List
Sample run with invalid grade
How many classes: 1
Grade? P
Credit hours? 3
Invalid grade, quality points =0
Total Quality Points 0.00
Total Credit Hours 3.00
Grade Point Average = 0.00
Academic Probation
- The algorithm for calculating a GPA is to translate each letter grade to
a number of quality points (A=4, B=3, C=2, D=1, E=0) and multiply each grade
by the number of credit hours for that class. The total of these products
is divided by the total number of credit hours. So the sample run above
would calculate as 4*5 + 3*3 + 3*4 + 4*2 = 49 for quality points and
5 + 3 + 3 + 4 = 15.0 credit hours. 49.0/15.0 = 3.27 (formatted to 2 places).
- Note that classes CAN have a float number of credit hours!
- Special Cases: If the student has a GPA greater than 3.5
and 12 hours or more, they are on the Dean's List. If they have a GPA of
less than 2.0, they are on Academic Probation.
- The program should handle upper or lower case letters for the grades.
Do this without using any string functions (like .lower). Use a boolean or operator.
If the grade entered is not ABCDE or abcde, it's invalid - show a message about it
and use 0 for the quality points.
- Use augmented operators as often as possible.
- Protect your program from division by zero!
(21 points) Problem #1: Complete a test plan.
- These tests are not exhaustive. There is not enough time for that.
Note that this plan has cases where the loop executes exactly 1 time,
zero times and more than 1 time.
These cases test invalid grade input at least once.
They test test boundary cases - what's the highest and lowest GPA?
They test upper case and lower case letter grades.
I describe this because soon you will have to create the test plans from scratch!
-
Description | Inputs (numgrades, letter, hrs, ...) | Expected output |
| | Total QP | Total Cr | GPA | Msg |
Normal (All A's) | 3,A,3,A,3,A,3 | 36.09.04.0 | | | |
Normal (One of each grade) | 5,A,3,B,2,D,4,C,3,E,1 | _____A._____ |
Normal (Dean's List) | 4,A,4.5,B,3,A,4,A,2 | _____B._____ |
Normal (Probation) | 4,B,2,C,4,D,3,D,1 | _____C._____ |
Normal (Lowercase grades) | 3,a,3,b,3,c,3 | _____D._____ |
Normal (one grade) | 1,C,4 | _____E._____ |
Error (Invalid grade) | 2,Q,3,B,3 | _____F._____ |
Boundary case (no grades) | 0 | _____G._____ |
- Put these test cases as a multi-line comment at the bottom of the program you write for
Problem #3.
(24 points) Problem #2: Design
- Copy and paste this design into a python file.
Fill in the blanks in the design so that it solves the problem
and shows the control structures (loop and ifs) and
what they are supposed to do.
Prolog including 3 P's and Team members' names who are present
initialize ______________ and _____________
ask user for ________________
for each class (loop control structure)
input ___________ and _______________
convert letter grade to quality points using ____________ (control structure)
add quality points * credit hours to qptot
add credit hours to _________
if crtot is ____________,
divide qptot by crtot to get gpa
otherwise gpa is a 0
output _______, ______ and gpa (2 decimal places)
check gpa for special cases: probation and ________ using ____ (control structures)
(55 points) Problem #3: Complete the program.
- Implement the program starting with the .py file you have
written the design in. The design steps are the comments.
- Use the Minimum number of if's, comparisons, possible.
Make sure your branches contain ONLY the code that is needed.
If you see repeated code in each branch, take it OUT and do it ONE time!
- All the usual things - prolog, design, main function.
- Run your test cases to make sure they run! You do not have to capture them.
- Submit your finished program with the Canvas link.