Demo entry 6733076

c++

   

Submitted by wei on Apr 16, 2018 at 15:35
Language: C++. Code size: 1.6 kB.

// 实验二(C++).cpp: 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class Person
{

private:
	string personid;
	string name;
	string sex;
	string birthday;
	string adress;

public:
	static int num;

	Person()
	{
		cout << "输出学生基本信息。" << endl;
		num++;
		cout << "num=" << num << endl;

	}
	~Person()
	{
		num--;
		cout << "对象被撤销。" << endl;
		if (num == 0)
			system("pause");
		cout << "num=" << num << endl;

	}


	Person(string p, string n, string s, string b, string a)
	{
		cout << "对象被创建。" << endl;
		personid = p;
		name = n;
		sex = s;
		birthday = b;
		adress = a;
		num++;
		cout << "num=" << num << endl;

	}


	void inputPerson()
	{
		cout << "请输入身份证号:";
		cin >> personid;
		cout << "请输入姓名:";
		cin >> name;
		cout << "请输入性别:";
		cin >> sex;
		cout << "请输入生日:";
		cin >> birthday;
		cout << "请输入家庭住址:";
		cin >> adress;
	}


	void printPerson()
	{
		cout << "身份证号:" << Personid << ",姓名:" << Name << ",性别:" << Sex << ",生日:" << Birthday << ",家庭住址:" << Adress << endl;
	}


	Person(Person &stu)
	{
		cout << "" << endl;

		personid = stu.personid;
		name = stu.name;
		sex = stu.sex;
		birthday = stu.birthday;
		adress = stu.adress;
		num++;
		cout << "num=" << num << endl;


	}
};

int Person::num = 0;
int main(void)
{
	Person ps1;
	Person ps2("39493924828334", "小明", "男", "19990725", "青岛科技大学");
	Person ps3(ps2);
	ps2.printPerson();
	ps3.printPerson();
	ps1.inputPerson();
	ps1.printPerson();

	return 0;
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).