"Jerry Coffin" wrote:
<snip>
> Also, unless memory fails, the student ID and that student's proposed
> answers were on the same line, so you wouldn't normally want to use
> readline to read them (or at least not the ID).
I thought getline was a good choice for reading this line, too, it
demonstrates the nice substring capabilities available in <string>.
Something like this
while(getline(inf, line) ) // inf is a file that has been
// opened for reading
{
string id(line, 0, 7);
cout << id; // note no endl
string answers(line, 8, 100);
int code = validate(answers); // code of 0 - input
//is fine to continue to score
int sc = score(answers);
}
// do EOF stuff
where the results returned by both validate and score() are ignored, to
avoid clutter.
In my earlier post to the OP, I think I suggested validate returns a bool,
the above changes that to an int so that printing can be in main, rather
than farmed out to the functions - this strikes me as "more pure". The above
is intended to pay attention to the instructors desire for "functional
decomposition". .
In testing the snippet above, I belatedly noted that the student ids in the
test file are all the same