⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 3.cpp

📁 平常学习c++的一些小程序
💻 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 + -