例3.5.txt

来自「铁道出版社出版的C++的习题源代码」· 文本 代码 · 共 35 行

TXT
35
字号
#include<string.h>
#include<iostream.h>
class Student
{
public:
	Student(int n,string nam,char s)
	{
		num=n;
		name=nam;
		sex=s;
		cout<<"Constructor called."<<endl;
	}
	~Student()
	{
		cout<<"Destructor called."<<endl;
	}
	void display()
	{
		cout<<"num: "<<num<<endl;
		cout<<"name: "<<name<<endl;
		cout<<"sex: "<<sex<<endl<<endl;
	}
private:
	int num;
	char name[10];
	char sex;
};
int main()
{
	Student stud1(10010,"Wang_li",'f');
	stud1.display();
	Student stud2(10011,"Zhang_fun",'m');
	stud2.display();
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?