C語言實現(xiàn)小型工資管理系統(tǒng)
本文實例為大家分享了C語言實現(xiàn)小型工資管理系統(tǒng)的具體代碼,供大家參考,具體內容如下
課程大作業(yè)目的
通過該大作業(yè),考察學生分析、解決復雜問題的能力,考察學生編寫較大程序的能力,檢驗和評價《程序設計基礎》課程的學習效果
大作業(yè)內容
編寫一個小型工資管理系統(tǒng),用來管理職工的個人基本信息及工資薪酬等數(shù)據(jù)
基本要求
1、每個職工的數(shù)據(jù)應包括:工號、姓名、性別、部門、基本工資、績效工資、獎金、應發(fā)工資(應發(fā)工資=基本工資+績效工資+獎金)。職工數(shù)據(jù)要求采用結構體數(shù)據(jù)類型。
2、菜單顯示:顯示系統(tǒng)的一級功能菜單(數(shù)據(jù)輸入、數(shù)據(jù)修改、數(shù)據(jù)處理、數(shù)據(jù)輸出、退出)。
3、數(shù)據(jù)輸入:至少輸入10個職工的各項數(shù)據(jù)(應發(fā)工資由系統(tǒng)自動計算,不需要輸入)。**錄入的第一條記錄用自已的真實姓名,部門為自己的真實班級。**并將有自己真實姓名、班級的輸出結果截屏保存到大作業(yè)總結報告中。
4、數(shù)據(jù)修改:輸入工號,修改指定工號的各項數(shù)據(jù)。輸出修改完成后的全部職工數(shù)據(jù)。
5、數(shù)據(jù)處理:處理方式包括:排序、查詢??商峁┳硬藛巫層脩暨x擇。其中:
(1) 排序:按工號排序,顯示所有職工的全部數(shù)據(jù)。
(2) 查詢:按工號查詢,顯示指定工號的全部數(shù)據(jù)。
6、數(shù)據(jù)輸出:輸出全部職工的各項數(shù)據(jù)。
7、新增 刪除職工數(shù)據(jù)
8、新增 統(tǒng)計職工男女數(shù)量
9、退出:退出整個工資管理系統(tǒng)。
代碼如下
#include <stdio.h> #include <string.h> struct staff { ?char number[20]; ?char name[20]; ?char gender[10]; ?char bumen[20]; ?double jbgz; ?double jxgz; ?double bonus; ?double yfgz;? }; double jbgz,jxgz,bonus,yfgz; struct staff sta[10]; void inputdata(); ? ? ? ? ? ? ? ? ?//1.定義數(shù)據(jù)輸入函數(shù) input data void modifydata(); ? ? ? //2.定義數(shù)據(jù)修改函數(shù) modify data void processdata(); ? ? ? //3.定義數(shù)據(jù)處理函數(shù) process data void sortdata(); ? ? ? //定義數(shù)據(jù)處理函數(shù)中的按工號排序數(shù)據(jù)函數(shù) ?sort data void searchdata(); ? ? ? //定義數(shù)據(jù)處理函數(shù)中的按工號查詢數(shù)據(jù)函數(shù) ?search data void outputdata(); ? ? ? //4.定義數(shù)據(jù)輸出函數(shù) output data void deldata(); ? ? ? ?//5.定義數(shù)據(jù)刪除函數(shù) delete data ? ? ? 新增 void countgender(); ? ? ? ? ? ? ? ?//6.定義統(tǒng)計男女職工數(shù)量函數(shù) count gender ? ?新增? int main() { ?int i,choice;? ?while(1) ?{ ? for(i=1;i<90;i++) ? ?printf("*"); ? printf("\n"); ? printf("1.數(shù)據(jù)輸入 ?2.數(shù)據(jù)修改 ?3.數(shù)據(jù)處理 ?4.數(shù)據(jù)輸出 ?5.數(shù)據(jù)刪除 ?6.統(tǒng)計男女職工數(shù)量 ?7.退出\n"); ? for(i=1;i<90;i++) ? ?printf("*"); ? printf("\n"); ? do ? { ? ?printf("請根據(jù)菜單輸入數(shù)字:"); ? ?scanf("%d",&choice); ? } ? while(choice!=1&&choice!=2&&choice!=3&&choice!=4&&choice!=5&&choice!=6&&choice!=7); ? if(choice==7) ? ?break; ? else ? { ? ?if(choice==1) inputdata(); ? ?else if(choice==2) modifydata(); ? ?else if(choice==3) processdata(); ? ?else if(choice==4) outputdata(); ? ?else if(choice==5) deldata(); ? ?else if(choice==6) countgender(); ? ?else printf("該數(shù)不合法;\n"); ? ? //另加 ? } ?} ?return 0; } void inputdata() { ?int i; ?for(i=1;i<=10;i++) ?{ ? printf("請輸入第%d位職工的工號,姓名,性別,部門,基本工資,績效工資,獎金:",i); ? scanf("%s %s %s %s %lf %lf %lf",&sta[i].number,&sta[i].name,&sta[i].gender,&sta[i].bumen,&sta[i].jbgz,&sta[i].jxgz,&sta[i].bonus); ? //輸入第i位職工的工號,姓名,性別,部門,基本工資,績效工資,獎金 ? sta[i].yfgz=sta[i].jbgz+sta[i].jxgz+sta[i].bonus; ? printf("輸入成功\n"); ?} } void modifydata() { ?int i; ?char num[20]; ?printf("請輸入您想要修改職工的數(shù)據(jù)的工號:"); ?scanf("%s",&num); ?for(i=1;i<10;i++) ?{ ? if(strcmp(num,sta[i].number)==0) ? { ? ?printf("請輸入新工號,姓名,性別,部門,基本工資,績效工資,獎金\n"); ? ?scanf("%s %s %s %s %lf %lf %lf",&sta[i].number,&sta[i].name,&sta[i].gender,&sta[i].bumen,&sta[i].jbgz,&sta[i].jxgz,&sta[i].bonus); ? ?sta[i].yfgz=sta[i].jbgz+sta[i].jxgz+sta[i].bonus; ? } ? printf("修改成功!\n"); ? printf("修改后的數(shù)據(jù)為:\n"); ? printf(" ? ?工號 ? ? ? ? ?姓名 ? ? ? 性別 ? ? ? ?部門 ? ? ? ? ? 基本工資 ? ? ? ? ? 績效工資 ? ? ? ? ? ?獎金 ? ? ? ? ? 應發(fā)工資\n"); ? printf("%s ? ? ? %s ? ? ? ? ? %s ? ? ? ? %s ? ? ?%f ? %f ? ?%f ? ? %f\n",sta[i].number,sta[i].name,sta[i].gender,sta[i].bumen,sta[i].jbgz,sta[i].jxgz,sta[i].bonus,sta[i].yfgz); ? break; ?} } void processdata() { ?int choice,i; ?for(i=1;i<30;i++) ? printf("*"); ?printf("\n"); ?printf("二級菜單:\n"); ?printf("1.排序 2.查詢\n"); ?for(i=1;i<30;i++) ? printf("*"); ?printf("\n"); ?printf("請根據(jù)菜單輸入數(shù)字:"); ?scanf("%d",&choice); ?if(choice==1) sortdata(); ?else searchdata(); } void sortdata() { ?int i,j,k; ?char n[10]; ?for(i=1;i<=10;i++) ?{ ? for(j=1;j<=10;j++) ? { ? ?if(strcmp(sta[i].number,sta[j].number)>0) ? ?{ ? ? strcpy(n,sta[j].number); ? ? strcpy(sta[j].number,sta[i].number); ? ? strcpy(sta[i].number,n); ? ?} ? ? ? } ?? ?} ?for(k=1;k<=10;k++) ?{ ? printf("%s ? ? %s ? ?%s ? ? %s ? ? %lf ? ?%lf ? ?%lf\n",sta[k].number,sta[k].name,sta[k].gender,sta[k].bumen,sta[k].jbgz,sta[k].jxgz,sta[k].bonus,sta[k].yfgz); ?} } void searchdata() { ?int i; ?char snum[20]; ? ? ? //snum = searchnumber ?printf("請輸入您想要查詢的職工工號:"); ?scanf("%s",&snum); ?for(i=1;i<10;i++) ?{ ? if(strcmp(snum,sta[i].number)==0) ? { ? ?printf("該職工的數(shù)據(jù)為:\n"); ? ?printf(" ? ? 工號 ? ? ? ? ? 姓名 ? ? ? ? ? 性別 ? ? ? ? ? 部門 ? ? ? ? ?基本工資 ? ? ? 績效工資 ? ? ? ?獎金 ? ? ? ? ?應發(fā)工資\n\n"); ? ?printf(" %s ? ? ? %s ? ? ? ? ? %s ? ? ? ? %s ? ? ?%f ? %f ? ?%f ? ? %f\n",sta[i].number,sta[i].name,sta[i].gender,sta[i].bumen,sta[i].jbgz,sta[i].jxgz,sta[i].bonus,sta[i].yfgz); ? } ? break; ?} } void outputdata() { ?int i; ?printf(" ? ? 工號 ? ? ? ? ? 姓名 ? ? ? ? ? 性別 ? ? ? ? ? 部門 ? ? ? ? ?基本工資 ? ? ? 績效工資 ? ? ? ?獎金 ? ? ? ? ?應發(fā)工資\n"); ?for(i=1;i<=10;i++) ?{ ? printf(" %s ? ? ? %s ? ? ? ? ? %s ? ? ? ? %s ? ? ?%f ? %f ? ?%f ? ? %f\n",sta[i].number,sta[i].name,sta[i].gender,sta[i].bumen,sta[i].jbgz,sta[i].jxgz,sta[i].bonus,sta[i].yfgz); ?} } void deldata() { ?int i,j,choi; ?//char Y=Y; ?//char N=N; ?char delnum[20]; ?printf("請輸入您想要刪除職工數(shù)據(jù)的工號:"); ?scanf("%s",&delnum); ?for(i=1;i<10;i++) ?{ ? if(strcmp(delnum,sta[i].number)==0) ? { ? ?printf("該職工的數(shù)據(jù)為:\n"); ? ?printf(" ? ? 工號 ? ? ? ? ? 姓名 ? ? ? ? ? 性別 ? ? ? ? ? 部門 ? ? ? ? ?基本工資 ? ? ? 績效工資 ? ? ? ?獎金 ? ? ? ? ?應發(fā)工資\n"); ? ?printf(" %s ? ? ? %s ? ? ? ? ? %s ? ? ? ? %s ? ? ?%f ? %f ? ?%f ? ? %f\n",sta[i].number,sta[i].name,sta[i].gender,sta[i].bumen,sta[i].jbgz,sta[i].jxgz,sta[i].bonus,sta[i].yfgz); ? ?printf("確認刪除該名職工的數(shù)據(jù)嗎?(1.確認 ?2.取消)\n"); ? ?scanf("%d",&choi); ? ?if(choi==1) ? ?{ ? ? for(i=1,j=2;j<=10;i++,j++) ? ? { ? ? ?strcpy(sta[i].number,sta[j].number); ? ? ?strcpy(sta[i].name,sta[j].name); ? ? ?strcpy(sta[i].gender,sta[j].gender); ? ? ?strcpy(sta[i].bumen,sta[j].bumen); ? ? ?sta[i].jbgz=sta[j].jbgz; ? ? ?sta[i].jxgz=sta[j].jxgz; ? ? ?sta[i].bonus=sta[j].bonus; ? ? } ? ? printf("刪除成功!!\n");? ? ?} ? ?else break; ? } ?} } void countgender() { ?int i,count=0,fecount=0; ?char gen[10]="男"; ?for(i=1;i<=10;i++) ?{ ? if(strcmp(gen,sta[i].gender)==0) count++; ?} ?fecount=10-count; ?printf("該公司有%d名男職工,有%d名女職工\n",count,fecount); }
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
C語言數(shù)據(jù)結構不掛科指南之棧&隊列&數(shù)組詳解
自考重點、期末考試必過指南,這篇文章讓你理解什么是棧、什么是隊列、什么是數(shù)組。文中的示例代碼講解詳細,感興趣的小伙伴可以了解一下2022-09-09C/C++中一次性執(zhí)行多個DOS命令的實現(xiàn)思路
在C語言中執(zhí)行DOS命令的方法很多,在這就不一給大家一一介紹了,本文重點給大家介紹C/C++中一次性執(zhí)行多個DOS命令的實現(xiàn)思路,需要的朋友參考下2017-12-12