void count()//导入数据
{
fstream iofile;
iofile.open("tax.txt",ios::out|ios::app);
double tax=0;
int salary;
double s;
char name[N];
person s1;
cout<<"请输入姓名: ";
cin>>name;
cout<<"请输入工资:";
cin>>salary;
s=salary-1600;
if(salary>100000)
{
tax=(salary-100000)*0.45+func(100000);
}
else
{
tax=func(s);
}
cout<<"应缴的个人所得税为:"<<tax<<endl;
s1.set_name(name);
s1.set_money(salary);
s1.set_tax(tax);
iofile.write((char*)&s1,sizeof(s1));
} //导入数据void xiugai()
{
int i=0;
char my_name[N];
char new_name[N];
double new_money;
double a;
int b=1;
int flag=0;
person s1;
fstream iofile;
iofile.open("tax.txt",ios::out|ios::in);
cout<<"请输入姓名:";
cin>>my_name;
while(!iofile.eof())
{
iofile.read((char*)&s1,sizeof(s1));
b=strcmp(my_name,s1.get_name());
if(b==0)
{
flag=1;//找到了
cout<<"请输入新名字:";
cin>>new_name;
s1.set_name(new_name);
cout<<"请输入新工资:";
cin>>new_money;
s1.set_money(new_money);
a=s1.get_money();
s1.set_tax(func(a));
iofile.seekp(i*(sizeof(s1)),ios::beg);
iofile.write((char*)&s1,sizeof(s1));
break;
}
else
{
i++;
continue;
}
}
if(iofile.eof()&&flag==0)
{
cout<<"未找到数据!"<<endl;
}
iofile.close();
}//修改数据class person{
private:
double money;
double tax;
char name[N];
public:
person(){ }
void set_money(double a)
{
money=a;
}
void set_tax(double b)
{
tax=b;
}
void set_name(char* pname)
{
strcpy(name,pname);
}
double get_money()
{
return money;
}
double get_tax()
{
return tax;
}
char* get_name()
{
return name;
}
};//类的定义void chaxun()//查询函数
{
char my_name[N];
int a=1;
int flag=0;
person s1;
fstream iofile;
iofile.open("tax.txt",ios::in);
cout<<"请输入姓名:";
cin>>my_name;
while(!iofile.eof())
{
iofile.read((char*)&s1,sizeof(s1));
a=strcmp(my_name,s1.get_name());
if(a==0)
{
flag=1;//找到了
cout<<s1.get_money()<<endl;
cout<<s1.get_tax()<<endl;
break;
}
else
{
continue;
}
}
if(iofile.eof()&&flag==0)
{
cout<<"未找到数据!"<<endl;
}
iofile.close();
}//查询数据如上所示,数据能正常进行导入。但当进行修改的操作时,虽然在文档里看到覆盖掉数据成功,但用函数却查询不到,求分析函数错在哪里,如果要源码可以私我,感激不尽!!
目前暂无任何回答
- 0 回答
- 0 关注
- 1300 浏览
添加回答
举报
0/150
提交
取消