7.1
1 #include <iostream> 2 #include <vector> 3 #include <cctype> 4 #include <string> 5 #include <iterator> 6 #include <initializer_list> 7 #include <cassert> 8 9 using namespace std; 10 11 struct Sales_data{ 12 string bookNo; 13 unsigned units_sold = 0; 14 double revenue = 0.0; //单价 15 }; 16 17 int main() 18 { 19 Sales_data total; 20 if (cin >> total.bookNo >> total.units_sold >> total.revenue) { 21 Sales_data trans; 22 while (cin >> trans.bookNo >> trans.units_sold >> trans.revenue) { 23 if (trans.bookNo == total.bookNo) { 24 total.units_sold += trans.units_sold; 25 } 26 else { 27 cout << total.bookNo << "的销售额为:" << total.units_sold * total.revenue << endl; 28 total.bookNo = trans.bookNo; 29 total.units_sold = trans.units_sold; 30 total.revenue = trans.revenue; 31 } 32 } 33 cout << total.bookNo << "的销售额为:" << total.units_sold * total.revenue << endl; 34 } 35 else { 36 cerr << "No data?!" << endl; 37 } 38 return 0; 39 }