#include <algorithm>
#include <iomanip>
#include <ios>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
using std:: cin ; using std:: setprecision ;
using std:: cout ; using std:: string ;
using std:: endl ; using std:: streamsize ;
using std:: sort ; using std:: vector ;
int main( ) {
vector< string> names;
vector< double > finals;
typedef vector< double > :: size_type vec_sz;
vec_sz sizeStud;
string name;
double sum, grade;
int counter;
std:: istringstream cin ( "fred sally joe end-of-input 10 20 end-of-input 30 end-of-input" ) ;
cout << "Please enter the student's names \" end-of-input\" to end:\t " ;
while ( cin >> name&& name! = "end-of-input" ) {
names.push_back ( name) ;
}
sizeStud = names.size ( ) ;
if ( sizeStud == 0 ) {
cout << "No students entered! Please try again." << endl;
return 1 ;
}
for ( int i = 0 ; i < sizeStud; i++ ) {
sum= 0 ;
counter= 0 ;
cout << "Please enter the grades for " << names[ i]
<< " \" end-of-input\" to end:\t " ;
while ( cin >> grade) {
counter++ ;
sum+ = grade;
}
if ( counter== 0 ) {
cout << "No grades entered! Please try again." << endl;
}
else {
cout << endl;
finals.push_back ( sum/ counter) ;
}
}
for ( int i = 0 ; i < sizeStud; i++ ) {
streamsize prec = cout .precision ( ) ;
cout << names[ i] << "'s final:\t \t " << setprecision( 4 )
<< finals[ i] << setprecision( prec) << endl;
}
return 0 ;
}
I2luY2x1ZGUgPGFsZ29yaXRobT4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKI2luY2x1ZGUgPGlvbWFuaXA+ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKI2luY2x1ZGUgPGlvcz4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKI2luY2x1ZGUgPGlvc3RyZWFtPiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKI2luY2x1ZGUgPHN0cmluZz4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKI2luY2x1ZGUgPHZlY3Rvcj4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKI2luY2x1ZGUgPHNzdHJlYW0+Cgp1c2luZyBzdGQ6OmNpbjsgICAgIHVzaW5nIHN0ZDo6c2V0cHJlY2lzaW9uOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAp1c2luZyBzdGQ6OmNvdXQ7ICAgIHVzaW5nIHN0ZDo6c3RyaW5nOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAp1c2luZyBzdGQ6OmVuZGw7ICAgIHVzaW5nIHN0ZDo6c3RyZWFtc2l6ZTsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAp1c2luZyBzdGQ6OnNvcnQ7ICAgIHVzaW5nIHN0ZDo6dmVjdG9yOwoKaW50IG1haW4oKSB7CiAgICAgdmVjdG9yPHN0cmluZz4gbmFtZXM7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgIHZlY3Rvcjxkb3VibGU+IGZpbmFsczsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICB0eXBlZGVmIHZlY3Rvcjxkb3VibGU+OjpzaXplX3R5cGUgdmVjX3N6OyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgdmVjX3N6IHNpemVTdHVkOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgIHN0cmluZyBuYW1lOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICBkb3VibGUgc3VtLCBncmFkZTsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgaW50IGNvdW50ZXI7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgIHN0ZDo6aXN0cmluZ3N0cmVhbSBjaW4oImZyZWQgc2FsbHkgam9lIGVuZC1vZi1pbnB1dCAxMCAyMCBlbmQtb2YtaW5wdXQgMzAgZW5kLW9mLWlucHV0Iik7CiAgICAgY291dDw8IlBsZWFzZSBlbnRlciB0aGUgc3R1ZGVudCdzIG5hbWVzIFwiZW5kLW9mLWlucHV0XCIgdG8gZW5kOlx0IjsgICAgICAgIAogICAgIHdoaWxlKGNpbj4+bmFtZSYmbmFtZSE9ImVuZC1vZi1pbnB1dCIpIHsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgbmFtZXMucHVzaF9iYWNrKG5hbWUpOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgfSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgIHNpemVTdHVkID0gbmFtZXMuc2l6ZSgpOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICBpZihzaXplU3R1ZCA9PSAwKSB7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgIGNvdXQ8PCJObyBzdHVkZW50cyBlbnRlcmVkISBQbGVhc2UgdHJ5IGFnYWluLiI8PGVuZGw7ICAgICAgICAgICAgICAgICAgIAogICAgICAgICByZXR1cm4gMTsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICB9ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCgogICAgIGZvcihpbnQgaSA9IDA7IGkgPCBzaXplU3R1ZDsgaSsrKSB7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgc3VtPTA7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgY291bnRlcj0wOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgIGNvdXQ8PCJQbGVhc2UgZW50ZXIgdGhlIGdyYWRlcyBmb3IgIjw8bmFtZXNbaV0gICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgPDwiIFwiZW5kLW9mLWlucHV0XCIgdG8gZW5kOlx0IjsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgd2hpbGUoY2luPj5ncmFkZSkgeyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICBjb3VudGVyKys7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgc3VtKz1ncmFkZTsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgfSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgIGlmKGNvdW50ZXI9PTApIHsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgY291dDw8Ik5vIGdyYWRlcyBlbnRlcmVkISBQbGVhc2UgdHJ5IGFnYWluLiI8PGVuZGw7ICAgICAgICAgICAgICAgICAKICAgICAgICAgfSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgIGVsc2UgeyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgY291dDw8ZW5kbDsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgIGZpbmFscy5wdXNoX2JhY2soc3VtL2NvdW50ZXIpOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgIH0gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgIH0gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICBmb3IoaW50IGkgPTAgOyBpIDwgc2l6ZVN0dWQ7IGkrKykgeyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgIHN0cmVhbXNpemUgcHJlYyA9IGNvdXQucHJlY2lzaW9uKCk7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICBjb3V0PDxuYW1lc1tpXTw8IidzIGZpbmFsOlx0XHQiPDxzZXRwcmVjaXNpb24oNCkgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgIDw8ZmluYWxzW2ldPDxzZXRwcmVjaXNpb24ocHJlYyk8PGVuZGw7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgfSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAoKICAgICByZXR1cm4gMDsgICAgICAgICAgICAgIAp9