| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 683 人关注过本帖
标题:请大家帮帮忙!我实在想不出了……
只看楼主 加入收藏
_下一站521
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2011-12-21
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:2 
请大家帮帮忙!我实在想不出了……
题目: 创建职工人事基本信息文件,根据提示输入职工的各项信息,按职工编号对职工信息进行排序,并将排序后的职工信息存储到一个文件中。
2. 创建职工的工资信息文件,其中职工编号和姓名从人事信息文件中拷贝,其他工资组成项目按下面方法计算:
职务工资:助工=1270*(1+任职年限*2%);    工程师=2360*(1+任职年限*3%);
高级工程师=3450*(1+任年限*5%)
职务补贴=职务工资*25%               住房补贴=(职务工资+职务补贴)*15%
应发工资=职务工资+职务补贴+住房补贴
个人所得税=(应发工资-3000)*5%         养老保险=(职务工资+职务补贴)*10%
住房公积金=应发工资*5%
实发工资=应发工资-个人所得税-养老保险-住房公积金

#include <stdio.h>
#include <string.h>  
#include <stdlib.h>  
#define E 3
void creat();
void creat2();
void pai();
void put();
int number;
struct employee
{
    char num[5];
    char name[10];
    char sex[3];
    char shengri[10];
    char degree[10];
int  nianxian;
} emp[E];   
struct emp_gong
{
    char num[5];
    char name[10];
    float zhiwugongzi,zhiwubutie,zhufangbutie,yingfagongzi,gerensuodeshui,yanglaobaoxian,zhufanggongjijin,shifagongzi;
}emp_gongzi[E];


void main ()
{   
    put();
    creat();
    creat2();
    pai();
}
 void creat()
{
    FILE *fp;
    int i,j;

    printf("创建【一】基本信息文件.....\n");
    printf("    请您输入创建人数:");
    scanf("%d",&number);

    if ((fp = fopen("number.dat", "wb+")) == NULL)
    {
        printf("Can't open file\n");
        exit(0);
    }
    fwrite(&number,sizeof(int),1,fp);
    fclose(fp);

    if ((fp = fopen("employee.dat", "wb+")) == NULL)
    {
        printf("Can't open file\n");
        exit(0);
    }
    printf("        编号    姓名    性别    出生日期          职称          工作年限     \n");
    for (i=0;i<number;i++)
    {
        j=i+1;
        printf("->【%d】",j);
    scanf("        %s    %s    %s    %s          %s          %d",emp[i].num,emp[i].name,emp[i].sex,emp[i].shengri,emp[i].degree,&emp[i].nianxian);
        printf("\n");
    }
   
    pai();
    fwrite(emp,sizeof(struct employee),number, fp);
    fclose(fp);

    if ((fp = fopen("employee.dat", "rb+")) == NULL)
    {
        printf("Can't open file\n");
        exit(0);
    }
    printf(" 创建成功!!\n");
    printf("        编号    姓名    性别    出生日期          职称          工作年限\n");
    for (i = 0; fread(&emp[i],sizeof(struct employee),1,fp) == 1 ; i++)
    {
    printf("        %s        %s       %s        %s           %s             %d\n",emp[i].num,emp[i].name,emp[i].sex,emp[i].shengri,emp[i].degree,emp[i].nianxian);
    }
    fclose(fp);
}
void pai()      //排序
{
int i,j;
int t;
char  temp[10];
for (i=0;i<number;i++)
{
for (j=i+1;j<number;j++)
{
if (strcmp(emp[i].num,emp[j].num)>0)
{
strcpy(temp, emp[i].num);
strcpy(emp[i].num,emp[j].num);
strcpy( emp[j].num,temp);

strcpy(temp, emp[i].name);
strcpy(emp[i].name,emp[j].name);
strcpy(emp[j].name,temp);

strcpy(temp, emp[i].sex);
strcpy(emp[i].sex,emp[j].sex);
strcpy( emp[j].sex,temp);

strcpy(temp, emp[i].shengri);
strcpy(emp[i].shengri,emp[j].shengri);
strcpy( emp[j].shengri,temp);

strcpy(temp, emp[i].degree);
strcpy(emp[i].degree,emp[j].degree);
strcpy( emp[j].degree,temp);

t=emp[i].nianxian;
emp[i].nianxian=emp[j].nianxian;
emp[j].nianxian=t;


}
}
}
}
void put()
{
    printf("           ********企业职工工资管理系统********\n");
}         
void creat2()
{
        FILE *fp,*fp2;
        int i ,j;
        char *zhugong="助工";
        char *gongchengshi="工程师";
        char *gaojigongchengshi="高级工程师";
    float zhiwugongzi,zhiwubutie,zhufangbutie,yingfagongzi,gerensuodeshui,yanglaobaoxian,zhufanggongjijin,shifagongzi;


 printf("创建【二】工资信息文件.....\n");
 printf("      共创建人数:%d\n",number);
if ((fp = fopen("employee.dat", "rb")) == NULL)
{
printf("Can't open file\n");
exit(0);
}
fread(emp,sizeof(struct employee),number, fp);
if ((fp2= fopen("emp_gong.dat", "wb")) == NULL)
{
printf("Can't open file\n");
exit(0);
}
for (i=0;i<number;i++)
{
j=i+1;
strcpy(emp_gongzi[i].name, emp[i].name);
strcpy(emp_gongzi[i].num, emp[i].num);
float zhiwugongzi,zhiwubutie,zhufangbutie,kaoqin,yingfagongzi,yanglaobaoxian,zhufanggongjijin,shifagongzi;
if (strcmp(emp[i].degree,zhugong) == 0)
{
    zhiwugongzi=1270*(1+(emp[i].nianxian*2)/100);
    zhiwubutie=zhiwugongzi*25/100;
    zhufangbutie=(zhiwugongzi+zhiwubutie)*15/100;
    yingfagongzi=zhiwugongzi+zhiwubutie+zhufangbutie;
    gerensuodeshui=(yingfagongzi-3000)*5/100;
    yanglaobaoxian=(zhiwugongzi+zhiwubutie)*0.1;
    zhufanggongjijin=yingfagongzi*0.05;
    shifagongzi=yingfagongzi-gerensuodeshui-yanglaobaoxian-zhufanggongjijin;
    emp_gongzi[i].zhiwugongzi=zhiwugongzi;
    emp_gongzi[i].zhiwubutie=zhufangbutie;
    emp_gongzi[i].zhufangbutie=zhufangbutie;
    emp_gongzi[i].yingfagongzi=yingfagongzi;
    emp_gongzi[i].yanglaobaoxian=yanglaobaoxian;
    emp_gongzi[i].zhufanggongjijin=zhufanggongjijin;
    emp_gongzi[i].shifagongzi=shifagongzi;

}
if (strcmp(emp[i].degree,gongchengshi) == 0)
{
     zhiwugongzi=2360*(1+(emp[i].nianxian*3)/100);
     zhiwubutie=zhiwugongzi*25/100;
     zhufangbutie=(zhiwugongzi+zhiwubutie)*15/100;
     yingfagongzi=zhiwugongzi+zhiwubutie+zhufangbutie;
     gerensuodeshui=(yingfagongzi-3000)*5/100;
     yanglaobaoxian=(zhiwugongzi+zhiwubutie)*0.1;
     zhufanggongjijin=yingfagongzi*0.05;
     shifagongzi=yingfagongzi-gerensuodeshui-yanglaobaoxian-zhufanggongjijin;
     emp_gongzi[i].zhiwugongzi=zhiwugongzi;
     emp_gongzi[i].zhiwubutie=zhufangbutie;
     emp_gongzi[i].zhufangbutie=zhufangbutie;
     emp_gongzi[i].yingfagongzi=yingfagongzi;
     emp_gongzi[i].yanglaobaoxian=yanglaobaoxian;
     emp_gongzi[i].zhufanggongjijin=zhufanggongjijin;
     emp_gongzi[i].shifagongzi=shifagongzi;

}
if (strcmp(emp[i].degree,gaojigongchengshi) == 0)
{
     zhiwugongzi=3450*(1+(emp[i].nianxian*5)/100);
    zhiwubutie=zhiwugongzi*25/100;
     zhufangbutie=(zhiwugongzi+zhiwubutie)*15/100;
     yingfagongzi=zhiwugongzi+zhiwubutie+zhufangbutie;
     gerensuodeshui=(yingfagongzi-3000)*5/100;
     yanglaobaoxian=(zhiwugongzi+zhiwubutie)*0.1;
     zhufanggongjijin=yingfagongzi*0.05;
     shifagongzi=yingfagongzi-gerensuodeshui-yanglaobaoxian-zhufanggongjijin;
     emp_gongzi[i].zhiwugongzi=zhiwugongzi;
     emp_gongzi[i].zhiwubutie=zhufangbutie;
     emp_gongzi[i].zhufangbutie=zhufangbutie;
     emp_gongzi[i].yingfagongzi=yingfagongzi;
     emp_gongzi[i].yanglaobaoxian=yanglaobaoxian;
     emp_gongzi[i].zhufanggongjijin=zhufanggongjijin;
     emp_gongzi[i].shifagongzi=shifagongzi;
}
printf("\n");
}
fwrite(emp_gongzi, sizeof(struct emp_gong),number, fp2);
fclose(fp);
fclose(fp2);
if ((fp = fopen("emp_gong.dat", "rb+")) == NULL)
{
printf("Can't open file\n");
exit(0);
}
printf(" 自动创建成功!!\n\n\n");
for (i = 0; fread(&emp_gongzi[i],sizeof(struct emp_gong),1,fp) == 1 ; i++)
{
printf("编号%s   姓名%s   职务工资%f   职务补贴%f   住房补贴%f\n    应发工资%f    个人所得税%f    养老保险%f    住房公积金%f    实发工资%f\n",emp_gongzi[i].num,emp_gongzi[i].name,
       emp_gongzi[i].zhiwugongzi,emp_gongzi[i].zhiwubutie, emp_gongzi[i].zhufangbutie,
       emp_gongzi[i].yingfagongzi,emp_gongzi[i].gerensuodeshui,emp_gongzi[i].yanglaobaoxian, emp_gongzi[i].zhufanggongjijin,
       emp_gongzi[i].shifagongzi);
printf("\n\n\n");
}
fclose(fp);
}
void pai()      //排序
{
int i,j;
int t;
char  temp[10];
for (i=0;i<number;i++)
{
for (j=i+1;j<number;j++)
{
if (strcmp(emp[i].num,emp[j].num)>0)
{
strcpy(temp, emp[i].num);
strcpy(emp[i].num,emp[j].num);
strcpy( emp[j].num,temp);

strcpy(temp, emp[i].name);
strcpy(emp[i].name,emp[j].name);
strcpy(emp[j].name,temp);

strcpy(temp, emp[i].sex);
strcpy(emp[i].sex,emp[j].sex);
strcpy( emp[j].sex,temp);

strcpy(temp, emp[i].shengri);
strcpy(emp[i].shengri,emp[j].shengri);
strcpy( emp[j].shengri,temp);

strcpy(temp, emp[i].degree);
strcpy(emp[i].degree,emp[j].degree);
strcpy( emp[j].degree,temp);

t=emp[i].nianxian;
emp[i].nianxian=emp[j].nianxian;
emp[j].nianxian=t;


}
}
}
}
    提示错误如下:D:\360Rec\4\4.cpp(172) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
D:\360Rec\4\4.cpp(177) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
D:\360Rec\4\4.cpp(178) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
D:\360Rec\4\4.cpp(191) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
D:\360Rec\4\4.cpp(196) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
D:\360Rec\4\4.cpp(197) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
D:\360Rec\4\4.cpp(210) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
D:\360Rec\4\4.cpp(215) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
D:\360Rec\4\4.cpp(216) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
D:\360Rec\4\4.cpp(148) : warning C4101: 'zhufangbutie' : unreferenced local variable
D:\360Rec\4\4.cpp(148) : warning C4101: 'zhiwugongzi' : unreferenced local variable
D:\360Rec\4\4.cpp(148) : warning C4101: 'yingfagongzi' : unreferenced local variable
D:\360Rec\4\4.cpp(148) : warning C4101: 'zhufanggongjijin' : unreferenced local variable
D:\360Rec\4\4.cpp(148) : warning C4101: 'shifagongzi' : unreferenced local variable
D:\360Rec\4\4.cpp(148) : warning C4101: 'yanglaobaoxian' : unreferenced local variable
D:\360Rec\4\4.cpp(148) : warning C4101: 'zhiwubutie' : unreferenced local variable
D:\360Rec\4\4.cpp(169) : warning C4101: 'kaoqin' : unreferenced local variable
D:\360Rec\4\4.cpp(248) : error C2084: function 'void __cdecl pai(void)' already has a body
执行 cl.exe 时出错.

4.exe - 1 error(s), 0 warning(s)
 
还有那个年限的排序不太对,不知道应该怎么弄!
搜索更多相关主题的帖子: 养老保险 职务 项目 所得税 
2012-08-30 13:03
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:10 
从编译错误来看最大的问题是你这里面有两个函数都叫pai() 不知道这是俩函数还是一个函数写了两遍 反正重名肯定不对
2012-08-30 13:21
_下一站521
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2011-12-21
收藏
得分:0 
回复 2楼 zklhp
谢谢哈~
2012-08-30 21:16
快速回复:请大家帮帮忙!我实在想不出了……
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030482 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved