不带参数的构造函数有什么问题?
#include <iostream>
#include <cstring>
using namespace std;
class book
{
char name[20];
char chubanshe[20];
char zhuozhe[20];
char time[20];
double price;
public:
book()//不带参数的构造函数有问题
{
strcpy(name,"name");
strcpy(chubanshe,"chuban");
strcpy(zhuozhe,"zhuo");
strcpy(time,"time");
price=0;
}
book(char name1[20],char chuban[20],char zhuo[20],char time1[20],double price1)
{
strcpy(name,name1);
strcpy(chubanshe,chuban);
strcpy(zhuozhe,zhuo);
strcpy(time,time1);
price=price1;
}
void show()
{
cout<<name<<" "<<chubanshe<<" "<<zhuozhe<<" "<<time<<" "<<"$"<<price<<endl;
}
bool operator==(book b)
{
if (strcmp(name,b.name)==0&&strcmp(chubanshe,b.chubanshe)==0&&strcmp(zhuozhe,b.zhuozhe)==0&&strcmp(time,b.time)==0&&price==b.price)
{
return 1;
}
else
{
return 0;
}
}
book& operator=(book b)
{
strcpy(name,b.name);
strcpy(chubanshe,b.chubanshe);
strcpy(zhuozhe,b.zhuozhe);
strcpy(time,b.time);
price=b.price;
return (*this);
}
bool operator<(book b)
{
if (price<b.price)
{
return 1;
}
else
{
return 0;
}
}
book& operator++()
{
price=price+1;
return (*this);
}
book operator++(int)
{
book old;
old=(*this);
++(*this);
return old;
}
};
void main()
{
book c();
book a("qwe","asd","zxc","qaz",99);
a.show();
c.show();
c=a;
a.show();
c.show();
if (a==c)
{
cout<<"yes"<<endl;
}
else
{
cout<<"no"<<endl;
}
(a++).show();
c.show();
(++a).show();
c.show();
if (c<a)
{
cout<<"yes"<<endl;
}
else
{
cout<<"no"<<endl;
}
} |