1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using std::istream;
using std::ostream;
using std::string;
using std::cin;
using std::cout;
using std::vector;
using std::sort;
class Student {
public:
int id = {};
static constexpr int NumExams=4;
int exams[NumExams] = {};
int final{};
static constexpr int NumLabs=5;
int labs[NumLabs] = {};
double quizAvg{};
void read(istream &is);
bool operator < (const Student &rhs) const {
return final < rhs.final;
}
void write(ostream &os);
};
void Student::read(istream &is)
{
// YOU MUST WRITE THIS
}
void Student::write(ostream &os)
{
// YOU MUST WRITE THIS
}
// Add the data in "from" into "to"
void accumulate(Student &from, Student &to)
{
// YOU MUST WRITE THIS
}
// Given a student record and the number of students it represents,
// divide all grades by the number of students to convert them to an
// average
void averages(Student &st, int n)
{
// YOU MUST WRITE THIS
}
// Print one line of the histogram for grades between
// low and high (inclusive)
void printHistogram(const vector<Student> &students,
char grade, int low, int high)
{
// YOU MUST WRITE THIS
}
// Calculate and return the average of "arr" which has
// "size" elements
int calcAvg(int arr[], int size)
{
// YOU MUST WRITE THIS
int main()
{
vector<Student> students;
Student st;
Student total; // a dummy record to accumulate the totals
while (st.read(cin), cin) {
students.push_back(st);
accumulate(st, total);
st.write(cout);
}
averages(total, students.size());
sort(students.begin(), students.end());
printHistogram(students, 'A', 90, 100);
printHistogram(students, 'B', 80, 89);
printHistogram(students, 'C', 70, 79);
printHistogram(students, 'D', 60, 69);
printHistogram(students, 'F', 0, 59);
cout << "LOWEST SCORE IN CLASS: " << students[0].final << '\n';
cout << "HIGHEST SCORE IN CLASS: " << students.back().final << '\n';
cout << "NUMBER OF STUDENTS: " << students.size() << '\n';
cout << '\n';
for (int i=0; i<Student::NumExams; ++i) {
cout << "EXAM0" << i << " AVERAGE: " << total.exams[i] << '\n';
}
cout << '\n';
cout << "FINAL AVERAGE: " << total.final << '\n';
cout << '\n';
cout << "LABS AVERAGE: " << calcAvg(total.labs, total.NumLabs) << '\n';
cout << '\n';
cout << "QUIZZES AVERAGE: " << total.quizAvg << '\n';
}
|