C++ Primer-书店小程序

从一个文件中读取销售记录,生成每本书的销售记录,显示售出册数,总销售额和平均售价。我们假定每个ISBN书号的所有销售记录是聚在一起的。

 1 #include <iostream>
 2 #include "Sales_item.h"
 3 int main()
 4 {
 5     Sales_item total;//定义一个Sales_item类total;
 6     if (std::cin>>total){//读取输入的第一个数,并判断是否输入;
 7         Sales_item trans;
 8         while (std::cin>>trans){
 9             if (total.isbn()==trans.isbn()){
10                 total += trans;
11             }
12             else {
13                 std::cout<<total<<std::endl;
14                 total = trans;
15             }
16         }
17         std::cout<<total<<::std::endl;
18         system("pause");
19         return 0;
20     }
21     else {
22         std::cerr<<"NO data?!"<<std::endl;
23         system("pause");
24         return -1;
25     }
26 }
View Code

 

posted @ 2018-08-24 15:23  archerzon  阅读(391)  评论(0编辑  收藏  举报