练习1.23
#include <iostream>
#include "Sales_item.h"using namespace std;int main() {Sales_item trans1, trans2;cout << "请输入若干销售记录:" << endl;if (cin >> trans1) {int num = 1;while (cin >> trans2)if (trans1.isbn == trans2.isbn) {num++;} else { //ISBN不同cout << trans1.isbn << "共有" << num << "条销售记录" << endl;trans1 = trans2;num = 1;}cout << trans1.isbn << "共有" << num << "条销售记录" << endl;} else {cout << "没有数据" << endl;return -1;}return 0;
}
练习1.24
测试数据:
测试数据:0-201-78345-X 4 25.00-201-78345-X 1 25.00-201-78345-X 2 25.00-201-78345-X 9 25.00-207-78345-X 9 31.00-207-78345-X 3 31.00-202-78345-X 3 20.00-202-78345-X 3 20.0
测试结果: