#include<iostream>
using namespace std;
#include<string>
class Book
{
public:
void setBook(const char *str1,const char *str2,const float num)
{
int len=strlen(str1);
title=new char[len+1];
strcpy(title,str1);
len=strlen(str2);
author=new char[len+1];
strcpy(author,str2);
price=num;
}
Book(Book&);
Book()
{}
Book(const char *str1,const char *str2,const float num)
{
setBook(str1,str2,num);
}
~Book()
{
delete title;
delete author;
}
void print()
{
cout<<"书名:"<<title<<endl;
cout<<"作者:"<<author<<endl;
cout<<"价格:"<<price<<"元"<<endl;
}
private:
char *title;
char *author;
float price;
};
Book::Book(Book&p)
{
title=new char [strlen(p.title)+1];
strcpy(title,p.title);
author=new char [strlen(p.author)+1];
strcpy(author,p.author);
}
int main()
{
Book obj1("中国足球内幕","李承鹏",29.0),obj2(obj1);
obj1.print();
obj2.setBook("傻儿皇帝:阿斗回忆录","王新禧",25.0);
obj2.print();
return 0;
}
using namespace std;
#include<string>
class Book
{
public:
void setBook(const char *str1,const char *str2,const float num)
{
int len=strlen(str1);
title=new char[len+1];
strcpy(title,str1);
len=strlen(str2);
author=new char[len+1];
strcpy(author,str2);
price=num;
}
Book(Book&);
Book()
{}
Book(const char *str1,const char *str2,const float num)
{
setBook(str1,str2,num);
}
~Book()
{
delete title;
delete author;
}
void print()
{
cout<<"书名:"<<title<<endl;
cout<<"作者:"<<author<<endl;
cout<<"价格:"<<price<<"元"<<endl;
}
private:
char *title;
char *author;
float price;
};
Book::Book(Book&p)
{
title=new char [strlen(p.title)+1];
strcpy(title,p.title);
author=new char [strlen(p.author)+1];
strcpy(author,p.author);
}
int main()
{
Book obj1("中国足球内幕","李承鹏",29.0),obj2(obj1);
obj1.print();
obj2.setBook("傻儿皇帝:阿斗回忆录","王新禧",25.0);
obj2.print();
return 0;
}


