65,187
社区成员




/*三、以下是图书类book的定义,但没有类的实现部分的代码,请根据类的定义编写类的实现部分的代码,并编写响应的程序对所定义的类进行测试。
Class book
{
char *name; //书名
Char *author; //作者
Int sale; //销售量
Public
Book( ); //无参构造函数
Book(char,char,int); //有参构造函数
Void disp( ) //输出数据
~book( ); //析构函数
}
*/
#include<iostream>
#include<string.h>
using namespace std;
class Book
{
public:
Book(){name="c_plus_plus",author="T_H_Q",sale=60000;};
Book(string name1,string author1,int sale1):name(name1),
author(author1),sale(sale1){;};
string get_name(){return name;};
string get_author(){return author;};
int get_sale(){return sale;};
void display();
~Book();
private:
string name;
string author;
int sale;
};
void Book::display()
{
cout <<"name:";get_name();cout <<"\n";
cout <<"author:";get_author();cout <<"\n";
cout <<"sales:";get_sale();cout<<"\n";
};
int main()
{
Book book1;
Book book2("math","H_S_Q",70000);
book1.display();
book2.display();
return 0;
}