Hello ladies and gents, in Accelerated C++ I have an exercise wich goes as follows:
Write a program that will keep track of grades for several students at once. The programcould keep two vectors in sync. The first should hold the student's names, and the second the final grades that can be computed as input is read. For now, you should assume a fixed number of homework grades. We'll see in 4.1.3/56 how to handle a variable number of grades intermixed with student names.
What Ive got so far is this:
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<string> names;
string name;
vector<double> grades;
double grade;
char ch = 'n';
while (ch != 'Q')
{
cout << "First students name: " << endl;
while (cin >> name)
{
names.push_back(name);
cout << "Enter the three grades.\n";
for (int i = 0; i < 3; ++i)
{
cin >> grade;
grades.push_back(grade);
}
cin.clear();
cout << "Ad another student or press Ctr 'z'." << endl;
}
short count = names.size();
cout << setw(10) <<"Names:" << setw(10) << "Result 1:" << setw(10) << "Result 2:"
<< setw(10) << "Result 3:" << endl;
for (int i = 0; i < count; ++i)
{
cout << setw(10) << names[i];
for(int j = 0; j < amount; ++j)
{
cout << setw(10) << grades[j];
}
cout << endl;
}
cout << "Press Q to quit.\n";
cin.clear();
cin >> ch;
ch = toupper(ch);
}
return 0;
}
Problem with this code is that the same grades are used for each student, I somehow have to get to the grades from the second, third, ... student and think that I need to link the vector for the names with the vector for grades, but, this is the problem. HOW do I do that.
I could write the first student with it's grades and then output them, but, I don't think that's the idea of this exercise.
Thanks for any help.