谁能帮我把这个程序完善一下阿,为什么编译的时候没有错误,在执行的时候却出现了3个错误呢?
程序的源代码如下:
#include<iostream.h>
#include<afx.h>
#include<string.h>
class employee
{public:
char m_strName[10];
char m_strSex[6];
int m_nAge;
char m_strDept[20];
employee(){}
employee(char *name,char *sex,int age,char *dept);
void SaveEmp(CFile* fp){fp->Write(this,sizeof(employee));}
void ReadEmp(CFile* fp){fp->Read(this,sizeof(employee));}
void ShowMe()
{cout<<m_strName<<"\t"<<m_strSex<<"\t"<<m_nAge<<"\t"<<m_strDept<<endl;
}
};
employee::employee(char *name,char *sex,int age,char *dept)
{strcpy(m_strName,name);
strcpy(m_strSex,sex);
m_nAge=age;
strcpy(m_strDept,dept);
}
void main()
{int count=0;
employee emp[50];
int i,j,age;
CFile myfile;
CFileException e;
char name[10],sex[6],dept[20];
for(;;)
{cout<<"1.显示所有 2.增加雇员 3.删除雇员";
cout<<"4.存储信息 5.读取信息 6.退出\n";
cout<<"请输入选项编号:";
cin>>i;
switch(i){
case 1:
cout<<endl<<"--------------------------------"<<endl;
for(i=0;i<count;i++)
{cout<<" "<<i+1<<"\t";
emp[i].ShowMe();
}
cout<<endl<<"--------------------------------"<<endl;
break;
case 2:
if(count<50)
{i=count++;
cout<<"请依次输入姓名、性别、年龄、工作部门:\n";
cin>>name>>sex>>age>>dept;
emp[i]=employee(name,sex,age,dept);
strcpy(emp[i].m_strDept,dept);
}
else {cout<<"存储空间已满!";}
break;
case 3:
cout<<"请输入要删除的雇员号:\t";
cin>>i;
if(i<=count&&i>0)
{for(j=i;j<count;j++){emp[j-1]=emp[j];}
count--;
cout<<"\n记录已删除!\n";
}
else {cout<<"输入错误!";}
break;
case 4:
myfile.Open("emp_Rec",CFile::modeWrite|CFile::modeCreate,&e);
myfile.Write(&count,sizeof(count));
for(j=0;j<count;j++)emp[j].SaveEmp(&myfile);
myfile.Close();
cout<<"\n雇员信息已存!\n";
break;
case 5:
if(myfile.Open("emp_Rec",CFile::modeRead,&e))
{myfile.Read(&count,sizeof(count));
for(j=0;j<count;j++)emp[j].ReadEmp(&myfile);
myfile.Close();
cout<<"\n雇员信息已读入\n";
}
else {cout<<"\n文件打开失败\n";}
break;
default:
return;
}
}
}