定义一个代表书的bool类,要求包含下面几个属性:书名,作者,页数,价格,下面为什么不能运行,求解答! 10
c++程序设计,下面答案不能运行,怎么办/#include<iostream>#include<string>usingnamespacestd;classbook{pr...
c++程序设计,下面答案不能运行,怎么办/
#include<iostream>
#include<string>
using namespace std;
class book
{
private:
string bookname;
string authors;
int pages;
float price;
public:
book(string b=0,string a=0,int p=0,float pr=0)
{
bookname=b;
authors=a;
pages=p;
price=pr;
}
void set(string bo,string au,int pag,float pri);
string getbookname()
{
return bookname;
}
string getauthors()
{
return authors;
}
int getpages()
{
return pages;
}
float getprice()
{
return price;
}
};
void book::set(string bo,string au,int pag,float pri)
{
bookname=bo;
authors=au;
pages=pag; price=pri;
}
int mian()
{
string books;
string author;
int page;
float prices;
book b1,b2;
cout<<"请输入第一本书名,作者,页数,价格"<<endl;
cin>>books>>author>>page>>prices;
b1.set(books,author,page,prices);
cout<<"请输入第二本书的书名,作者,页数,价格"<<endl;
cin>>books>>author>>page>>prices;
b2.set(books,author,page,prices);
cout<<"第一本书名"<<b1.getbookname()<<"作者"<<b1.getauthors()<<"页数"<<b1.getpages()<<"价格"<<b1.getprice()<<endl;
cout<<"第二本书书名"<<b2.getbookname()<<"作者"<<b2.getauthors()<<"页数"<<b2.getpages()<<"价格"<<b2.getprice()<<endl;
return 0;
} 展开
#include<iostream>
#include<string>
using namespace std;
class book
{
private:
string bookname;
string authors;
int pages;
float price;
public:
book(string b=0,string a=0,int p=0,float pr=0)
{
bookname=b;
authors=a;
pages=p;
price=pr;
}
void set(string bo,string au,int pag,float pri);
string getbookname()
{
return bookname;
}
string getauthors()
{
return authors;
}
int getpages()
{
return pages;
}
float getprice()
{
return price;
}
};
void book::set(string bo,string au,int pag,float pri)
{
bookname=bo;
authors=au;
pages=pag; price=pri;
}
int mian()
{
string books;
string author;
int page;
float prices;
book b1,b2;
cout<<"请输入第一本书名,作者,页数,价格"<<endl;
cin>>books>>author>>page>>prices;
b1.set(books,author,page,prices);
cout<<"请输入第二本书的书名,作者,页数,价格"<<endl;
cin>>books>>author>>page>>prices;
b2.set(books,author,page,prices);
cout<<"第一本书名"<<b1.getbookname()<<"作者"<<b1.getauthors()<<"页数"<<b1.getpages()<<"价格"<<b1.getprice()<<endl;
cout<<"第二本书书名"<<b2.getbookname()<<"作者"<<b2.getauthors()<<"页数"<<b2.getpages()<<"价格"<<b2.getprice()<<endl;
return 0;
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询