溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

怎么用C語言實現(xiàn)職工工資管理系統(tǒng)

發(fā)布時間:2022-02-28 09:08:40 來源:億速云 閱讀:195 作者:iii 欄目:開發(fā)技術(shù)

本文小編為大家詳細(xì)介紹“怎么用C語言實現(xiàn)職工工資管理系統(tǒng)”,內(nèi)容詳細(xì),步驟清晰,細(xì)節(jié)處理妥當(dāng),希望這篇“怎么用C語言實現(xiàn)職工工資管理系統(tǒng)”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學(xué)習(xí)新知識吧。

設(shè)計要求:

模擬并設(shè)計一個企業(yè)的職工工資管理系統(tǒng),職工信息包括工號、姓名、基本工資、津貼,設(shè)職工人數(shù)不超過500人,以菜單選項的方式完成相應(yīng)的功能,主要功能需求如下:

1、建立工資表;

2、職工扣稅和實發(fā)工資;

3、按實發(fā)工資從高到低的順序顯示工資明細(xì)表;

4、修改職工的工資信息;

5、按工號查詢職工工資信息;

6、職工工資統(tǒng)計分析;

7、退出系統(tǒng)。

基本思路:

將職工工資管理系統(tǒng)的職工信息錄入功能、數(shù)據(jù)處理并存入文件功能、按照職工工號查找職工工資信息功能、修改職工信息功能分成多個模塊,為了使程序的可讀性更強,程序的編寫將以函數(shù)形式編寫封裝各個功能,然后在主函數(shù)中以循環(huán)形式讀取用戶輸入的指令,根據(jù)用戶的指令選擇不同的函數(shù)入口地址,從而執(zhí)行不同的操作,實現(xiàn)設(shè)計要求的職工工資管理系統(tǒng)的各項功能。

全部代碼:

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


#define Q 15               //最大字符串長度 
#define N 500              //最大員工數(shù)量 


typedef struct workers{
    int workersID;            //職工工號
    char name[Q];             //職工姓名
    double basicsalary;       //基本工資
    double allowance;         //津貼
    double taxsalary;         //扣稅
    double truesalary;        //實發(fā)工資
}WORKERS;                     //職工信息


void Menu(int *n);                               //主菜單 
void Payroll(WORKERS work[],int *p);             //建立工資表 
void Taxsalary(WORKERS work[],int num);          //計算職工扣稅和實發(fā)工資
void Sort(WORKERS work[],int num ) ;             //將工資從高到低排序
void Change(WORKERS work[],int num);             //修改職工的工資信息
int Find(WORKERS work[],int num);                //按工號查詢職工工資信息
void Analyse(WORKERS work[],int num);            //職工工資統(tǒng)計分析 
void Printworkroll(WORKERS work[],int num);      //顯示工資明細(xì)表
void Writefile(WORKERS work[],int num);          //輸出數(shù)據(jù)并寫入 data.txt 文件 

    
int main()
{   
    WORKERS work[N];                             //定義一個結(jié)構(gòu)體數(shù)組來存儲員工信息 
    char ch;                                     //ch為檢測是否返回主菜單 
    int n,num=0,ret;                             //n為操作數(shù),num為總?cè)藬?shù),ret判斷數(shù) 
    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);             //職工扣稅和實發(fā)工資
                Writefile(work,num);             //輸出數(shù)據(jù)并寫入 data.txt 文件 
                printf("計算完成,并輸出數(shù)據(jù)至txt文件!\n");
                Sleep(2000);
                system("cls");
                break;
            case 3:
                Sort(work,num);                  //將工資從高到低排序
                Printworkroll(work,num);         //顯示工資明細(xì)表
                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);               //職工工資統(tǒng)計分析
                printf("\n是否返回主菜單?Y or N\n");
                fflush(stdin);
                ch=getchar();
                if(ch=='N'){
                    exit(0);
                }
                break;
        }
    }
    return 0;
}


void Menu(int *n)                                 //主菜單   *n為返回操作數(shù) 
{
    int a;
    printf(" ——————職工工資管理系統(tǒng)——————\n");
    printf("|       1.建立職工工資表                 |\n");
    printf("|       2.職工扣稅和實發(fā)工資             |\n");
    printf("|       3.實發(fā)工資從高到低排序           |\n");
    printf("|       4.修改職工工資信息               |\n");
    printf("|       5.查詢職工工資信息               |\n");
    printf("|       6.職工工資統(tǒng)計分析               |\n");
    printf("|       0.退出系統(tǒng)                       |\n");
    printf(" ————————————————————\n");
    printf("提示:請輸入數(shù)字序號選擇對應(yīng)的操作!\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("是否繼續(xù)錄入?Y or N\n"); 
        fflush(stdin);
        scanf("%c",&ch);
        num++;
    }while(ch=='Y');
    
    *p=num;      //返回總?cè)藬?shù) 
    system("cls");
}


void Taxsalary(WORKERS work[],int num)            //職工扣稅和實發(fā)工資
{
    
    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("實發(fā)工資:%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("實發(fā)工資:%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)                 //查詢輸入的工號并調(diào)用信息; 
        {
            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("實發(fā)工資:%.2lf\n",work[i].truesalary); 
            break;
        }
    }
    return flag;
}


void Analyse(WORKERS work[],int num)              //職工工資統(tǒng)計分析
{
    int i,s=0,m=0,l=0;      //s表示工資小于3000的人數(shù);m表示工資在3000到4000的人數(shù);l表示工資大于4000的人數(shù)。 
    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("實發(fā)工資\n");
    printf("(3000元以下)        人數(shù):%d\t比例:%.2lf%%\n",s,x);              
    printf("(3000以上4000以下)  人數(shù):%d\t比例:%.2lf%%\n",m,y);     
    printf("(4000以上)          人數(shù):%d\t比例:%.2lf%%\n",l,z);     
    
}


void Printworkroll(WORKERS work[],int num)        //顯示工資明細(xì)表
{
    printf("工號\t姓名\t基本工資\t津貼\t扣稅\t實發(fā)工資\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)            //輸出數(shù)據(jù)并寫入 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,"職工工資管理系統(tǒng)\n成功錄入%d人\n詳表如下:\n\n",num);
    fprintf(fp,"工號\t姓名\t基本工資\t津貼\t扣稅\t實發(fā)工資\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語言實現(xiàn)職工工資管理系統(tǒng)”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識點還需要大家自己動手實踐使用過才能領(lǐng)會,如果想了解更多相關(guān)內(nèi)容的文章,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI