#include #include using namespace std; class Book { char *title; char *author; int numsold; public: Book() { } Book(const char *str1, const char *str2, const int num) { int len = strlen(str1); title = new char[len + 1]; strcpy(title, str1); len = strlen(str2); author = new char[len + 1]; strcpy(author, str2); numsold = num; } void setbook(const char *str1, const char *str2, const int num) { int len = strlen(str1); title = new char[len + 1]; strcpy(title, str1); len = strlen(str2); author = new char[len + 1]; strcpy(author, str2); numsold = num; } ~Book() { delete title; delete author; } void print(ostream &output) { output << "book:" << title << endl; output << "author:" << author << endl; output << "total:" << numsold << endl; } }; int main() { Book obj1("Physics", "LiFu", 200), obj2; obj1.print(cout); obj2.setbook("C++ Programming", "SunJuason", 300); obj2.print(cout); return 0; } /* book:Physics author:LiFu total:200 book:C++ Programming author:SunJuason total:300 */