1 /*练习 1.23*/ 2 #include <iostream> 3 #include "Sales_item.h" 4 5 int main(void) 6 { 7 Sales_item total, trans; 8 std::cout << "请输入销售记录" << std::endl; 9 if(std::cin >> total) 10 { 11 int n = 1; 12 while(std::cin >> trans) 13 { 14 if(compareIsbn(total,trans)) 15 ++n; 16 else 17 { 18 std::cout << total << "的销售记录条数为:" << n <<std::endl; 19 total = trans; 20 n = 1; 21 } 22 } 23 std::cout << total << "的销售条数是:" << std::endl; 24 } 25 return 0; 26 }
这个是模仿开头的计数器程序写的
1.24自己去试数据就行
1.25是书上的程序
1 #include <iostream> 2 #include "Sales_item.h" 3 4 int main() 5 { 6 Sales_item total; 7 if(std::cin >> total){ 8 Sales_item trans; 9 while(std::cin >> trans){ 10 if(total.isbn() == trans.isbn()) 11 total += trans; 12 else{ 13 std::cout << total << std::endl; 14 total = trans; 15 } 16 } 17 std::cout << total << std::endl; 18 }else{ 19 std::cerr << "No data?!" << std::endl; 20 return -1; 21 } 22 return 0; 23 }