Here's Moonglow's format. The text file is composed of words. If a word is a number, then that is a student's score on a question, so you add it to the student's exam score. If the word is not a number, but is the word "NAME", then the next word is the student's name (Moonglow only uses first names -- last names are corporate and impersonal). If the word is "AVERAGE", then you start reading numbers until you read a word that is not a number (or is the end of the file). You average all of those numbers and add that to the score. Since Moonglow is a little scatterbrained, sometimes a number does not follow "AVERAGE." In that case, you ignore the "AVERAGE"
This is the assignment. I haven't completely gotten to the math yet, because currently on this program I am getting tons of compilation errors.
Here is a sample of what it should look like:
"UNIX> cat test-5.txt
NAME Baby-Daisy
AVERAGE 3 4 5 6
AVERAGE 7 8 9
Where's Starrlite!!
UNIX> ./moonglow < test-5.txt
Baby-Daisy 12.5"
How would I convert a read in word to a double or an integer?
I also need to read in numbers before I hit AVERAGE and/or NAME for individual scores (these will be added to the average at the end). Should I have cin read into a string and integer at the same time? Would vectors be best?
while (cin >> word)
{
if (word == "NAME")
{
// read the name
}
elseif (word == "AVERAGE")
{
// do average calculation
}
else // Found numbers
{
}
cin.clear();
}