有关***.exe已停止运行。十万火急!!求各路大神相助!
一个职工工资管理系统,定义好了类,在主程序里面创建一个二进制文件,但是在程序运行一开始就出现说exe已停止运行,搞了好久,就是不知道哪里不对。所以想请各路大神帮忙看看,到底是哪里出了问题。
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
class Employee
{
friend ostream& operator<<(ostream&,Employee&);
friend istream& operator>>(istream&,Employee&);
private:
char name[20];//姓名
char sex[5];//性别
int account;//工号
char section[20];//科室
double salary;//工资
char telephone[15];//电话
char address[50];//住址
char key[15];//密码
public:
Employee(){}
Employee(char[],char[],char[],char[],char[],int,char[],double);
char* Getname();
char* Getsex();
char* Gettelephone();
char* Getaddress();
char* Getkey();
int Getaccount();
char* Getsection();
double Getsalary();
void revise_account(int);//修改工号
void revise_section(char[]);//修改科室
void revise_salary(double);//修改工资
void revise_name(char[]);//修改姓名
void revise_sex(char[]);//修改性别
void revise_telephone(char[]);//修改电话
void revise_address(char[]);//修改住址
int revise_key(char[]);//修改密码
void addEmployee();//增加员工信息
virtual ~Employee();
};
#endif
#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <dos.h>
#include <windows.h>
#include "emp.h"
ostream& operator<<(ostream& output,Employee&a)
{
output<<"姓名: "<<a.name<<endl;
output<<"性别: "<<a.sex<<endl;
output<<"电话: "<<a.telephone<<endl;
output<<"住址:"<<a.address<<endl;
output<<"工号: "<<a.account<<endl;
output<<"科室: "<<a.section<<endl;
output<<"工资: "<<a.salary<<"/月"<<endl;
return output;
}
istream& operator>>(istream& input,Employee&a)
{
input>>a.name>>a.sex>>a.telephone>>a.address>>a.key>>a.account>>a.section>>a.salary;
return input;
}
Employee::Employee(char n[],char sex[],char t[],char ad[],char k[],int a,char sec[],double sal)
{
strcpy(name,n);
strcpy(sex,sex);
strcpy(telephone,t);
strcpy(address,ad);
strcpy(key,k);
account=a;
strcpy(section,sec);
salary=sal;
}
int Employee::Getaccount()
{
return account;
}
char* Employee::Getsection()
{
return section;
}
double Employee::Getsalary()
{
return salary;
}
void Employee::revise_account(int a)
{
account=a;
cout<<"工号修改成功!"<<account<<endl;
Sleep(1000);
system("cls");
}
void Employee::revise_section(char c[])
{
strcpy(section,c);
cout<<"科室修改成功!"<<section<<endl;
Sleep(1000);
system("cls");
}
void Employee::revise_salary(double c)
{
salary=c;
cout<<"工资修改成功!"<<salary<<endl;
Sleep(1000);
system("cls");
}
char* Employee::Getname()
{
return name;
}
char* Employee::Getsex()
{
return sex;
}
char* Employee::Gettelephone()
{
return telephone;
}
char* Employee::Getaddress()
{
return address;
}
char* Employee::Getkey()
{
return key;
}
void Employee::revise_name(char a[])
{
strcpy(name,a);
cout<<"姓名修改成功!"<<name<<endl;
Sleep(1000);//延迟界面保留时间
system("cls");//清屏
}
void Employee::revise_sex(char b[])
{
strcpy(sex,b);
cout<<"性别修改成功!"<<sex<<endl;
Sleep(1000);
system("cls");
}
void Employee::revise_telephone(char b[])
{
strcpy(telephone,b);
cout<<"电话修改成功!"<<telephone<<endl;
Sleep(1000);
system("cls");
}
void Employee::revise_address(char d[])
{
strcpy(address,d);
cout<<"住址修改成功!"<<address<<endl;
Sleep(1000);
system("cls");
}
int Employee::revise_key(char e[])
{
if(strlen(e)<6||strlen(e)>15)
{
cout<<"密码应不小于6位,不大于15位!"<<endl;
return 0;
}
else
{
strcpy(key,e);
cout<<"密码修改成功!"<<key<<endl;
return 1;
}
Sleep(1000);
system("cls");
}
void Employee::addEmployee()
{
ofstream outfile("employee.dat",ios::out|ios::binary|ios::ate|ios::app);
if(!outfile)
{
cerr<<"open error!"<<endl;
exit(1);
}
cout<<"请输入新职工的信息:"<<endl;
cout<<"姓名:";
cin>>name;
outfile<<name;
cout<<"性别:";
cin>>sex;
outfile<<sex;
cout<<"电话:";
cin>>telephone;
outfile<<telephone;
cout<<"住址:";
cin>>address;
outfile<<address;
cout<<"工号:";
cin>>account;
outfile<<account;
cout<<"科室:";
cin>>section;
outfile<<section;
cout<<"工资:";
cin>>salary;
outfile<<salary;
cout<<"密码:";
cin>>key;
outfile<<key;
outfile.close();
}
Employee::~Employee()
{
cout<<"退出成功!"<<endl;
Sleep(1000);
system("cls");
}
#include <iostream.h>
#include <string.h>
#include <fstream.h>
#include <stdlib.h>
#include "emp.h"
int main()
{
int i;
Employee emp[n]={
Employee("赵衡","男","15957158000","西湖区留下路280号","123456",20150101,"人力资源部",7800),
Employee("钱方","男","15957158001","西湖区留下路272号","123456",20150102,"财政管理部",7500)
};
ofstream outfile;
outfile.open("employee.dat",ios::out|ios::binary);
if(!outfile)
{
cerr<<"open error!"<<endl;
exit(1);
}
for(i=0;i<n;i++)
outfile.write((char*)&emp[i],sizeof(emp[i])); //向磁盘文件输出所有职工信息
outfile.close();
}