I have been trying to get this program to work for hours and I am no where close. It is really frustrating. |
If you get stuck for more than 30 minutes, seek help. It's easy to spin your wheels for hours and hours but it isn't productive.
You've got some good stuff here, it just needs to be rearranged a little and expanded on. First, notice that the assignment says you should have these functions. Follow those instructions from the start. It looks like you're trying to write the code first, and then break it into functions later.
Use three arrays: a one-dimensional array to store the student names, a two-dimensional array to store the test scores, and a one-dimensional array to store the grades. |
You've got most of this. I suggest:
1 2 3 4 5 6 7 8 9
|
const int NumStudents = 5; // at file scope so you can use them everywhere
const int NumTests = 5;
int main()
{
string names[NumStudents];
int scores[NumStudents][NumTests];
string grades[NumStudents]; // this one is new
...
|
Note that I've renamed rows and cols to be NumStudents and NumTests because that's more descriptive
Your program must contain at least the following functions: read and store data into two arrays |
I guess that should read the names and the test scores:
1 2 3
|
void read(string names[NumStudents], int scores[NumStudents][NumTests], istream &is)
{
}
|
Notice that I've passed the stream as a parameter. This makes it more flexible than, say, passing in the name of the file.
a function to calculate average test score and grade |
Hmm. Are you supposed to print the average scores? I didn't see this anywhere. Okay, let's make a function that takes one set of test scores and returns a grade
1 2 3
|
string getGrade(int scores[NumTests])
{
}
|
And finally the display function:
1 2 3
|
void display(string names[NumStudents], int scores[NumStudents][NumTests], string grades[NumStudents], ostream &os)
{
}
|
Now your main function will look like this:
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
|
int main()
{
string names[NumStudents];
int scores[NumStudents][NumTests];
string grades[NumStudents]; // this one is new
ifstream inFile;
// NOTE THE DOUBLE SLASHES BELOW!
inFile.open("C:\\Users\\STUDENTS\\Desktop\\Ch9Ex12.txt");
if (!inFile){
cout << "File not found!" << endl;
return 1;
}
read(names, scores, inFile);
inFile.close();
// Calcuate the grades
for (student = 0; student < NumStudents; ++student) {
grades[student] = getGrade(scores[student]);
}
// display the results
display(names, scores, grades, cout);
return 0;
}
|
Hope this helps.