求解释 。这个程序错哪里了。
#include<iostream>#include<fstream>
#include<string>
#include<iomanip>
#include"conio.h"
using namespace std;
void zhuye(string user);
string username="";
void insert();
void update();
void del();
void select();
void cont();
void add();
bool contain(char* ch,fstream &file);
bool contain2(char* ch,fstream &file);
float getam2(float bm,int am);
char* getfname(fstream &file,char* ch);
long getl(fstream &file);
long getl2(fstream &file);
long getl3(char *c,fstream &file);
long l1,l2;
int error=0;
int i2=0;
int i3=0;
fstream iofile;
fstream iofile2;
//职工工资信息
class worker
{
public:
worker();
worker(int a){}
char* getno(){return no;}
char* getname(){return name;}
float getbm(){return bmoney;}
float getam(){return amoney;}
void setbm(float fl){bmoney=fl;}
void setdel(bool bb){b=bb;}
void setmmoney(float fl){mmoney=fl;}
void setamoney(float fl){amoney=fl;}
bool b;
int title;
private:
char no[5];
char name[7];
float bmoney;
float amoney;
float mmoney;
};
worker::worker()
{
b=true;
int x=0;
title=1;
cout<<"请输入第"<<i2+1<<"个"<<"职工号:";
cin>>no;
do{
if(x!=0)
{
system("cls");
cout<<"工资低于底薪5000,请重新输入工资:"<<endl;
}
cout<<"请输入第"<<i2+1<<"个"<<"职工工资额:";
cin>>bmoney;
x++;
}while(bmoney<5000);
mmoney=bmoney-5000; //应纳税所得额
amoney=getam2(mmoney,bmoney); //税后所得工资
strcpy(name,getfname(iofile2,no));
//cout<<name<<"-----";
}
//职工个人信息
class worker2
{
public:
worker2();
worker2(int a){}
char* getn();
char* getname();
private:
char name[7];
char no[5];
};
worker2::worker2()
{
cout<<"请输入第"<<i3+1<<"个"<<"职工号:";//职工号不能重复!!还要有权限
fflush(stdin);
cin>>no;
cout<<"请输入第"<<i3+1<<"个"<<"职工姓名:";
fflush(stdin);
cin>>name;
}
char* worker2::getn(){return no;}
char* worker2::getname(){return name;}
//主函数
int main()
{
zhuye();
return 0;
}
//主页
void zhuye(string user)
{
while(true)
{
system("cls");
iofile.open("work.txt",ios::in|ios::out);
iofile2.open("workinfo.txt",ios::in|ios::out);
if(!iofile||!iofile2)
{
cout<<"cuole";
}
username=user;
cout<<"当前用户: "<<username<<endl;
cout<<endl;
cout<<" 1.录入职工信息"<<endl;
cout<<" 2.计算税金"<<endl;
cout<<" 3.添加职工信息"<<endl;
cout<<" 4.删除职工信息"<<endl;
cout<<" 5.按职工编号进行信息查询"<<endl;
cout<<" 6.按个人所得税排序"<<endl;
cout<<" 7.退出"<<endl;
cout<<endl;
char x;
cout<<"请选择你要执行的功能:";
cin>>x;
switch(x)
{
case '1':
insert();
break;
case '2':
update();
break;
case '3':
del();
break;
case '4':
select();
break;
case '5':
add();
break;
case '6':
exit(1);
break;
case '7':
exit(1);
break;
default:
cout<<"请输入1——7的数字!";
for(int i=0;i<100000000;i++){}
iofile.close();
iofile2.close();
break;
}
}
}
//添加职工工资信息
void insert()
{
int size=0;
i2=0;
char e,e2,n,f;
system("cls");
iofile<<left;
cout<<"请输入你要添加职工信息的数目:";
cin>>size;
// while(i2<size)
// {
do
{
l1=getl(iofile);
l2=getl2(iofile2);//有contain,worker的地方都要用
worker work;
if(contain(work.getno(),iofile2))
{
if(contain2(work.getno(),iofile))
{
cout<<"此前已有"<<work.getname()<<"的工资信息!"<<endl;
cout<<"覆盖原来信息输'f',添加输't',退出输'n',其他任意键回主页:";
cin>>f;
if(f=='t')
{
iofile.seekp(0,ios::end);
iofile.write((char*)&work,sizeof(work));
i2++;
if(i2==size)
break;
}
else if(f=='n')
{
exit(1);
}
else if(f=='f')
{
long l=getl3(work.getno(),iofile);
cout<<l/sizeof(work);
iofile.seekg(l);
iofile.write((char*)&work,sizeof(work));
i2++;
if(i2==size)
break;
}
else
{
iofile.close();
iofile2.close();
return;
}
}
else
{
iofile.seekp(0,ios::end);
iofile.write((char*)&work,sizeof(work));
i2++;
if(i2==size)
break;
}
}
else
{
cout<<"没有此号,请确认输入无误!继续输入输'y'"<<endl<<"添加用户输入't',退出输'n',其他任意键回主页:";
cin>>n;
if(n=='n')
{
exit(1);
}
else if(n=='t')
{
add();
return;
}
else if(n=='y')
{
system("cls");
cout<<"请继续输入:"<<endl;
// i2++;
}
else
{
iofile.close();
iofile2.close();
return;
}
}
}while(n=='y'||i2<size);
// }
cout<<"是否还要添加职工工资信息?"<<endl;
cout<<" 若要继续请输'Y',退出输'N',回主页输其他任意键:"<<endl;
cin>>e;
if(e=='y'||e=='Y')
{
cout<<"请继续添加职工工资信息"<<endl;
do
{
worker work2;
if(contain(work2.getno(),iofile2))
{
cout<<"有";
iofile.write((char*)&work2,sizeof(work2));
cout<<"继续添加输'y',推出输'N',回主页输其他任意键:"<<endl;
cin>>e2;
}else
{
cout<<"没有";
}
}while(e2=='y'||e2=='Y');
if(e2=='n'||e2=='N')
{
exit(1);
}
else
{
iofile.close();
iofile2.close();
return;
}
}
else if(e=='n'||e=='N')
{
iofile.close();
iofile2.close();
exit(1);
}
else{
iofile.close();
iofile2.close();
return;
}
}
void update()
{
system("cls");
// int length=getl(iofile);
char c[5],e,e2;
float fl;
int byte=0;
worker work(1);
cout<<"请输入您要修改的号码:";
cin>>c;
iofile.seekg(0);
iofile.read((char *)&work,sizeof(work));
while(!iofile.eof())
{
if(strcmp(c,work.getno())==0)
{
break;
}
iofile.read((char *)&work,sizeof(work));
byte++;
}
cout<<"请输入要修改的工资:";
cin>>fl;
work.setbm(fl);
work.setmmoney(fl-1600);
work.setamoney(getam2(fl-1600,fl));
iofile.seekp(byte*sizeof(work));
iofile.write((char *)&work,sizeof(work));
cout<<"是否还要修改职工工资信息?"<<endl;
cout<<" 若要继续请输'Y',退出输'N',回主页输其他任意键:"<<endl;
cin>>e;
if(e=='y'||e=='Y')
{
cout<<"请继续输入您要修改的号码:";
cin>>c;
iofile.seekg(0);
while(!iofile.eof())
{
iofile.read((char *)&work,sizeof(work));
if(strcmp(c,work.getno())==0)
{
break;
}
byte++;
}
cout<<"请输入要修改的工资:";
cin>>fl;
work.setbm(fl);
work.setmmoney(fl-1600);
work.setamoney(getam2(fl-1600,fl));
iofile.seekp(byte*sizeof(work));
iofile.write((char *)&work,sizeof(work));
cout<<"继续修改输'y',退出输'N',回主页输其他任意键:"<<endl;
cin>>e2;
while(e2=='y'||e2=='Y');
if(e2=='n'||e2=='N')
{
exit(1);
}
else
{
iofile.close();
iofile2.close();
return;
}
}
else if(e=='n'||e=='N')
{
exit(1);
}
else{
iofile.close();
iofile2.close();
return;
}
}
void del()
{
system("cls");
int length=getl(iofile);
char c[5],e,e2;
int byte=0;
worker work(1);
cout<<"请输入您要删除的号码:";
cin>>c;
iofile.seekg(0);
while(!iofile.eof())
{
iofile.read((char *)&work,sizeof(work));
if(strcmp(c,work.getno())==0)
{
break;
}
}
byte=iofile.tellg()/sizeof(work)-1;
/* work.setdel(false);
iofile.seekp(byte*sizeof(work));
iofile.write((char *)&work,sizeof(work));*/
while(!iofile.eof())
{
iofile.seekg((byte+1)*sizeof(work));
iofile.read((char *)&work,sizeof(work));
iofile.seekp(byte*sizeof(work));
iofile.write((char *)&work,sizeof(work));
byte++;
if(byte+1==length)
break;
}
iofile.seekp(-sizeof(work),ios::end);
for(int l=0;l<sizeof(work);l++)
{
iofile.put(NULL);
}
cout<<"删除成功!"<<endl;
cout<<"是否还要删除职工工资信息?"<<endl;
cout<<" 若要继续请输'Y',退出输'N',回主页输其他任意键:"<<endl;
cin>>e;
if(e=='y'||e=='Y')
{
cout<<"请继续删除职工工资信息"<<endl;
do
{
cout<<"请输入您要删除的号码:";
cin>>c;
iofile.seekg(0);
while(!iofile.eof())
{
iofile.read((char *)&work,sizeof(work));
if(strcmp(c,work.getno())==0)
{
break;
}
}
byte=iofile.tellg()/sizeof(work)-1;
while(!iofile.eof())
{
iofile.seekg((byte+1)*sizeof(work));
iofile.read((char *)&work,sizeof(work));
iofile.seekp(byte*sizeof(work));
iofile.write((char *)&work,sizeof(work));
byte++;
if(byte+1==length)
break;
}
iofile.seekp(-sizeof(work),ios::end);
for(int l=0;l<sizeof(work);l++)
{
iofile.put(NULL);
}
cout<<"删除成功"<<endl;
cout<<"继续删除输'y',退出输'N',回主页输其他任意键:"<<endl;
cin>>e2;
}while(e2=='y'||e2=='Y');
if(e2=='n'||e2=='N')
{
exit(1);
}
else
{
iofile.close();
iofile2.close();
return;
}
}
else if(e=='n'||e=='N')
{
exit(1);
}
else{
iofile.close();
iofile2.close();
return;
}
}
//按员工编号进行信息查询
void select()
{
char c,type;
do
{
system("cls");
char n[5];
char name[7];
cout<<left;
long l=getl(iofile);
worker work(1);
{ system("cls");
cout<<"请输入要查询的职工编号:";
cin>>n;
long tl=getl3(n,iofile);
iofile.seekg(tl);
iofile.read((char*)&work,sizeof(work));
cout<<setw(7)<<"号码"<<setw(9)<<"姓名"<<setw(16)<<"税前工资"<<setw(16)<<"税后工资"<<endl;
iofile.seekg(0,ios::beg);
cout<<setw(7)<<work.getno()<<setw(9)<<work.getname()<<setw(16)
<<work.getbm()<<setw(16)<<work.getam()<<endl;
cout<<"退出输'n',回主页输其他任意键:";
cin>>c;
if(c=='n'||c=='N')
{
exit(1);
}else
{
iofile.close();
iofile2.close();
return;
}
}
//添加职工基本信息
void add()
{
int size=0;
i3=0;
char e,e2;
system("cls");
iofile2.seekp(0,ios::end);
iofile<<left;
cout<<" 欢迎进入添加职工成员!"<<endl;
cout<<"请输入你要添加职工信息的数目:";
cin>>size;
while(i3<size)
{
worker2 work2;
iofile2.write((char*)&work2,sizeof(work2));
i3++;
}
cout<<"是否还要添加职工信息?"<<endl;
cout<<" 若要继续请输'Y',退出输'N',回主页输其他任意键:"<<endl;
cin>>e;
if(e=='y'||e=='Y')
{
cout<<"请继续添加职工信息"<<endl;
do
{
worker2 work2;
iofile2.write((char*)&work2,sizeof(work2));
cout<<"继续添加输'y',推出输'N',回主页输其他任意键:"<<endl;
cin>>e2;
}while(e2=='y'||e2=='Y');
if(e2=='n'||e2=='N')
{
exit(1);
}
else
{
iofile.close();
iofile2.close();
return;
}
}
else if(e=='n'||e=='N')
{
exit(1);
}
else{
iofile.close();
iofile2.close();
return;
}
}
//判断用户有无
bool contain(char* ch,fstream &file)
{
worker2 work(1);
file.seekg(0);
int flag=0;
for(int i=0;i<l2;i++)
{
file.read((char*)&work,sizeof(work));
if(strcmp(ch,work.getn())==0)
{
flag=1;
break;
}
}
if(flag==1)
{
return true;
}
else
{
return false;
}
}
//获取数目
long getl(fstream &file)
{
file.seekg(0,ios::end);
worker work(1);
return (file.tellg())/sizeof(work);
}
long getl2(fstream &file)
{
file.seekg(0,ios::end);
worker2 work(1);
return (file.tellg())/sizeof(work);
}
//获取位置
long getl3(char *c,fstream &file)
{
worker work(1);
file.seekg(0);
for(int i=0;i<l1;i++)
{
file.read((char *)&work,sizeof(work));
if(strcmp(c,work.getno())==0)
break;
}
return file.tellg()-(long)sizeof(work);
}
//判断是否已有工资信息
bool contain2(char* ch,fstream &file)
{
worker work(1);
file.seekg(0);
int flag=0;
for(int i=0;i<l1;i++)
{
file.read((char*)&work,sizeof(work));
if(strcmp(ch,work.getno())==0)
{
flag=1;
break;
}
}
if(flag==1)
{
return true;
}
else
{
return false;
}
}
//获取职工税后工资
float getam2(float bm,int am)
{
if(bm<=8000)
{
return am-bm*5/100;
}
else if(bm<=10000)
{
return am-3000*5/100-(bm-3000)*10/100;
}
else if(bm<=12000)
{
return am-3000*5/100-2000*10/100-(bm-5000)*15/100;
}
else
{
return am-3000*5/100-2000*10/100-2000*15/100-(bm-7000)*20/100;
}
}
测试的时候 错误是这样的 。求具体改法。我初学 麻烦说浅显点。
12.cpp
c:\users\chenxuewei\appdata\local\temp\rar$ex06.840\vc6\myprojects\1\12.cpp(681) : fatal error C1010: unexpected end of file while looking for precompiled header directive
Generating Code...