#include #include #include #include #include using namespace std; class Receipt { public: Receipt() = default; void add_product(string const& name, double price, int count = 1) { product[name] = {price, count}; } void print_reciept(ostream& os = cout) const { double total{0}; auto it = max_element( product.cbegin(), product.cend(), [](pair> const& a, pair> const& b) { return a.first.length() < b.first.length(); } ); if ( it != product.cend() ) { int len = it->first.length(); for ( auto const& p : product ) { cout << setw(len) << left << p.first << setw(9) << right << p.second.first << setw(4) << right << p.second.second << setw(9) << right << p.second.first * p.second.second << endl; total += p.second.first * p.second.second; } cout << setw(len+9+4+9) << setfill('=') << '=' << endl << setw(len+9+4) << setfill('.') << left << "Totalt " << setw(9) << setfill(' ') << right << total << endl << setw(len+9+4) << setfill('.') << left << "Varav moms " << setw(9) << setfill(' ') << right << total*.2 << endl; } else { cerr << "No input!" << endl; } } private: map> product{}; }; int main(int argc, char* argv[]) { Receipt r; string line; cout << setprecision(2) << fixed; while ( getline(cin, line) ) { istringstream iss{line}; string name{}; double price{}; int count{1}; iss >> name >> price >> count; r.add_product(name, price, count); } cout << endl; r.print_reciept(); return 0; }