帮我改改小代码
#include<iostream.h>#include<stdio.h>
#include<string.h>
#include<stdlib.h>
class SCHOOL
{
public:
template<typename T>
void add(T *worker);
};
class PEOPLE
{
protected:
char name[10],sex[3];
};
class WORKER:virtual public PEOPLE
{
private:
int worknum;
public:
void getworker();
void output()
{
cout<<name<<endl<<sex<<endl<<worknum<<endl<<endl;
}
WORKER *next;
};
void WORKER::getworker()
{
cout<<"请输入职工姓名:"<<endl;
cin>>name;
cout<<"请输入职工性别"<<endl;
cin>>sex;
cout<<"请输入工号:"<<endl;
cin>>worknum;
}
template<typename T>
void SCHOOL::add(T *worker) //添加学生函数模版
{
char ad[3];
FILE *fp;
if ((fp=fopen("c:\\学生档案.dat","ab"))==NULL)
{
cout<<"打开失败!";
abort();
}
do
{
worker=new T;
worker->getworker();
fwrite(worker,sizeof(T),1,fp);
delete worker;
cout<<"是否继续添加"<<endl;
cin>>ad;
}
while (strcmp(ad,"是")==0);
fclose(fp);
}
void addwhich() //添加函数的菜单
{
int n;
WORKER *worker;
SCHOOL school;
cout<<"1.添加职工"<<endl<<"2.添加学生"<<endl<<"3.添加在职学生"<<endl;
cin>>n;
switch(n)
{
case 1:school.add(worker);break;
}
}
void main()
{
int n;
cout<<"1.添加"<<ends<<"2.查找"<<ends<<"3.删除"<<endl;
cin>>n;
switch (n)
{
case 1:addwhich();break;
}
}