#include #include #include #include using namespace std; int main(int argc, char* argv[]) { if ( argc != 2 ) { cerr << "ERROR: usage: " << argv[0] << " filnamn" << endl; return 1; } ifstream grade_data(argv[1]); if ( ! grade_data ) { cerr << "ERROR: could not open '" << argv[1] << "'" << endl; return 1; } cout << setprecision(2) << fixed; string product_name; while ( getline(grade_data, product_name, ';') ) { double grade = 0.0; int votes = 0; int price = 0; string junk; grade_data >> price >> junk >> votes; if ( votes > 0 ) grade_data >> grade; grade_data.ignore(1024, '\n'); if ( votes > 3 ) { double average = grade + (grade - 5)/votes; cout << setw(45) << left << product_name << setw(10) << right << price << ":-" << setw(6) << votes << setw(8) << grade << setw(8) << average << endl; } } return 0; }