64,636
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
using namespace std;
class book
{
public:
book():bookname(" "),number(0),money(0.0){}
book(string& dbookname,int dnumber,double dmoney):bookname(dbookname),number(dnumber),money(dmoney){}
friend istream& operator>>(istream& in,book& inbook)
{
cout<<"Please Enter bookname"<<endl;
in>>inbook.bookname;
in.clear();
cout<<"how much"<<endl;
in>>inbook.number;
in.clear();
cout<<"how money"<<endl;
in>>inbook.money;
in.clear();
return in;
}
friend ostream& operator<<(ostream& put,book& putbook)
{
put<<"the bookname:"<<putbook.bookname<<endl;
put<<"the number :"<<putbook.number<<endl;
put<<"how money :"<<putbook.money<<endl;
return put;
}
book& operator+(book& b1)
{
//book result;
bookname+=b1.bookname;
number+=b1.number;
money+=b1.money;
return *this;
}
private:
string bookname;
int number;
double money;
};
int main()
{
string strName = "Hacker's story";
string strName1 = "c++primer";
book a(strName, 2, 89.56);
book b(strName1, 1, 68.2);
book c;
c=a+b;
cout<<c;
return 0;
string s1="Hacker's story",s2="c++primer";
book a(s1,2,89.56);
book b(s2,1,68.2);
class book
{
public:
book():bookname(" "),number(0),money(0.0){}
book(string& dbookname,int dnumber,double dmoney):bookname(dbookname),number(dnumber),money(dmoney){}
friend istream& operator>>(istream& in,book& inbook);
friend ostream& operator<<(ostream& put,book& putbook);
book& operator+(book& b1)
{
//book result;
bookname+=b1.bookname;
number+=b1.number;
money+=b1.money;
return *this;
}
private:
string bookname;
int number;
double money;
};
istream& operator>>(istream& in,book& inbook)
{
cout<<"Please Enter bookname"<<endl;
in>>inbook.bookname;
in.clear();
cout<<"how much"<<endl;
in>>inbook.number;
in.clear();
cout<<"how money"<<endl;
in>>inbook.money;
in.clear();
return in;
}
ostream& operator<<(ostream& put,book& putbook)
{
put<<"the bookname:"<<putbook.bookname<<endl;
put<<"the number :"<<putbook.number<<endl;
put<<"how money :"<<putbook.money<<endl;
return put;
}
int _tmain(int argc, _TCHAR* argv[])
{
string strName = "Hacker's story";
string strName1 = "c++primer";
book a(strName, 2, 89.56);
book b(strName1, 1, 68.2);
book c;
c=a+b;
cout<<c;
system("pause");
return 0;
}