#include #include #include "CPstring.h" // file: sales.cc // author Dietolf Ramm; date: 11/13/96 // Process sales ticket with last name followed by variable number of numbers // Illustrate using string streams double Summary(string & ticket) // precondition: ticket contains one name followed by one or more numbers // postcondition: name, number of numbers and sum of numbers is printed { int numsales = 0; istrstream indata(ticket); string name; double sale, sales = 0.0; indata >> name; while (indata >> sale) { sales += sale; numsales++; } cout << name << " sold " << numsales << " items worth " << sales << endl; return sales; } int main() { string ticket; double total = 0.0; cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); cout << "Type sale info (enter to quit)" << endl; getline(cin, ticket); while (ticket.length() > 0) { total += Summary(ticket); cout << "Type sale info (enter to quit)" << endl; getline(cin, ticket); } cout << "Total sales were " << total << endl; return 0; } Sample output: sales Type sale info (enter to quit) ramm 10 20 ramm sold 2 items worth 30.00 Type sale info (enter to quit) smith 11 30 smith sold 2 items worth 41.00 Type sale info (enter to quit) morgan 33 44 55 66 morgan sold 4 items worth 198.00 Type sale info (enter to quit) Total sales were 269.00