CMSC104 Fall 2010
Programming Project 3
GPA Calculator
Out: Friday, November 26, 2010
Due Date: Thursday, December 9, 2010 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 points 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 3 credit and one 4 credit course and received 2 A's, your GPA for that semester would be:
3 credits * 4 points = 12 quality points 4 credits * 4 points = 16 quality points 28 total quality points / 7 total credits = 4.000 GPA
So for each course, you just calculate the quality points for that course and add those points to the total quality points. You should also add the 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 name, number of credits and grade for each course, one course at a time. The user should enter "end" as the name of the course to end the input phase. So "end" 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. You should print the explanation using an alert(). The function should not return anything. -
function GetValidNumberInput(promptString, lowerNum, upperNum){}
- This function takes three arguments: the string that contains the prompt you want to print when prompting the user to enter the credits, the lowerbound for the number, and the upper bound for number. You should ask the user for the number. Then the function should error check to make sure the input is a number between lowerNum and upperNum inclusive. The function should return the valid number. The function should be general and not mention anything about credits. -
function GenerateGPAReport(totalCredits, totalQualityPoints){}
- This function should display the gpa 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, totalQualityPoints){}
- This function simply performs the GPA calcuation. It should return the calculated GPA. -
function ConvertGradeToPoints(grade){}
- This function converts a letter grade into its corresponding point value. Points should be assigned based on the following: 4 for an A, 3 for B, 2 for a C, 1 for a D and 0 for an F. The function takes the letter grade as its argument and returns the corresponding point value.
- You should use the GetValidNumberInput() function to get the number of credits from the user. For this project, you should use 1 as the minimum number of credits and 4 as the maximum.
- You do not have to error check the grades. You can assume the user will only type A, B, C, D, or F.
- You do not have to error check the course name or the semester.
- An internal style sheet can add up to 5 points extra credit for presentation.
-
Screenshots
Explanation of program
Getting semester from user
Getting course name from user
Getting number of credits from user
User entering invalid credits
Invalid credits error message
Getting grade from user
Entering sentinel value
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.