CMSC104, Fall 2007
Programming Project 3
GPA Calculator
Out: Tuesday, November 27, 2007
Due Date: Tuesday, December 4, 2007 before 11:59 p.m.
The Objective
This project is designed to give you practice writing your own functions in JavaScript.
The Task
This program will allow you to calculate your GPA for one semester. After receiving an explanation of the program and entering the semester, the student will be allowed to enter as many courses as he/she sees fit. The program must then calculate and display the GPA earned for that semester.
In order to produce the GPA, several calculations are needed. For each course, the number of credits, multiplied by the grade point earned in that class, results in a value known as quality points. To calculate the GPA, the total number of quality points for the semester is divided by the total number of credits taken that semester, exclusive of credits for courses taken with the Pass/Fail grading method. Your program should NOT handle Pass/Fail courses at all. The only acceptable grade points are in the range of 0 through 4, where 4 is an A, 3 a B, 2 a C, 1 a D and 0 an F. So, for example, if you took one 4 credit course and received a B, your GPA for that semester would be:
4 credits * 3 points = 12 quality points 12 total quality points / 4 total credits = 3.000 GPA
If there is more than one course, you just keep adding the quality points to the total points and credits to the total credits.
To begin the program , you should print a message to the user explaining what the program does. Then you should ask the user to enter the semester. After these initial steps, you should begin asking the user to enter the number of credits and grade points for each course, one course at a time. The user should enter a -1 as the number of credits to end the input phase. So -1 is the sentinel value for this exercise. At this point a report should be generated that shows the total number of credits taken, the total quality points earned, and the GPA for the semester.
Your program must generate all of the same information as shown in the sample output. You do not need to match the output exactly, however the GPA should be shown to three decimal places. You may also use the data shown here to test your program for accuracy.
More Details
- You are REQUIRED to use the following functions exactly as they are given:
-
function PrintExplanation(){}
- This function should display a description of the program to the user. It should let the user know the specific points values for each of the letter grades. You should print the explanation using an alert(). The function should not return anything. -
function GetValidInput(string, sentinel){}
- This function takes two arguments: the string that contains the prompt you want to print and the sentinel, which is -1 in this program. As long as the number the user enters is less than equal to 0 and not equal to the sentinel, it should continue to prompt for a new number. The function should return the valid number. -
function GetValidInt(string, min, max){}
- This function takes three arguments: the string that contains the prompt you want to print, the minimum value in the range and the maximum value in the range. As long as the number the user enters is less than the min or greater than the max, it should continue to prompt for a new number. The function should return the valid number. -
function GenerateGradeReport(semester, totalCredits, totalPoints){}
- This function should display the grade report to the user. You should use document.write() to produce the report. You will make a call to the function CalculateGPA() from within this function. The function should not return anything. -
function CalculateGPA(totalCredits, totalPoints){}
- This function simply performs the GPA calcuation. It should return the calculated GPA.
-
- Feel free to add any style you would like to the GPA Report.
Screenshots
Explanation of program
Getting semester from user
User attempting invalid credits
Error message for invalid credits
User entering valid credits
User attempting invalid points
Error message for invalid points
User entering valid points
User entering -1 to quit
The final GPA report below was produced with the following course input (credits/points): 4/3,4/4,3/2,3/3 and 3/2.
Final GPA report
Submitting the Program
You do not have to do anything to submit the program. It should be in your pub/www/cs104/proj3 directory.