int main() { std::istream_iterator<Sales_item> in_iter(std::cin), in_eof; std::vector<Sales_item> vec; while (in_iter != in_eof) vec.push_back(*in_iter++); sort(vec.begin(), vec.end(), compareIsbn); for (auto beg = vec.cbegin(), end = beg; beg != vec.cend(); beg = end) { end = find_if(beg, vec.cend(), [beg](const Sales_item &item){ return item.isbn() != beg->isbn(); }); std::cout << std::accumulate(beg, end, Sales_item(beg->isbn())) << std::endl; } }
int main() { Sales_item item; // call the item argument in Sales_item.h // prompt the user for the desired information to enter // std::string is used for long strings that run to multiple lines std::string my_phrase = "Input ISBN, number of copies sold, and" " price sold and when complete enter C-c"; std::cout << my_phrase << std::endl; /* * defined while to allow users to continually enter in items until stopped * by C-c */ for (int i = 0; i >= 0; ++i) { // index the item number for the count while (std::cin >> item) { if (item != Sales_item()) { // if item is not empty add one for the next item number i += 1; std::cout << "\t" << " " << " " << "\tISBN,\t\t# sold, price," " avg price" << std::endl; std::cout << "Item " << i << " is " << item << std::endl; } } } return 0; }