试题7-5-1.txt

来自「为初学者提供的最佳的C++程序设计源程序库」· 文本 代码 · 共 75 行

TXT
75
字号
#include<iostream.h>
#include<stdio.h>
enum boolean{False,True};
class base
{
public:
	void getname()
	{
		cout<<"姓名:";
		cin>>name;
	}
	void printname(){cout<<"姓名:"<<name<<endl;}
	virtual boolean isgood()=0;
protected:
	char name[8];
};
class student:public base
{
public:
	void getnum()
	{
		cout<<"考试成绩:";
		cin>>num;
	}
	boolean isgood(){return (num>90)?True:False;}
private:
	int num;
};
class teacher:public base
{
public:
	void getnum()
	{
		cout<<"每年发表论文数:";
		cin>>num;
	}
	boolean isgood(){return(num>3)?True:False;}
private:
	int num;
};
void main()
{
	base *p[50];
	student *pstud;
	teacher *ptech;
	char ch;
	int count=0;
	do
	{
		cout<<"输入教师(t)或学生(s):";
		cin>>ch;
		if(ch=='s')
		{
			pstud=new student;
			pstud->getname();
			pstud->getnum();
			p[count++]=pstud;
		}
		else if(ch=='t')
		{
			ptech=new teacher;
			ptech->getname();
			ptech->getnum();
			p[count++]=ptech;
		}
		else
			cout<<"输入错误"<<endl;
		cout<<"继续输入吗(y/n)?";
		cin>>ch;
	}while(ch=='y');
	for(int i=0;i<count;i++)
		if(p[i]->isgood()==True)
			p[i]->printname();
}

⌨️ 快捷键说明

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