1 CS 215 Fall 2017 Project 2: Grade Calculator Due October 9 @ midnight Version 2.1 Published 9/24 changes in Red [DUE DATE changed 10/3] Learning Objectives: - Developing a C++ program using the Procedure-Oriented Programming design paradigm. - Use of Functions - Use of Loops - Use of Decisions General Description: You are to write a program to assist a professor in entering scores and calculating the grades for a class of students. The program will first ask the user to enter general information about the class, including the number of tests, projects, labs and lecture attendance days so far for the semester. Next the program will process each student one at a time. The program asks the user to enter the student s name, or DONE to exit the program. For each student, the program will ask the user to enter the individual test, project, lab and attendance scores. It then calculates averages for the tests, projects, labs and attendance days entered, along with the overall percentage and letter grade. Finally, it prints a report for the student, then begins the next student. When the user enters DONE as the student name, no more student data is entered or processed. Instead, the program prints a report with the average overall percentage of the class, along with the name and overall percentage of the student with the highest percentage of all students entered. Structure Chart: this chart demonstrates the overall design that is to be used. Each box represents a function to be written. Specifications for each function are detailed below. A line between a higher-level function and a lower-level one indicates the higher-level function invokes the lower.
2 Specifications: Each function of the project is specified in detail below. Failure to follow the specifications, even if the program executes correctly, will result in deduction of points!. As always, if you would like to make a modification to the specifications, email the instructor and ask permission. You should use only the C++ language structures we have studied in class. In particular, do not use Classes or Arrays. Also, do not use any built-in C++ functions other than the following (again, you may ask for permission to use others): setw(), setprecision(), cin.ignore(), cin.getline(), to_string() printlogo: Prints a logo as shown in the examples below. Make up your own program name if you wish. Include your name in the logo. asknumber(): Given: - a question to ask the user - a maximum number Return: the valid number entered by the user. Prints the given question and allows the user to enter a number (which may have a decimal point). It should validate the user s input to be between zero and the maximum given, using the error message Invalid input. Enter a number between 0 and maximum The question should be left-justified and printed in a field width of 40. Example: when given Enter a score and a maximum of 4 Enter a score: -1 Invalid input. Enter a number between 0 and 4! Enter a score: 5 Invalid input. Enter a number between 0 and 4! Enter a score: 3.5 The 3.5 is returned. NOTE: when needed, use reserved words left and right for justification in a cout. cout << left << setw(10) << Num = << right setw(6) << 12.5; Prints: Num =...12.5 (where the dots are blanks) getclassnumbers(): Alters: the number of tests, projects, labs and attendance days. Invokes asknumber() with the following questions and maximums: Enter number of tests: 4 Enter number of projects: 5 Enter number of labs: 7 Enter number of attendance days: 50 getavg(): Given: the name of an item (ex: test, project, etc), the number of items, and the maximum score. Return: the average of the scores entered as a percentage. InvokingaskNumber() to get the individual scores, calculates a percentage of the scores entered based on the given maximum score. It should construct a prompt including the item number for each invocation of asknumber(). Example: given project, 3 and 50, it will invoke asknumber() 3 times with the prompt Enter item score n:
3 Some algebra will have to be done to correctly calculate the percentage. For example, projects are out of 50 points. But if someone has 3 projects, all 50 points, the percentage returned should be 100%, not 50%! Note: to concatenate an integer with a string, use the C++ built-in function to_string(). int age = 21; string name = Miguel ; string sentence = name + is age + to_string(age) +!\n ; cout << sentence; prints: Miguel is age 21! CalcPercentage(): Given: the test, project, lab and attendance averages Return: the calculated overall percentage Calculates the overall percentage using the following weights: Tests 40% Projects 30% Labs 20% Attendance 10% calcgrade(): Given: an overall percentage Return: a letter grade Use the standard 10-point scale for determining the letter grade: 90% or above A 80%-90% B 70%-80% C 60%-70% D Below 60% E printstudent(): Given: the name, all averages, percentage and grade Print the student report using the formatting shown in the examples below. Numbers should be rightjustified and printed with 1 digit past the decimal point. processstudent() Given: the name and number of tests, projects, labs and attendance days Return: the overall percentage calculated This is the middle manager function. It s job is to simply to coordinate the invocation of the functions detailed above, retrieving the results of functions and passing them to others. Invoke getavg() for the tests, projects and labs, using the following maximum number of points: Tests 100 Projects 50 Labs 10 For the attendance average, simply invoke asknumber(). Remember to calculate a percentage. (So if the number of attendance days is 15, and the student attended 15 days, the average should be 100%, not 15%!!).
Finally invoke the functions to calculate the overall percentage, the letter grade, and to print the student report. Return the calculated overall percentage. updatestats() Given: - the name and overall percentage of the student just processed. Alters: - the name and percentage of the top student so far in the class - the sum of the percentages of all students so far in the class - the number of students counted so far in the class At the end of execution, the program must print the name and percentage of the top student in the class, as well as the average overall percentage of all students in the class. The purpose of this function is to update the stats being maintained after one student has been processed. So, now there is one more student counted, and the given percentage is added to the sum of the percentages. If the percentage of the last student processed is higher than the top so far, then we have a new top student. printclassreport() Given: - the name and percentage of the top student - the number of students processed, and the sum of the percentages of all students processed. Calculates the average percentage of all students in the class and prints the class report as shown in the examples below. main() The primary job of main() is to coordinate the execution of the main functions, receiving the results and passing them to the next functions invoked as needed. Main is also responsible for the Sentinel Controlled Loop that stops the processing of students, and proceeds to the report. That is, main() asks the user to enter the student s name or DONE to quit. As usual, there should be a system pause at the end of main(). When asking for the student s name, the program should accept names including spaces at this point. Remember that: string name; cout << Enter name: ; cin >> name; will not accept anything with spaces. Instead, use the following: string name; cout << Enter name: ; cin.ignore(); // without this, the next command may not getline(cin,name); // work correctly. It won t STOP and WAIT 4
Example #1: 5
Example #2: error checking 6