#include <iostream>
#include <string>
#include <sstream>
bool readAndDisplayRecord(std::istream& is)
{
std::cout << "Name: ";
float grade;
while (!(is >> grade)) // A name is not a number.
{
is.clear(); // clear the stream's error state.
std::string name;
if (!(is >> name))
return false;
std::cout << name << ' ';
}
std::cout << "\nGrades:\n\t" << grade << '\n';
for (unsigned i = 0; i < 2; ++i)
{
if (!(is >> grade))
return false;
std::cout << '\t' << grade << '\n';
}
return true;
}
int main()
{
std::istringstream input_stream(
std::string(
"Achmed Abdul Jonah Josh Tonn 75.5 80.0 99.9\n"
"John Smith 80.0 90.9 100\n"
"Samantha F Jones 70.0 79.0 75.0\n"
)
);
while (readAndDisplayRecord(input_stream))
std::cout << '\n' ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8c3N0cmVhbT4KCmJvb2wgcmVhZEFuZERpc3BsYXlSZWNvcmQoc3RkOjppc3RyZWFtJiBpcykKewogICAgc3RkOjpjb3V0IDw8ICJOYW1lOiAiOwoKICAgIGZsb2F0IGdyYWRlOwogICAgd2hpbGUgKCEoaXMgPj4gZ3JhZGUpKSAgICAgIC8vIEEgbmFtZSBpcyBub3QgYSBudW1iZXIuCiAgICB7CiAgICAgICAgaXMuY2xlYXIoKTsgLy8gY2xlYXIgdGhlIHN0cmVhbSdzIGVycm9yIHN0YXRlLgogICAgICAgIHN0ZDo6c3RyaW5nIG5hbWU7CiAgICAgICAgaWYgKCEoaXMgPj4gbmFtZSkpCiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKCiAgICAgICAgc3RkOjpjb3V0IDw8IG5hbWUgPDwgJyAnOwogICAgfQoKICAgIHN0ZDo6Y291dCA8PCAiXG5HcmFkZXM6XG5cdCIgPDwgZ3JhZGUgPDwgJ1xuJzsKICAgIGZvciAodW5zaWduZWQgaSA9IDA7IGkgPCAyOyArK2kpCiAgICB7CiAgICAgICAgaWYgKCEoaXMgPj4gZ3JhZGUpKQogICAgICAgICAgICByZ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