inFile/output data

I am behind in my classes due to me missing a couple days for being sick and I am lost on how to handle data that is inside of a txt file and output it. Below is the description for the program and it must include a for statement.

The file prog7Data.txt contains an undetermined number of lines. Each line contains the first and last names of a student followed by the number of tests which the student has taken followed by the individual test scores. Your program should print out each student's name followed by the student's average test score and the highest average score.

Ex. data
Joe Jones 2 70 80
Bozette Brown 3 70 71 74
Bozo Brown 2 85 86

Ex. output

Joe Jones 75
Bozette Brown 71.67
Bozo Brown 85.5

This is what I'm at so far.


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
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
//--------
char ch;
int num; int nChars; int MaxChar;
int count; int i; int MaxLine;
int sum; int nNames; int nNum;
count = 0;
MaxChar=0;
//--------
ifstream infile;
//--------
infile.open("prog7Data.txt", ios ::in);
if (!infile)
{cout << "Unsuccessful!" << endl;
assert(infile);}
//--------
infile >> nNames;
infile.get(ch);
for (i = 1; i <=nNames; i++)
    {
         infile.get(ch);
         nChars=0;
         while ( ch != '\n' )
         {
               if( ((ch >= 'a') && (ch <= 'z'))||((ch >='A' && (ch <= 'Z')) ))
                   nChars++;
               infile.get(ch);
               
               }
         cout << "line " << i << "nChars " << nChars << endl;
         if ( nChars > MaxChar )
         {
              MaxLine = i;
              MaxChar = nChars;
              }
}
cout << endl;
letters" << endl;
//--------------------------
for (i = 1; i <=nNum; i++)
    {
         infile.get(num);
         nNum=0;
         while ( ch != '\n' )
         {
               if ((num >= 1 && (num <= 100))
                  nChars++;
               infile.get(num);
               
               }
         cout << "line " << num << "nNum " << nNum << endl;
         if ( nChars > MaxChar )
         {
              MaxLine = i;
              MaxChar = nChars;
              }
} 

Topic archived. No new replies allowed.