设计评选优秀教师和优秀学生候选人的程序。

设计评选优秀教师和优秀学生候选人的程序。如果学生的分数大于90,则可评为优秀生;如果教师发
表的论文数大于 3,则可评为优秀教师。具体要求如下:
(1)定义基类Base:①保护数据成员
char name[8]; //存放姓名 
int num; //存放分数或论文数 
②公有成员函数
Base():构造函数,输入姓名;
void print):功能函数,输出数据成员;
virtual int Isgood()=0:纯虚函数,用于判断是否满足条件;
(2)由基类派生学生类Student,定义公有成员函数:
Student():构造函数,输入分数;
int Isgood():根据优秀学生的标准,满足条件返回1,否则返回0;
(3)由基类派生教师类Teacher,定义公有成员函数:
Teacher():构造函数,输入论文数;
int Isgood():根据优秀教师的标准,满足条件返回1,否则返回0;
(4)在主函数中定义学生数组和教师数组,输入一系列教师或学生的记录后,将优秀教师及学生候选
人的情况列出来,并体现运行的多态性

#include<iostream>
using namespace std;
class base
{
protected:
	char name[8];
	int num;
public:
	base() 
	{
		cout << "输入姓名:" << endl;
		cin >> name;
	}
	void print()
	{
		cout << "姓名:" << this->name << "  " << "数字:" << this->num << endl;
	}
	virtual int isgood() = 0;
};
class student :public base
{
public:
	student()
	{
		cout << "输入分数:" << endl;
		cin >> num;
	}
	void print()
	{
		cout << "姓名:" << this->name << "  " << "分数:" << this->num << endl;
	}
	virtual int isgood()
	{
		if (this->num >= 90)
			return 1;
		else
			return 0;
	}
};
class teacher :public base
{
public:
	teacher()
	{
		cout << "输入论文数:" << endl;
		cin >> num;
	}
	void print()
	{
		cout << "姓名:" << this->name << "  " << "论文数目:" << this->num << endl;
	}
	virtual int isgood()
	{
		if (this->num >= 3)
			return 1;
		else
			return 0;
	}
};
int main()
{
	student stu[3];
	student* ps = stu;
	int i = 0;
	for (i=0,ps=stu;i<3;i++, ps++)
	{
		if (ps->isgood())
			ps->print();
	}
	teacher tea[4];
	teacher* pt = tea;
	for (i = 0, pt = tea; i < 4; i++, pt++)
	{
		if (pt->isgood())
			pt->print();
	}
	system("pause");
}

  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值