怎样在switch语句后创建类对象??求解
写了一个学校管理系统,但是到最后选择的时候不太会,怎样在switch语句后创建类对象??求解啊求解下面上代码代
程序代码:
#include <iostream> #include <string> using namespace std; #define null class record { public: record(string nam,string sex,int ca,int bir,string add,int a):name(nam),sex(sex),card(ca),birth(bir),address(add),age(a){} void input() { cout<<"请输入姓名:"<<endl; cin>>name; cout<<"请输入性别:"<<endl; cin>>sex; cout<<"请输入身份证号:"<<endl; cin>>card; cout<<"请输入生日:"<<endl; cin>>birth; cout<<"请输入地址:"<<endl; cin>>address; cout<<" 请输入年龄:"<<endl; cin>>age; } void display() { cout<<"姓名:"<<name<<" "<<"性别:"<<sex<<" "<<"身份证号:"<<card<<endl; cout<<"生日:"<<birth<<" "<<"地址:"<<address<<" "<<"年龄:"<<endl; } private: string name; string sex; int card; int birth; string address; int age; }; class student:public record { public: student(string nam,string sex,int ca,int bir,string add,int a,int num,int ro,string sub,int gr):record( nam, sex, ca, bir, add, a) {number=num; room=ro; subject=sub; grade=gr; } void inputstu() { input(); cout<<"请输入学号:"<<endl; cin>>number; cout<<"请输入宿舍号:"<<endl; cin>>room; cout<<"请输入专业:"<<endl; cin>>subject; cout<<"请输入年级:"<<endl; cin>>grade; } void showstu() { display(); cout<<"学号:"<<number<<" "<<"宿舍号:"<<room<<" "<<"专业:"<<subject<<" "<<"年级:"<<grade<<endl; } private: int number; int room; string subject; int grade; }; class teacher:public record { public: teacher(string nam,string sex,int ca,int bir,string add,int a,int ap,int wo,int ea,string th,string re,int yanum): record(nam,sex,ca,bir,add,a) {apartment=ap; work=wo; earn=ea; teach=th; research=re; yanumber=yanum; } void inputtea() { input(); cout<<"请输入公寓:"<<endl; cin>>apartment; cout<<"请输入工作时间:"<<endl; cin>>work; cout<<"请输入所教专业:"<<endl; cin>>teach; cout<<"请输入科研单位:"<<endl; cin>>research; cout<<"请输入所带研究生数目:"<<endl; cin>>yanumber; } void showtea() { display(); cout<<"公寓:"<<apartment<<" "<<"工作时间:"<<work<<" "<<"收入:"<<earn<<" "<<"所教科目:"<<teach<<" "<<"科研名称:" <<research<<" "<<"所带研究生数目:"<<yanumber<<endl; } private: int apartment; int work; int earn; string teach; string research; int yanumber; }; int main() { int flag=1; student *stu=null;teacher *tea=null; while(flag) { cout<<"================================================="<<endl; cout<<" 1 学生通道 2 教师通道 "<<endl; cout<<" 3 退出 "<<endl; cout<<"================================================="<<endl; cout<<"请输入您的选择:"<<endl; int choice; cin>>choice; switch(choice) { case 1: stu=new student();if(stu) *stu->inputstu();cout<<"现在核查一遍信息:"<<endl;*stu->showstu();break; case 2: tea=new student();if(tea) *tea->inputtea();cout<<"现在核查一遍信息:"<<endl;*tea->showtea();break; case 3: break; } } return 0; }