有关***.exe已停止运行。十万火急!!求各路大神相助!

cittitt 2016-06-28 07:36:06
一个职工工资管理系统,定义好了类,在主程序里面创建一个二进制文件,但是在程序运行一开始就出现说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();
}

...全文
205 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
小灸舞 2016-06-29
  • 打赏
  • 举报
回复
Windows: 崩溃的时候在弹出的对话框按相应按钮进入调试,按Alt+7键查看Call Stack里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处。 Linux: 进程意外退出会在当前目录下产生‘core’文件或形如‘core.数字’的文件比如‘core.1234’ 使用命令 gdb 运行程序名 core或core.数字 进入gdb然后使用bt命令 可以查看进程意外退出前函数调用的堆栈,内容为从上到下列出对应从里层到外层的函数调用历史。 如果进程意外退出不产生core文件,参考“ulimit -c core文件最大块大小”命令 代码功能归根结底不是别人帮自己看或讲解或注释出来的;而是被自己静下心来花足够长的时间和精力亲自动手单步或设断点或对执行到某步获得的中间结果显示或写到日志文件中一步一步分析出来的。 提醒:再牛×的老师也无法代替学生自己领悟和上厕所! 单步调试和设断点调试(VS IDE中编译连接通过以后,按F10或F11键单步执行,按Shift+F11退出当前函数;在某行按F9设断点后按F5执行停在该断点处。)是程序员必须掌握的技能之一。
renwotao2009 2016-06-28
  • 打赏
  • 举报
回复
调试模式运行
super_admi 2016-06-28
  • 打赏
  • 举报
回复
好长,好乱,好难看。
yshuise 2016-06-28
  • 打赏
  • 举报
回复
把char通通改成string 把windows.h提到头文件最前。

64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧