///////////////////////////main.h
#include<iostream>
using namespace std;
class Student
{
public:
	virtual void cou()=0;
};
class Student1:public Student
{
public:
	void cou()
	{
		cout<<"本科生"<<endl;
	}
};
class Student2:public Student
{
public:
	void cou()
	{
		cout<<"研究生"<<endl;
	}
};
class Student3:public Student
{
public:
	void cou()
	{
		cout<<"高中生"<<endl;
	}
};
class Stack                          //这里并不是实际意义上的栈，且不遵守栈的原则
{
	Student** stack;                       //二重指针，栈名
	Student** botton;                      //栈底
	Student** top;                        //栈顶
public:
	Stack() 
	{
		stack=new Student*[10];
		top=stack;
		botton=stack;
	}
	void push(Student* p)                      //从栈顶入栈
	{
		if(top-stack==9)
		{
			return;
		}
		*top=p;
		top++;
	}
	Student* pop()                            //从栈底出栈
	{
		if(botton==top)
		{
			return NULL;
		}
		return *botton++;
	}
	~Stack()
	{
		delete [] stack;
	}
};

///////////////////////////main.cpp
#include"main.h"
int main()
{
	cout<<"欢迎使用该系统！"<<endl;
	char key='a';
	Stack save;
	while((int)key!=81&&(int)key!=113)
	{
		cout<<"请输入学生类型"<<endl<<"b本科生  y研究生 g 高中生";  
        cout<<"q退出"<<endl;
		cin>>key;
		switch((int)key)                   
        //强制类型转换，把char变成switch语句接受的int型
		{
		case 66:
		case 98:
			{
				save.push(new Student1);
			    break;
			}
		case 89:
		case 121:
			{
				save.push(new Student2);
				break;
			}
		case 71:
		case 103:
			{
				save.push(new Student3);
				break;
			}
		case 81:
		case 113:
			{
				break;
			}
		default:
			{
				cout<<"请查看输入提示，并输入正确的字符"<<endl;
			}
		}
	}
    Student* temp=save.pop();
	while(temp)
	{
		temp->cou();
		temp=save.pop();
	}
	return 0;
}
