I have just begun to tackle a coding problem I must solve, and am unsure how to get started and accomplish the task. There are multiple text files 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. 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. Sometimes a number does not follow "AVERAGE." In that case, you ignore the "AVERAGE". The input will always only have one name and the student's name won't be "Average" or "Name."
Here are some examples:
UNIX> cat test-1.txt
NAME Fred
UNIX> ./moonglow < test-1.txt
Fred 0
UNIX> cat test-2.txt
NAME Dontonio
8.6
16.2
UNIX> ./moonglow < test-2.txt
Dontonio 24.8
UNIX> cat test-3.txt
I miss Starrlight!!
15 NAME
Frank
UNIX> ./moonglow < test-3.txt
Frank 15
UNIX> cat test-4.txt
AVERAGE 10 15 20 NAME Luther 10 Starrlite!!
UNIX> ./moonglow < test-4.txt
Luther 25
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
UNIX> cat test-6.txt
Starrlite AVERAGE Starrlite!!! NAME
Starrlite
AVERAGE 55 Starrlite!!! Starrlite
AVERAGE Starrlite 5 6 7
UNIX> ./moonglow < test-6.txt
Starrlite 73
Sometimes, unnecessary words appear in the file and must be ignored.
Basically, I want to know with what method would I approach reading the input with? Getline? Purely cin? I am not sure how to handle the varying places that each piece of information can be in (name, average, scores) with cin when each can change from file to file.