请问C++这道题应该怎么做?
C++程序如下:
#include <iostream>
#include <string>
using namespace std;
class Goods
{
protected:
string name;
int quantity;
string supplier;
public:
//构造函数
Goods();
//拷贝构造函数
Goods(const Goods& g);
//析构函数
~Goods();
void input();
void show();
};
Goods::Goods()
{
cout<<"构造函数"<<endl;
}
Goods::Goods(const Goods& g)
{
cout<<"拷贝构造函数"<<endl;
this->name = g.name;
this->quantity = g.quantity;
this->supplier = g.supplier;
}
Goods::~Goods()
{
cout<<"析构函数"<<endl;
}
void Goods::input()
{
cout<<"货品名称:";
cin>>name;
cout<<"数量:";
cin>>quantity;
cout<<"购货商家名称:";
cin>>supplier;
}
void Goods::show()
{
cout<<"货品名称:"<<name<<endl;
cout<<"数量:"<<quantity<<endl;
cout<<"购货商家名称:"<<supplier<<endl;
}
int main()
{
Goods goods0 = Goods();
goods0.input();
goods0.show();
Goods goods1 = goods0;
return 0;
}
运行测试: