?? 3.cpp
字號:
/*
Please fulfill the definition of the following class and add
an assignment operator overloaded function which means
when we declared person p1, p2, we can realize p2=p1.
Then you can test it in the main function.
*/
#include <iostream>
#include <string>
using namespace std;
class person{
char *Name;
int Age;
char Sex;
public:
person(char *name="JACK",int age=10,char sex='F');
~person(){}
person operator=(const person& p);
char *GetName(){return Name;}
int GetAge(){return Age;}
char GetSex(){return Sex;}
void show();
};
person::person(char *name,int age,char sex)
{
Name=new char[strlen(name)+1];
strcpy(Name,name);
Age=age;
Sex=sex;
}
person person::operator=(const person& p)
{
Name=new char[strlen(p.Name)+1];
strcpy(Name,p.Name);
Age=p.Age;
Sex=p.Sex;
return person(Name,Age,Sex);
}
void person::show()
{
cout<<Name<<'\t'<<Age<<'\t'<<Sex<<endl;
}
void main()
{
person p1;
person p2("hewei",19,'F');
p1.show();
p1=p2;
p1.show();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -