include<iostream>
#include<string>
using namespace std;
class Book {
char*title;
char*author;
int numsold;
public:
Book(){}
Book(const char*strl,const char*str2,const int num) {
int len=strlen(strl);
title=new char[1en+1];
strcpy(title,strl);
len=strlen(str2);
author=new char[1en+1];
strcpy(author,str2);
numsold=num; }
void sethook(const char * strl,const char * str2,const int num) {
int len=strlen(strl);
title=new char[1en+1];
strcpy(title,strl);
len=strlen(str2);
author=new char[1en+1];
strcpy(author,str2);
numsold=num;
}
~Book() {
delete title;
delete author;
}
void print(ostream& output) {
output<<"书名:"<<title<<endl;
output<<"作者:"<<author<<endl;
output<<"月销售量:"<<numsold<<endl;
}
};
void main() {
Book obj1("数据结构","严蔚敏",200),obj2;
obj1.print(cout);
obj2.setbook("C++语言程序设计","李春葆",210);
obj2.print(cout);
}
书名:数据结构
作者:严蔚敏
月销售量:200
书名:C++语言程序设计
作者:李春葆
月销售量:210