Putting It All Together C Program that Reads Assignment Grades Code
Program Assignment
Write a C++ program that reads assignment grades (integer values between 0 and 100) taken over TWO years and then displays statistics about this data in a formatted table.
Study the tests below to help you understand program behavior. Use the following tests and your own tests to run against your solution in Develop mode. These are the same tests that your solution will be executed against when you submit your work in Submit mode. User input is in bold:
Sample Runs (Program Behavior)
Assume the user will only enter grades between 0 and 100.
Assume the user will correctly enter the specified number of grades for a year.
User in put is in bold:
Test 1
> run
Enter # of grades during year 1: 0
Enter at least one but no more than 15 grades. Try again.
Enter # of grades during year 1: -5
Enter at least one but no more than 15 grades. Try again.
Enter # of grades during year 1: 1
Enter the 1 grade(s): 85
Enter # of grades during year 2: -5
Enter at least one but no more than 15 grades. Try again.
Enter # of grades during year 2: 0
Enter at least one but no more than 15 grades. Try again.
Enter # of grades during year 2: 1
Enter the 1 grade(s): 75
Year Avg Stddev Grades
----------------------------
1 85.0 0.00 { 85 }
No outliers
2 75.0 0.00 { 75 }
No outliers
The first year had the highest grade of 85.
The first year's lowest grade is 85.
The second year's lowest grade is 75.
Test 2
> run
Enter # of grades during year 1: 1
Enter the 1 grade(s): 62
Enter # of grades during year 2: 1
Enter the 1 grade(s): 100
Year Avg Stddev Grades
----------------------------
1 62.0 0.00 { 62 }
No outliers
2 100.0 0.00 { 100 }
No outliers
The second year had the highest grade of 100.
The first year's lowest grade is 62.
The second year's lowest grade is 100.
Test 3
> run
Enter # of grades during year 1: 1
Enter the 1 grade(s): 88
Enter # of grades during year 2: 1
Enter the 1 grade(s): 88
Year Avg Stddev Grades
----------------------------
1 88.0 0.00 { 88 }
No outliers
2 88.0 0.00 { 88 }
No outliers
Both years had the highest grade of 88.
The first year's lowest grade is 88.
The second year's lowest grade is 88.
Test 4
> run
Enter # of grades during year 1: 2
Enter the 2 grade(s): 0 100
Enter # of grades during year 2: 1
Enter the 1 grade(s): 50
Year Avg Stddev Grades
----------------------------
1 50.0 50.00 { 0, 100 }
No outliers
2 50.0 0.00 { 50 }
No outliers
The first year had the highest grade of 100.
The first year's lowest grade is 0.
The second year's lowest grade is 50.
Test 5
> run
Enter # of grades during year 1: 2
Enter the 2 grade(s): 76 64
Enter # of grades during year 2: 2
Enter the 2 grade(s): 94 83
Year Avg Stddev Grades
----------------------------
1 70.0 6.00 { 76, 64 }
No outliers
2 88.5 5.50 { 94, 83 }
No outliers
The second year had the highest grade of 94.
The first year's lowest grade is 64.
The second year's lowest grade is 83.
Test 6
> run
Enter # of grades during year 1: 2
Enter the 2 grade(s): 90 67
Enter # of grades during year 2: 2
Enter the 2 grade(s): 68 90
Year Avg Stddev Grades
----------------------------
1 78.5 11.50 { 90, 67 }
No outliers
2 79.0 11.00 { 68, 90 }
No outliers
Both years had the highest grade of 90.
The first year's lowest grade is 67.
The second year's lowest grade is 68.
Test 7
> run
Enter # of grades during year 1: 2
Enter the 2 grade(s): 65 65
Enter # of grades during year 2: 1
Enter the 1 grade(s): 75
Year Avg Stddev Grades
----------------------------
1 65.0 0.00 { 65, 65 }
No outliers
2 75.0 0.00 { 75 }
No outliers
The second year had the highest grade of 75.
The first year's lowest grade is 65.
The second year's lowest grade is 75.
Test 8
> run
Enter # of grades during year 1: 2
Enter the 2 grade(s): 45 60
Enter # of grades during year 2: 2
Enter the 2 grade(s): 60 50
Year Avg Stddev Grades
----------------------------
1 52.5 7.50 { 45, 60 }
No outliers
2 55.0 5.00 { 60, 50 }
No outliers
Both years had the highest grade of 60.
The first year's lowest grade is 45.
The second year's lowest grade is 50.
Test 9
> run
Enter # of grades during year 1: 1
Enter the 1 grade(s): 67
Enter # of grades during year 2: 2
Enter the 2 grade(s): 45 70
Year Avg Stddev Grades
----------------------------
1 67.0 0.00 { 67 }
No outliers
2 57.5 12.50 { 45, 70 }
No outliers
The second year had the highest grade of 70.
The first year's lowest grade is 67.
The second year's lowest grade is 45.
Test 10
> run
Enter # of grades during year 1: 4
Enter the 4 grade(s): 45 46 45 55
Enter # of grades during year 2: 3
Enter the 3 grade(s): 60 47 17
Year Avg Stddev Grades
----------------------------
1 47.8 4.21 { 45, 46, 45, 55 }
Outliers: < 55 >
2 41.3 18.01 { 60, 47, 17 }
Outliers: < 60, 17 >
The second year had the highest grade of 60.
The first year's lowest grade is 45.
The second year's lowest grade is 17.
Test 11
> run
Enter # of grades during year 1: 5
Enter the 5 grade(s): 17 43 30 47 60
Enter # of grades during year 2: 7
Enter the 7 grade(s): 56 75 66 65 66 98 45
Year Avg Stddev Grades
----------------------------
1 39.4 14.73 { 17, 43, 30, 47, 60 }
Outliers: < 17, 60 >
2 67.3 15.29 { 56, 75, 66, 65, 66, 98, 45 }
Outliers: < 98, 45 >
The second year had the highest grade of 98.
The first year's lowest grade is 17.
The second year's lowest grade is 45.
Test 12
> run
Enter # of grades during year 1: 9
Enter the 9 grade(s): 45 46 45 43 40 44 42 65 42
Enter # of grades during year 2: 10
Enter the 10 grade(s): 76 75 60 79 75 74 73 80 90 75
Year Avg Stddev Grades
----------------------------
1 45.8 7.02 { 45, 46, 45, 43, 40, 44, 42, 65, 42 }
Outliers: < 65 >
2 75.7 7.01 { 76, 75, 60, 79, 75, 74, 73, 80, 90, 75 }
Outliers: < 60, 90 >
The second year had the highest grade of 90.
The first year's lowest grade is 40.
The second year's lowest grade is 60.
Test 13
> run
Enter # of grades during year 1: 10
Enter the 10 grade(s): 76 75 60 79 75 74 73 80 90 75
Enter # of grades during year 2: 9
Enter the 9 grade(s): 45 46 45 43 40 44 42 65 42
Year Avg Stddev Grades
----------------------------
1 75.7 7.01 { 76, 75, 60, 79, 75, 74, 73, 80, 90, 75 }
Outliers: < 60, 90 >
2 45.8 7.02 { 45, 46, 45, 43, 40, 44, 42, 65, 42 }
Outliers: < 65 >
The first year had the highest grade of 90.
The first year's lowest grade is 60.
The second year's lowest grade is 40.
Test 14
> run
Enter # of grades during year 1: 10
Enter the 10 grade(s): 45 46 45 43 40 44 42 65 42 90
Enter # of grades during year 2: 10
Enter the 10 grade(s): 76 75 40 79 75 74 73 80 90 75
Year Avg Stddev Grades
----------------------------
1 50.2 14.84 { 45, 46, 45, 43, 40, 44, 42, 65, 42, 90 }
Outliers: < 90 >
2 73.7 12.17 { 76, 75, 40, 79, 75, 74, 73, 80, 90, 75 }
Outliers: < 40, 90 >
Both years had the highest grade of 90.
The first year's lowest grade is 40.
The second year's lowest grade is 40.
Write a C++ program that reads assignment grades taken over TWO years and then displays statistics about this data in a formatted table.
Your solution will be graded based upon program behavior (passing tests). Your solution will not receive full credit (or receives no credit) if you fail to follow these restrictions:
Your program must compile and run. Otherwise it will receive a zero.
Add your solution to the provided code template.
Only use C++ statements presented in the lecture notes and assigned readings.
Only use course material up to passing arrays.
Do not use explicitly defined pointer variables, i.e. using the * notation.
Do not use vectors.
Use descriptive variable names. Avoid too short variable names, especially single letter variable names.
DO NOT start a variable name with a capital letter. Use the name convention for constants given in the lecture notes.
If you define your own function name, make sure it is a descriptive name.
Properly use const, pass-by-value, and pass-by-reference when defining function parameters.
Properly choose between using the while vs the for statement.
DO NOT use the do-while loop.
Avoid repetitive code where possible.
DO NOT use explicit type casting. Instead use coercion (see lecture notes).
DO NOT unnecessarily use parenthesis in an expression, e.g. an equation or formula. Parenthesis should only be used for grouping portions of an expression to change operator precedence order. For example, parenthesis are unnecessary in the expression (a + b + c). Instead use a + b + c. Parenthesis are necessary in the expression (a + b + c) / 3.
Do NOT use the break and continue statements.
Your program must be readable including indenting, spaces, and avoid lines that are too long. Use the the sample programs in the lecture notes as a guide.
Comment your program. Read the document at the "Lecture" link on Carmen under Modules->Commenting Your Program-> Commenting your program. DO NOT comment every line.
Only use C++ statements presented in the course. I.e. statements and notation presented in the lecture notes and assigned readings.
You will implement the main function and a collection of functions. DO NOT delete nor change the code already given to you in the code template. You will add your code to this template to formulate your solution.
TASK 1: Replace "??" with your name, creation date, and a description of the program (synopsis).
TASK 2: Declare a GLOBAL constant to hold the integer 15, which will represent the maximum number of grades the user can record for one year.
TASK 3: Implement the following algorithm in the main function:
i. Declare your variables. Use the global constant (see TASK 2 above) to allocate TWO arrays, where each array holds the grades for a single year. Use fixed memory allocation.
ii. Read the grades for each year (there are two years). Call the function described in TASK 4, step 6. You will call this function twice, i.e. once for each day.
iii. Output an empty line.
iv. Display the headings for the formatted table. Call the procedure in TASK 4, step 7.
v. Display the statistics for each of the two years. Call the procedure in TASK 4, step 8. You will call this function twice, i.e. once for each year.
vi. Display the highest and lowest grades from the grade data in both days. Call the procedure in TASK 4, step 9.
TASK 4: Define the following functions and helper functions. Remember, a procedure is a function with no return value. In order to receive full credit, closely follow the provided instructions below. You must determine when to use const and pass by value vs. pass by reference. If you are not sure, then please study the lecture slides and notes.
Important: You will write eight functions as specified below. Choose descriptive function and variable names.
Place function prototypes BEFORE the main procedure.
Place function definitions AFTER the main procedure.
Each function should have a comment (placed above the function definition) that describes the function's task.
Include in this comment a short description of each input parameter.
Write a function to read from the user the grades for one year. Use the global constant (see TASK 2 above) in this function. The function has two input parameters: 1) an array to hold the grades for this year and 2) the year these grades belong to (either 1 or 2 for year 1 or year 2). The function returns the number of grades entered by the user. Prompt the user for the number of grades to read, say n, which must be at least 1 but no more than 15 (The value of the global constant). If invalid input is entered, then display a warning message and repeatedly ask the user again. See the provided test cases for the exact prompt and warning messages to use. Finally, read the n grades from the user.
Assume the user will enter exactly n grades.
Assume the user will only enter integer grades in the range 0 to 100. I.e., you DO NOT have to check for valid input here.
Write a procedure to display the first two lines of the output table containing the column names and dashed line. Use iomanip functions to attain the correct spacing. This procedure has no input parameters. Remember, a procedure is a function that does not return a value.
Write a procedure that computes the statistics (average, min, max, standard deviation) of a list of grades and then prints these statistics in the formatted table. This procedure has five input parameters: 1) which year (year 1 or year 2), 2) an array of grades, 3) the number of grades in the array, 4) the minimum grade found, and 5) the maximum grade found. Here is a link to a Wikipedia page that defines the standard deviation ( https://en.wikipedia.org/wiki/Standard_deviation ). Examples of how to calculate the standard deviation can be found here ( https://www.mathsisfun.com/data/standard-deviation.html ). Use fixed mode to display decimal values. The average is displayed with one digit after the decimal place. The standard deviation is displayed with two digits after the decimal place. Use iomanip functions to achieve proper spacing (see the provided test case output). This procedure MUST call these four "helper" functions whose descriptions are provided below:
(a) Write a procedure to compute the average (i.e., mean), minimum, and maximum grades. This procedure has five input parameters: 1) an array of grades, 2) the number of grades in the array, 3) the average computed by this procedure, 4) the minimum grade computed by this procedure, and 5) the maximum grade computed by this procedure.
(b) Write a function to compute the standard deviation and the number of (how many) "outliers". An "outlier" is a grade that is more than one standard deviation away from the average grade. The function has four input parameter: 1) an array of grades, 2) the number of grades in the array, 3) the average of the grades, and 4) the number of "outliers" computed by this function. The return value is the standard deviation computed by this function.
(c) Write a procedure to output the sampled grades in a comma separated list delimited by curly braces. This procedure has two input parameters: 1) an array of grades and 2) the number of grades in the array. Use an endl after the closing curly braces.
(d) Write a procedure to output the "outliers" as a comma separated list delimited by angle brackets, i.e. "< … >". If there are no "outliers" then output "No outliers". The procedure has five input parameters: 1) an array of grades, 2) the number of grades in the array, 3) the average of the grades, 4) the standard deviation of the grades, and 5) the number of "outliers". Use an endl at the end of the output.
Write a procedure to output the highest grade across the two years and the lowest grades for both years. The procedure has four input parameters: 1) the lowest grade in year 1, 2) the highest grade on year 1, 3) the lowest grade on year 2, and 4) the highest grade on year 2. Use an endl at the end of the output.
Be sure that there is a comment documenting each variable.
Be sure that your if statements, for and while loops and blocks are properly indented.
Test your solution.