10.5.cpp

来自「这是C++的一部分练习程序!对初学者有一定的帮助作用。」· C++ 代码 · 共 48 行

CPP
48
字号
#include <iostream.h>
#include <string.h>
class Student
{
  public:
	Student(int no,char *str,char s)
	{
		stuno=no;
		strcpy(name,str);
		sex=s;
		cout<<"Constructor called.S\n";
	}
	void Print()
	{
		cout<<stuno<<'\t'<<name<<'\t'<<sex<<'\t';
	}
  private:
	int stuno;
	char name[20];
	char sex;
};
class Student1:public Student
{
  public:
	Student1(int no,char *str,char s,int a,int sco):Student(no,str,s)
	{
		age=a;
		score=sco;
		cout<<"Constructor called.S1\n";
	}
	void Print()
	{
		Student::Print();
		cout<<age<<'\t'<<score<<endl;
	}
  private:
	int age,score;
};
void main()
{
	Student1 s1(502001,"Ma li",'m',20,90),s2(502002,"Li hua",'f',19,88);
	s1.Print();
	s2.Print();
}



⌨️ 快捷键说明

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