Need help understanding

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";

else
{ //files OK
- //do rest of program
infile >> course >> semester >> weight1 >> weight2 >> weight3 >> weight4;
outReport << "Little School of Soft Knocks\n";
outReport << "Student Grade Report" << endl;
outReport << "\nSemester: " << semester << "\nCourse: "<< course <<endl;
outReport << "\nIn computing the Final Grade for each student, the following\n"
<< "weights were used:\n"
<< setw(10) << "Grade 1"<< setw(6) << weight1*100 << "% \t"
<< setw(10) << "Grade 2"<< setw(6) << weight2*100 << "% \n"
<< setw(10) << "Grade 3"<< setw(6) << weight3*100 << "% \t"
<< setw(10) << "Grade 4"<< setw(6) << weight4*100 << "% \n";
outReport << setiosflags(ios::right)
<< setw (10) << "Student ID"
<< setw(10) <<"Name"<< setw(10) << ' '
<< setw(20) << "Grades 1 - 4" << setw(14) <<"Final Grade"
<< resetiosflags(ios::right) << endl << endl;

while
(infile >> id >> LastName >> FirstName >> grade1 >> grade2 >> grade3 >> grade4){
FinalGrade = weight1*grade1 + weight2*grade2 + weight3*grade3 + weight4*grade4;
outReport << setiosflags (ios::fixed) << setprecision(2)
<< setw (11) << setiosflags (ios::left) << id << setw(10) << FirstName << setw(10) << LastName
<< setiosflags(ios::right)
<< setw
(5) << grade1 << setw (5)<< grade2 << setw (5)<< grade3
<< setw (5)<< grade4 << setw (10) << FinalGrade
<< resetiosflags(ios::right) << endl;
SumGrades += FinalGrade;
n++;
if (FinalGrade > MaxSoFar)
MaxSoFar = FinalGrade;
if (FinalGrade
< MinSoFar)
MinSoFar = FinalGrade;
} //end while
outReport << endl << setiosflags(ios::showpoint | ios::fixed | ios::left)
<< setw(25) << "number of students = "<< n << endl
<< setw(25) << "Class Average is "<< SumGrades/n << endl
<< setw(25) << "Maximum Grade is "<< MaxSoFar << endl
<< setw(25) << "Minimum Grade is "<< MinSoFar << endl;
return
0;
}//end if/else from testing files
} //end main


Input file:
Object-
Oriented_Programming
Fall2014
0.15 0.25 0.25 0.35
123456789 Archer Lew 99 62 101 89
111111111 Bond James 100 98 99 89
101010101 Burke Amos 65 77 88 98
222222222 Chambers Pat 44 84 88 101
999999999 Chambers Diane 70 32 90 95
333333333 Clousseau Inspector 42 65 85 54
444444444 Ed Mister 88 99 77 99
666666666 Hammer Mike 88 87 98 78
111222333 Hope Matthew 89 90 80 87
777777777 Kent Clark 99 99 98 99
555555555 Kramer Cosmo 98 87 76 65
000111222 Marlowe Philip 78 76 65 67
888888888 Rockford James 89 78 87 89
444555666 Sunnydale Buffy 87 32 78 92
777888999 Wolfe Nero 100 100 99 100


Output report:
Little School of Soft Knocks
Student Grade Report
Semester: Fall2014
Course: Object-
Oriented_Programming
In computing the Final Grade for each student, the following
weights were used:
Grade 1 15%
Grade 2 25%
Grade 3 25%
Grade 4 35%
Student ID Name Grades 1 -
4 Final Grade
123456789 Lew Archer 99 62 101 89 86.75
111111111 James Bond 100 98 99 89 95.40
101010101 Amos Burke 65 77 88 98 85.30
222222222 Pat Chambers 44 84 88 101 84.95
999999999 Diane Chambers 70 32 90 95 74.25
333333333 Inspector Clousseau 42 65 85 54 62.70
444444444 Mister Ed 88 99 77 99 91.85
666666666 Mike Hammer 88 87 98 78 86.75
111222333 Matthew Hope 89 90 80 87 86.30
777777777 Clark Kent 99 99 98 99 98.75
555555555 Cosmo Kramer 98 87 76 65 78.20
000111222 Philip Marlowe 78 76 65 67 70.40
888888888 James Rockford 89 78 87 89 85.75
444555666 Buffy Sunnydale 87 32 78 92 72.75
777888999 Nero Wolfe 100 100 99 100
99.75
number of students = 15
Class Average is 83.99
Maximum Grade is 99.75
Minimum Grade is 62.70
Last edited on
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.




Topic archived. No new replies allowed.