温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么用C语言实现职工工资管理系统

发布时间:2022-02-28 09:08:40 来源:亿速云 阅读:198 作者:iii 栏目:开发技术

本文小编为大家详细介绍“怎么用C语言实现职工工资管理系统”,内容详细,步骤清晰,细节处理妥当,希望这篇“怎么用C语言实现职工工资管理系统”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。

设计要求:

模拟并设计一个企业的职工工资管理系统,职工信息包括工号、姓名、基本工资、津贴,设职工人数不超过500人,以菜单选项的方式完成相应的功能,主要功能需求如下:

1、建立工资表;

2、职工扣税和实发工资;

3、按实发工资从高到低的顺序显示工资明细表;

4、修改职工的工资信息;

5、按工号查询职工工资信息;

6、职工工资统计分析;

7、退出系统。

基本思路:

将职工工资管理系统的职工信息录入功能、数据处理并存入文件功能、按照职工工号查找职工工资信息功能、修改职工信息功能分成多个模块,为了使程序的可读性更强,程序的编写将以函数形式编写封装各个功能,然后在主函数中以循环形式读取用户输入的指令,根据用户的指令选择不同的函数入口地址,从而执行不同的操作,实现设计要求的职工工资管理系统的各项功能。

全部代码:

#include <stdio.h> 
#include <stdlib.h>
#include <math.h>
#include <windows.h>


#define Q 15               //最大字符串长度 
#define N 500              //最大员工数量 


typedef struct workers{
    int workersID;            //职工工号
    char name[Q];             //职工姓名
    double basicsalary;       //基本工资
    double allowance;         //津贴
    double taxsalary;         //扣税
    double truesalary;        //实发工资
}WORKERS;                     //职工信息


void Menu(int *n);                               //主菜单 
void Payroll(WORKERS work[],int *p);             //建立工资表 
void Taxsalary(WORKERS work[],int num);          //计算职工扣税和实发工资
void Sort(WORKERS work[],int num ) ;             //将工资从高到低排序
void Change(WORKERS work[],int num);             //修改职工的工资信息
int Find(WORKERS work[],int num);                //按工号查询职工工资信息
void Analyse(WORKERS work[],int num);            //职工工资统计分析 
void Printworkroll(WORKERS work[],int num);      //显示工资明细表
void Writefile(WORKERS work[],int num);          //输出数据并写入 data.txt 文件 

    
int main()
{   
    WORKERS work[N];                             //定义一个结构体数组来存储员工信息 
    char ch;                                     //ch为检测是否返回主菜单 
    int n,num=0,ret;                             //n为操作数,num为总人数,ret判断数 
    while(1){
        system("cls");
        Menu(&n);                                //主菜单 
        
        switch(n){
            case 0:
                system("cls");                   //退出程序 
                printf("退出成功!\n");
                exit(0);
            case 1:
                Payroll(work,&num);              //建立工资表
                break;
            case 2:
                Taxsalary(work,num);             //职工扣税和实发工资
                Writefile(work,num);             //输出数据并写入 data.txt 文件 
                printf("计算完成,并输出数据至txt文件!\n");
                Sleep(2000);
                system("cls");
                break;
            case 3:
                Sort(work,num);                  //将工资从高到低排序
                Printworkroll(work,num);         //显示工资明细表
                printf("\n是否返回主菜单?Y or N\n");
                fflush(stdin);
                ch=getchar();
                if(ch=='N'){
                    exit(0);
                }
                break;
            case 4:
                Change(work,num);                //修改职工的工资信息
                printf("\n是否返回主菜单?Y or N\n");
                fflush(stdin);
                ch=getchar();
                if(ch=='N'){
                    exit(0);
                }
                break;
            case 5:
                ret=Find(work,num);              //按工号查询职工工资信息
                if(ret==0){
                    printf("查无此人!");        //反馈查询不到信息 
                }
                printf("\n是否返回主菜单?Y or N\n");
                fflush(stdin);
                ch=getchar();
                if(ch=='N'){
                    exit(0);
                }
                break;
            case 6:
                Analyse(work,num);               //职工工资统计分析
                printf("\n是否返回主菜单?Y or N\n");
                fflush(stdin);
                ch=getchar();
                if(ch=='N'){
                    exit(0);
                }
                break;
        }
    }
    return 0;
}


void Menu(int *n)                                 //主菜单   *n为返回操作数 
{
    int a;
    printf(" ——————职工工资管理系统——————\n");
    printf("|       1.建立职工工资表                 |\n");
    printf("|       2.职工扣税和实发工资             |\n");
    printf("|       3.实发工资从高到低排序           |\n");
    printf("|       4.修改职工工资信息               |\n");
    printf("|       5.查询职工工资信息               |\n");
    printf("|       6.职工工资统计分析               |\n");
    printf("|       0.退出系统                       |\n");
    printf(" ————————————————————\n");
    printf("提示:请输入数字序号选择对应的操作!\n");
    scanf("%d",&a);
    *n=a;
    system("cls");
}


void Payroll(WORKERS work[],int *p)               //建立工资表 
{
    int num=*p;
    char ch;
    do{
        system("cls");
        printf("员工(%d)的信息\n",num+1);
        printf("工号:");
        scanf("%d",&work[num].workersID);
        printf("姓名:");
        scanf("%s",&work[num].name);
        printf("基本工资:");
        scanf("%lf",&work[num].basicsalary);
        printf("津贴:");
        scanf("%lf",&work[num].allowance);
        printf("是否继续录入?Y or N\n"); 
        fflush(stdin);
        scanf("%c",&ch);
        num++;
    }while(ch=='Y');
    
    *p=num;      //返回总人数 
    system("cls");
}


void Taxsalary(WORKERS work[],int num)            //职工扣税和实发工资
{
    
    int i;
    double money;
    for(i=0;i<num;i++)
    {
        money=work[i].basicsalary+work[i].allowance;
        if( money<3000)
        {
              work[i].taxsalary=0;
             work[i].truesalary= money-work[i].taxsalary;
           }
        else if((money<4000)&&(money>=3000))
        {
            work[i].taxsalary=(money-3000)*0.05;
            work[i].truesalary= money-work[i].taxsalary; 
        }
        else
        { 
            work[i].taxsalary=(money-3000)*0.05+(money-4000)*0.1;
            work[i].truesalary= money-work[i].taxsalary; 
        } 
    }
}


void Sort(WORKERS work[],int num)                 //将工资从高到低排序
{
    int i,j;
    WORKERS temp;
    for (i=0;i<num-1;i++)
    {
        for(j=i+1;j<num;j++)    
        {
            if (work[i].truesalary<work[j].truesalary)
            {
                temp=work[j];
                work[j]=work[i];
                work[i]=temp;
            } 
        }    
    }
} 


void Change(WORKERS work[],int num)               //修改职工的工资信息
{
    int n,sum;
    char ch;
    printf("修改职工的工资信息\n\n");
    printf("请输入你的工号:");
    scanf("%d",&n);
    putchar('\n');
    for(int i=0;i<num;i++){
        if(work[i].workersID==n){
            printf("工号:%-10d\n",work[i].workersID);
            printf("姓名:%s\n",work[i].name); 
            printf("基本工资:%6.2lf\n",work[i].basicsalary); 
            printf("津贴:%6.2lf\n",work[i].allowance); 
            printf("扣税:%6.2lf\n",work[i].taxsalary); 
            printf("实发工资:%6.2lf\n",work[i].truesalary); 
            printf("\n是否需要修改信息?Y or N\n");
            fflush(stdin);
            scanf("%c",&ch);
            if(ch=='Y'){
                printf("\n基本工资:");
                scanf("%lf",&work[i].basicsalary);
                printf("津贴:");
                scanf("%lf",&work[i].allowance);
                sum=work[i].basicsalary+work[i].allowance;
                if(sum<=3000){  
                    work[i].taxsalary=0;
                    work[i].truesalary=sum;
                }
                else if((sum<=4000)&&(sum>3000)){
                    work[i].taxsalary=(sum-3000)*0.05;
                    work[i].truesalary=3000+((sum-3000)*0.95);
                }
                   else{
                    work[i].taxsalary=50+(sum-4000)*0.10;
                    work[i].truesalary=3950+((sum-4000)*0.9);
                }
                system("cls");
                
                printf("员工信息修改成功!\n\n");
                printf("扣税:%6.2lf\n",work[i].taxsalary); 
                printf("实发工资:%6.2lf\n",work[i].truesalary); 
                
                break;    
            }
            else{
                break;
            }    
        }
    }
} 


int Find(WORKERS work[],int num)                  //按工号查询职工工资信息
{
    int s,i,flag=0;
    printf("查询职工工资信息\n\n");
    printf("请输入您的工号:");
    scanf("%d",&s);
    putchar('\n');
    for(i=0;i<num;i++)
    {
        if(work[i].workersID==s)                 //查询输入的工号并调用信息; 
        {
            flag=1; 
            printf("工号:%d\n",work[i].workersID);
            printf("姓名:%s\n",work[i].name); 
            printf("基本工资:%.2lf\n",work[i].basicsalary); 
            printf("津贴:%.2lf\n",work[i].allowance); 
            printf("扣税:%.2lf\n",work[i].taxsalary); 
            printf("实发工资:%.2lf\n",work[i].truesalary); 
            break;
        }
    }
    return flag;
}


void Analyse(WORKERS work[],int num)              //职工工资统计分析
{
    int i,s=0,m=0,l=0;      //s表示工资小于3000的人数;m表示工资在3000到4000的人数;l表示工资大于4000的人数。 
    double x,y,z;
    for(i=0;i<num;i++)
    {
        if(work[i].truesalary<3000)    
        {
            s++;
        }    
        else if((work[i].truesalary<=4000)&&(work[i].truesalary>=3000))
        {
            m++;
        }        
        else
        {
            l++;
        }
    }
    x=(double)s/num*100;
    y=(double)m/num*100;
    z=(double)l/num*100;
    printf("实发工资\n");
    printf("(3000元以下)        人数:%d\t比例:%.2lf%%\n",s,x);              
    printf("(3000以上4000以下)  人数:%d\t比例:%.2lf%%\n",m,y);     
    printf("(4000以上)          人数:%d\t比例:%.2lf%%\n",l,z);     
    
}


void Printworkroll(WORKERS work[],int num)        //显示工资明细表
{
    printf("工号\t姓名\t基本工资\t津贴\t扣税\t实发工资\n");
    for(int i=0;i<num;i++){
        printf("%d\t",work[i].workersID);
        printf("%s\t",work[i].name); 
        printf("   %.2lf\t",work[i].basicsalary); 
        printf("%.2lf\t",work[i].allowance); 
        printf("%.2lf\t",work[i].taxsalary); 
        printf("%.2lf\n",work[i].truesalary); 
    }
}


void Writefile(WORKERS work[],int num)            //输出数据并写入 data.txt 文件
{ 
    WORKERS temp;
    for(int i=0;i<num-1;i++)
    {
        for(int j=i+1;j<num;j++)
        {
            if(work[i].workersID>work[j].workersID)
            {
                temp=work[i];
                work[i]=work[j];
                work[j]=temp;
            }
        }
    }
    
    FILE *fp;
    if((fp=fopen("data.txt","w"))==0){
        printf("错误!\n");
        exit(0);
    }
    fprintf(fp,"职工工资管理系统\n成功录入%d人\n详表如下:\n\n",num);
    fprintf(fp,"工号\t姓名\t基本工资\t津贴\t扣税\t实发工资\n");
    for(int i=0;i<num;i++){
        fprintf(fp,"%-10d\t",work[i].workersID);
        fprintf(fp,"%s\t",work[i].name); 
        fprintf(fp,"%.2lf\t",work[i].basicsalary); 
        fprintf(fp,"%.2lf\t",work[i].allowance); 
        fprintf(fp,"%.2lf\t",work[i].taxsalary); 
        fprintf(fp,"%.2lf\n",work[i].truesalary); 
    }
    fclose(fp);
}

读到这里,这篇“怎么用C语言实现职工工资管理系统”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI