I'm having issues figuring out a program I need to write. I can't figure out exactly how to start it and I'm not even sure I'm on the right track any help would be appreciated. I need to use a sentinel controlled loop to display the data. I believe I would use a sentinel value of -1 due to the content of the text file but I'm not sure of the steps to get there. Yes, I know the homework policy here, please read my note at the end of the page.
The program is described as follows.
Students in a self-paced course must take 10 quizzes. Each quiz is worth up to 12 points. A file named scoreData.txt contains a student’s first and last name initials, followed by their quiz scores so far, followed by a -1 sentinel value. The output should be as follows:
Name 1 2 3 4 5 6 7 8 9 10 Low Avg
A.A. 5 11 9 5 8 5 3 3 7.2
R.D. 11 2 3 12 8 11 9 2 9.0
J.E. 10 N/A 10.0
K.H. 4 11 5 4 6 8 2 6 11 5 2 6.7
G.M. 10 1 1 9 3 1 5.8
S.O. 3 1 6 1 4.5
The ScoreData.txt file is as follows:
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
|
A A
5
11
9
5
8
5
3
-1
R D
11
2
3
12
8
11
9
-1
J E
10
-1
K H
4
11
5
4
6
8
2
6
11
5
-1
G M
10
1
1
9
3
-1
S O
3
1
6
-1
|
Here is what I have right now:
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
|
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
ifstream gradeFile; //Input filestream object named gradeFile, associate it with ScoreData.txt and attempt to open
gradeFile.open("ScoreData.txt");
if(gradeFile.fail())
{
cout << "File not found. Program terminated." << endl;
return 1;
}
//Begin reading date from ScoreData.txt
double score;
char grade;
while(!gradeFile.eof())
{
gradeFile >> score >> grade;
cout << setw(20) << score << setw(20) << grade << endl;
}
gradeFile.close();
return 0;
}
|
Final note: As you can probably tell this is part of a homework assignment. I know the policy on that here and I'm NOT just looking for an answer.
If someone could help me get the program to the point that it will output this:
1 2
|
A.A. 5 11 9 5 8 5 3
First Student Processed.
|
Then I will take it from there.