My professor has given us this assignment and her solutions are quite confusing.
Please if you can help break down the assignment and solution it would be much appreciated :)
Assignment:
Write a program to provide a report of student grades. Each student is given four exams. The final grade of each student is determined by calculating the weighted average of all the exams. Your report should show the average of each student, the class average, and the maximum and minimum grades for the class.
The first set of data input contains the weights (proportions) for the four exam grades. Next, input the number of students in the class. The set of data input for each student contains the following information:
-- Student's name
-- Student's ID
-- Grade for exam 1
-- Grade for exam 2
-- Grade for exam 3
-- Grade for exam 4
Use the following test data:
-- weights for exams: .10, .20, .25, .45
-- number of student: 15
-- first student record: 101101032, 75, 87, 79, 92
-- make up the rest yourself.
Your output should be neat and readable with appropriate headings.
SOLUTIONS:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std; //input data file
ifstream infile ("C: \\Users\\lwfriedman\\Documents\\cplusplus\\grading\\students.dat");
//output text file - Reportofstream outReport ("C: \\Users\\lwfriedman\
\Documents\\cplusplus\\grading\\report.txt");
int main (){ //variable declarations
string id, course, semester, LastName, FirstName;
float weight1, weight2, weight3, weight4;
int n = 0, grade1, grade2, grade3, grade4;
float FinalGrade, SumGrades = 0;
float MaxSoFar = -1;
float MinSoFar = 150;
if (!infile) //testing files
cerr << Error: could not open input file\n" ;
else
if (!outReport)
cerr << Error: could not open output file\n";
Assignment:
Write a program to provide a report of student grades. Each student is given four exams. The final grade of each student is determined by calculating the weighted average of all the exams.
Break it down.
Write a program to provide a report of student grades. -- Ok, we need a "cout" or file out routine that prints some data. Lets do this last, once we know what we have and will be writing out.
Each student is given four exams. -- Unimportant, red herring. Code as if each student can have N exams. Then you can pass 4 in for now, but if that were to change, you can quickly make the code handle any number of exams.
The final grade of each student is determined by calculating the weighted average of all the exams. -- You need a function that computes this value. This is one of the first things you will do after you have acquired input and populated any data structures.
Your report should show the average of each student, the class average, and the maximum and minimum grades for the class. -- these details support writing the report task above.
-- and just from knowing what we know, you will need a way to GET the data, and probably a class or something to store this data. That creates more tasks:
- create data structure to store data
- create input / population routines to get the data
Flow looks like
-- get data and populate data structure
-- compute averages for each
-- generate report
From there, you write it. You know all the pieces, and it makes sense here to do them in order, so you first write your data structure, then you write the code to populate it, then stop and test that to be sure it works by printing back what you put in and validating it. Then do the computation and test that, then do the output and check that.