C++Primer中文版(第四版)题解整理(9)
时间:2025-04-20
时间:2025-04-20
C++Primer题解
Sales_itembook;
system("CLS");
cout<<"Entertransactions:"<<endl;
while(cin>>book){
//输出ISBN,售出书的本数,总收入,平均价格
cout<<"ISBN,numberofcopiessold,"<<"totalrevenue,andaveragepriceare:"<<endl;
cout<<book<<endl;
}
return0;
}
习题1.22
编写程序,读入两个具有相同ISBN的Sales_item对象并产生它们的和。#include<iostream>
#include"Sales_item.h"
#include"windows.h"
usingnamespacestd;
intmain()
{
Sales_itemtrans1,trans2;
//读入交易
system("CLS");
cout<<"Entertwotransactions:"<<endl;
cin>>trans1>>trans2;
if(trans1.same_isbn(trans2))
cout<<"Thetotalinformation:"<<endl
<<"ISBN,numberofcopiessold,"
<<"totalrevenue,andaveragepriceare:"
<<endl<<trans1+trans2;
else
cout<<"ThetwotransactionshavedifferentISBN."<<endl;
return0;
}
习题1.23
编写程序,读入几个具有相同ISBN的交易,输出所有读入交易的和。#include<iostream>
#include"Sales_item.h"