首页 > 学院 > 开发设计 > 正文

第七章 类 答案

2019-11-06 06:37:55
字体:
来源:转载
供稿:网友

7.1

#include <iostream>
//#include <string>#include "Sales_data.h"/* run this PRogram using the console pauser or add your own getch, system("pause") or input loop */using namespace std;int main(){	cout << "输入数据(ISBN、销售量、原价、实际售价):" << endl; 	Sales_data total;	if (cin >> total.bookNo >> total.units_sold >> total.revenue)	{		Sales_data trans;		while(cin >> trans.bookNo >> trans.units_sold >> trans.revenue)		{			if (total.bookNo == trans.bookNo)			{				total.units_sold += trans.units_sold;				total.units_sold += trans.revenue;							}			else			{				cout << total.bookNo <<" "  << total.units_sold << " " << total.revenue << " " << endl;				total = trans; 			}			}		cout << total.bookNo <<" "  << total.units_sold << " " << total.revenue << " " << endl;	}	else	{		cerr << "No data ?!" << endl;		return -1;	} 	return 0;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表