#include<stdio.h>
#include <windows.h>
#include <time.h>
#include <math.h>
#include <conio.h>
#include <iostream>
using namespace std;
class base//说明一个基类
{
public:
int mar;//标志优秀教师和优秀学生
void getname(){cout << "姓名:" ;cin >> name;}//成员函数
void printneme(){cout << "姓名:" << name << endl;}
virtual bool excell() = 0; //判断优秀与否,纯虚函数
protected:
char name[8];
};
class student:public base
{
int num;
public:
void getnum(){cout << "考试成绩:"; cin >> num;}
bool excell(){return (num > 90)? true:false;}//子类中定义基类的虚函数
};
class teacher:public base
{
int num;
public:
void getnum(){cout << "每周发表贴子数:"; cin >> num;}
bool excell(){return (num > 3)? true:false;}
};
void main(void)
{
base *p[50];
student *pstu;
teacher *pteach;
int count = 0;
char ch;
do
{
cout << "输入老师(t)输入学生(s):";
cin >> ch;
if (ch == 's')
{
pstu = new student;
pstu -> getname();
pstu -> getnum();
pstu -> mar = 0;
p[count++] = pstu;
}
else if (ch == 't')
{
pteach = new teacher;
pteach -> getname();
pteach -> getnum();
pteach -> mar = 1;
p[count++] = pteach;
}
else
cout << "输入错误" << endl;
cout << "重新输入吗(Y/N)";
cin >> ch;
} while (ch == 'y');
for (int i = 0; i < count; i++)
{
if ((p[i] -> mar) == 0)
{
if (p[i] -> excell() == true)
{
cout << "优秀学生:";
p[i] -> printneme();
}
}
else
{
cout << "优秀教师:";
p[i] -> printneme();
}
}
}