Files
912-notes/c++ note/chp7/exercise7_3.cpp
2019-05-21 18:44:09 +08:00

24 lines
733 B
C++

#include "exercise7_2.h"
int main() {
Sales_data total; // variable to hold the running sum
if (read(cin, total)) { // read the first transaction
Sales_data trans; // variable to hold data for the next transaction
while (read(cin, trans)) { // read the remaining transactions
if (total.isbn() == trans.isbn()) // check the isbns
total = total.combine(trans); // update the running total
else {
print(cout, total) << endl; // print the results
total = trans; // process the next book
}
}
print(cout, total) << endl; // print the last transaction
}
else { // there was no input
cerr << "No data?!" << endl; // notify the user
}
system("pause");
return 0;
}