当前位置:网站首页>C language course set up salary management system (big homework)
C language course set up salary management system (big homework)
2022-07-01 06:26:00 【Ordinary senior】

One 、 Design function ( The article is for reference only )
The general idea is to input functions , Output function , Modify the function , Delete function , Add function , Query function , A function used to count grades , There are also functions to save files , And menu functions , Finally, all of them are called in the main function
Two 、 Function display






3、 ... and 、 Mind mapping

Four 、 Program source code
#include<stdio.h>
#include<windows.h>
#include<string.h>
#include<conio.h>
#define N 100
struct clerk
{
int num; //ID Number
char name[20]; // full name
int jbgz; // Basic salary
int zwgz; // Job salary
int jt; // allowance
int yb; // Medical insurance
int gjj; // Accumulation fund
int total; // Total wage
}em[100];
void menu();
void input();
void save(int);
void display();
void del();
void add();
void search();
void search_num();
void search_name();
void modify();
void sta();
void start(); /* Define each function */
void start() // Start interface
{
system("cls");// Clear the screen
printf("\n\n\n\n\n\n");
printf("************************************************");
printf("********<<<<<< Welcome to the salary management system >>>>>>********");
printf("************************************************");
printf("\t\t\t *** Press any key to enter ***\n");
}
void menu() // Menu interface
{
system("cls");
system("color 1F"); // Set the background color blue The color of the text is white
printf("*** menu ***\n\n");
printf(">>>>>>>>>>>>>>>>>>>>>>>>> 1 Input \n\n");
printf(">>>>>>>>>>>>>>>>>>>>>>>>> 2 Show \n\n");
printf(">>>>>>>>>>>>>>>>>>>>>>>>> 3 lookup \n\n");
printf(">>>>>>>>>>>>>>>>>>>>>>>>> 4 Delete \n\n");
printf(">>>>>>>>>>>>>>>>>>>>>>>>> 5 add to \n\n");
printf(">>>>>>>>>>>>>>>>>>>>>>>>> 6 modify \n\n");
printf(">>>>>>>>>>>>>>>>>>>>>>>>> 7 Statistics \n\n");
printf(">>>>>>>>>>>>>>>>>>>>>>>>> 8 sign out \n\n");
printf(" explain :* If used for the first time No data has been entered Please enter the data first \n * The entered data will be saved automatically \n * When the input function is selected again, the original data will be overwritten \n\n");
int n,button=0;
char a;
do
{
printf(" Functional selection (1--8):\n");
scanf("%d",&n);
if(n>=1&&n<=8)
{
button=1;
break;
}
else
{
button=0;
printf(" Your input is wrong , Please reselect !");
}
}while(button==0);
while(button==1)
{
switch(n)
{
case 1:input();break;
case 2:display();break;
case 3:search();break;
case 4:del();break;
case 5:add();break;
case 6:modify();break;
case 7:sta();break;
case 8:exit(0);break;
default :break;
}
getchar();
printf("\n");
printf(" Press any key to continue \n");
getch();
system("cls"); /* Clear the screen */
menu(); /* Call menu function */
printf(" Functional selection (1--8):\n");
scanf("%d",&n);
printf("\n");
}
}
void input() /* Input function */
{
int i,m;
system("cls");
printf(" Number of employees (1--100):\n");
scanf("%d",&m);
for (i=0;i<m;i++)
{
printf(" Please enter the employee number : ");
scanf("%d",&em[i].num);
printf(" Please enter a name : ");
scanf("%s",&em[i].name);
getchar();
printf(" Please enter the basic salary : ");
scanf("%d",&em[i].jbgz);
printf(" Please enter the job salary : ");
scanf("%d",&em[i].zwgz);
printf(" Please enter allowance : ");
scanf("%d",&em[i].jt);
printf(" Please enter medical insurance : ");
scanf("%d",&em[i].yb);
printf(" Please enter the provident fund : ");
scanf("%d",&em[i].gjj);
em[i].total=((em[i].jbgz)+(em[i].zwgz)+(em[i].jt)-(em[i].yb)-(em[i].gjj));// Calculate the total wage
printf("\n");
}
printf("\n Creation completed !\n");
save(m);// Keep the number of employees m
}
void save(int m) /* Save file function */
{
int i;
FILE*fp; // Statement fp Is a pointer , Used for pointing FILE Object of type
if ((fp=fopen("clerk_list","wb"))==NULL) // The open employee list file is empty
{
printf (" Open the failure \n");
exit(0);
}
for (i=0;i<m;i++) /* Output the information in memory to disk file */
if (fwrite(&em[i],sizeof(struct clerk),1,fp)!=1)// Write data block &em[i]: The output data is the address sizeof(struct clerk): Get the length of a monomer 1: Number of data items fp: Target file pointer
printf(" File read / write error \n");
fclose(fp);// The last remaining data in the buffer is output to the disk file , And release the file pointer and associated buffer
}
int load() /* Import function int type */
{
FILE*fp;
int i=0;
if((fp=fopen("clerk_list","rb"))==NULL) /*“rb” Open a binary file , Only reading is allowed */
{
printf ("cannot open file\n");
exit(0);
}
else
{
do
{
fread(&em[i],sizeof(struct clerk),1,fp); // Read
i++;
}
while(feof(fp)==0); // Detect end of file on stream
}
fclose(fp);
return(i-1);// Number of returnees
}
void display() /* Browse functions */
{
int i,sum=0;
int m=load();
system("cls");
printf(" Employee number full name Basic salary Job salary allowance Medical insurance Accumulation fund Total wage \n");
for(i=0;i<m;i++) /*m Is the number of employees in the input section */
{
printf("\n %02d %-6s %-8d %-8d %-8d %-8d %-8d%-6d ",em[i].num,em[i].name,em[i].jbgz,em[i].zwgz,em[i].jt,em[i].yb,em[i].gjj,em[i].total);
sum+=em[i].total;// Calculate the sum of employees' total wages
}
printf("\n\n The average wage of employees :%-8d \n",sum/m);
}
void del() /* Delete function */
{
int m=load();
int i,j,n,t,button;
char name[20];
printf("\n Original employee information :\n");
display(); // Display the employee information before deletion
printf("\n");
printf(" Delete by name :\n");
scanf("%s",name);
for(button=1,i=0;button&&i<m;i++)// In the main function button==1 Each function can be called only when
{
if(strcmp(em[i].name,name)==0)// Find an employee by employee name And call up its data
{
printf("\n The original record of this person is :\n");// Displays information about the selected employee
printf(" Employee number full name Basic salary Job salary allowance Medical insurance Accumulation fund Total wage \n");
printf("\n %02d %-6s %-8d %-8d %-8d %-8d %-8d %-8d ",em[i].num,em[i].name,em[i].jbgz,em[i].zwgz,em[i].jt,em[i].yb,em[i].gjj,em[i].total);
printf("\n Sure to delete Please press 1, If you don't want to delete, please press 0\n");
scanf("%d",&n);
if(n==1)
{
for(j=i;j<m-1;j++)// From i A start Assign the values of the members of the latter item to the corresponding members of the previous item Complete the second i Item Deletion
{
strcpy(em[j].name,em[j+1].name);
em[j].num=em[j+1].num;
em[j].jbgz=em[j+1].jbgz;
em[j].zwgz=em[j+1].zwgz;
em[j].jt=em[j+1].jt;
em[j].yb=em[j+1].yb;
em[j].gjj=em[j+1].gjj;
em[j].total=em[j+1].total;
}
button=0;
}
}
}
if(!button)//button==0 Indicates that the deletion is complete
m=m-1;// Reduce the total number of employees by one person
else
printf("\n Check no one !\n");
getch();
save(m); // Call the save function
display(); // Call the browse function
printf("\n To continue deleting, press 1, To not delete again, press 0\n");
scanf("%d",&t);
switch(t)
{
case 1:del();break;
case 0:break;
default :break;
}
}
void add()/* Add function */
{
FILE*fp;
int n;
int count=0;
int i;
int m=load();
printf("\n Original employee information :\n");
display();
printf("\n");
fp=fopen("clerk_list","a"); /* Opened as an appended file clerk_list File additional information */
printf(" Please enter the number of employees you want to increase :\n");// Determine the number of employees to join n
scanf("%d",&n);
for (i=m;i<(m+n);i++)// add to n Employee information
{
printf("\n Please enter the information of the new employee :\n");
printf(" Please enter the employee number : ");
scanf("%d",&em[i].num);
printf(" Please enter a name : ");
scanf("%s",em[i].name);
printf(" Please enter the basic salary : ");
scanf("\t%d",&em[i].jbgz);
printf(" Please enter the job salary : ");
scanf("%d",&em[i].zwgz);
printf(" Please enter allowance : ");
scanf("%d",&em[i].jt);
printf(" Please enter medical insurance : ");
scanf("\t%d",&em[i].yb);
printf(" Please enter the provident fund : ");
scanf("%d",&em[i].gjj);
em[i].total=( em[i].jbgz+ em[i].zwgz + em[i].jt- em[i].yb- em[i].gjj);// Calculate the total salary of the employee
printf("\n");
count=count+1;
}
printf("\n Add success , Please press any key \n");
getch();
m=m+count;// Add the number of new employees to the total number of employees
save(m);
display();// Display the added information
fclose(fp);
}
void search()/* Query function */
{
int t,button;
system("cls");// Clear the screen
do
{
printf("\n Press 1 Query by job No \n\n Press 2 Search by name \n\n Press 3 Return to main menu \n");
scanf("%d",&t);
if(t>=1&&t<=3)
{
button=1;
break;
}
else
{
button=0;
printf(" Input error , Please re-enter \n");
}
}while(button==0);// Go back to Query options
while(button==1)
{
switch(t)// Select query method
{
case 1:printf(" Query by job No \n");search_num();break;
case 2:printf(" Search by name \n");search_name();break;
case 3:menu();break;
default:break;
}
}
}
void search_num()// Query by employee No
{
int a;
int i,t;
int m=load();
printf(" Please enter the employee number you want to find :\n");
scanf("%d",&a);
for(i=0;i<m;i++)
if(a==em[i].num)
{
printf(" Employee number full name Basic salary Job salary allowance Medical insurance Accumulation fund Total wage \n");
printf("\n %02d %-6s %-8d %-8d %-8d %-8d %-8d %-8d ",em[i].num,em[i].name,em[i].jbgz,em[i].zwgz,em[i].jt,em[i].yb,em[i].gjj,em[i].total);
break;
}
if(i==m)
printf("\n I'm sorry , Check no one \n");
printf("\n");
printf(" To return the query function, press 1, To continue to query the employee number, please press 2\n");
scanf("%d",&t);
switch(t)
{
case 1:search();break;
case 2: break;
default:break;
}
}
void search_name()
{
char name[30];
int i,t;
int m=load();
printf(" Please enter a name :\n");
scanf("%s",name);
for(i=0;i<m;i++)
if(strcmp(em[i].name,name)==0) // String comparison
{
printf("\n Already found , It is recorded as :\n");
printf(" Employee number full name Basic salary Job salary allowance Medical insurance Accumulation fund Total wage \n");
printf("\n %02d %-6s %-8d %-8d %-8d %-8d %-8d %-8d ",em[i].num,em[i].name,em[i].jbgz,em[i].zwgz,em[i].jt,em[i].yb,em[i].gjj,em[i].total);
}
if(i==m)
printf("\n I'm sorry , Check no one \n");
printf("\n To return to the query menu, press 1, To continue querying your name, press 2\n");
scanf("%d",&t);
switch(t)
{
case 1:search();break;
case 2:break;
default :break;
}
}
void modify() /* Modify the function */
{
int num;
char name[20];
int jbgz;
int zwgz;
int jt;
int yb;
int gjj;
int b,c,i,n,t,button;
int m=load();
system("cls");
printf("\n Original employee information :\n");
display();
printf("\n");
printf(" Please enter the name of the employee to be modified :\n");
scanf("%s",name);
for(button=1,i=0;button&&i<m;i++)
{
if(strcmp(em[i].name,name)==0)
{
printf("\n The original record of this person is :\n");
printf(" Employee number full name Basic salary Job salary allowance Medical insurance Accumulation fund Total wage \n");
printf("\n %02d %-6s %-8d %-8d %-8d %-8d %-8d %-8d ",em[i].num,em[i].name,em[i].jbgz,em[i].zwgz,em[i].jt,em[i].yb,em[i].gjj,em[i].total);
printf("\n determine Press 1 ; If not, please press 0\n");
scanf("%d",&n);
if(n==1)
{
printf("\n Options that need to be modified \n 1. Employee number 2. full name 3. Basic salary 4. Job salary 5. allowance 6. Medical insurance 7. Accumulation fund 8. Back to the top \n");
printf(" Please select the serial number 1-8:\n");
scanf("%d",&c);
if(c>8||c<1)
printf("\n Wrong choice , Please reselect !\n");
}
button=0;
}
}
if(button==1)
printf("\n Check no one \n");
do
{
switch(c) /* Because when you find the first i When an employee ,for After the statement i Self added 1, Therefore, the following should assign the changed information to the second i-1 personal */
{
case 1: printf(" The employee number is changed to : ");
scanf("%d",&num);
em[i-1].num=num;
break;
case 2: printf(" Name changed to : ");
scanf("%s",name);
strcpy(em[i-1].name,name);
break;
case 3: printf(" The basic salary is changed to : ");
getchar();
scanf("%d",&jbgz);
em[i-1].jbgz=jbgz;
em[i-1].total=( em[i-1].jbgz+ em[i-1].zwgz + em[i-1].jt- em[i-1].yb- em[i-1].gjj);
break;
case 4: printf(" The position salary is changed to : ");
scanf("%d",&zwgz);
em[i-1].zwgz=zwgz;
em[i-1].total=( em[i-1].jbgz+ em[i-1].zwgz + em[i-1].jt- em[i-1].yb- em[i-1].gjj);
break;
case 5: printf(" Change to allowance : ");
scanf("%d",&jt);
em[i-1].jt=jt;
em[i-1].total=( em[i-1].jbgz+ em[i-1].zwgz + em[i-1].jt- em[i-1].yb- em[i-1].gjj);
break;
case 6: printf(" Medical insurance is changed to : ");
scanf("%d",&yb);
em[i-1].yb=yb;
em[i-1].total=( em[i-1].jbgz+ em[i-1].zwgz + em[i-1].jt- em[i-1].yb- em[i-1].gjj);
break;
case 7: printf(" The provident fund is changed to : ");
scanf("%d",&gjj);
em[i-1].gjj=gjj;
em[i-1].total=( em[i-1].jbgz+ em[i-1].zwgz + em[i-1].jt- em[i-1].yb- em[i-1].gjj);
break;
case 8: modify();
break;
}
printf("\n");
printf("\n\n Confirm modification Please press 1 ; Revise Please press 2: \n");
scanf("%d",&b);
}while(b==2);
printf("\n");
save(m);
display();
printf("\n Press 1 Continue to modify , If you don't want to modify it again, please press 0\n");
scanf("%d",&t);
switch(t)
{
case 1:modify();break;
case 0:break;
default :break;
}
}
void sta()// Statistical function
{
int i,sum=0,suma=0,sumb=0,sumc=0,sumd=0,sume=0;
int m=load();
system("cls");
printf(" Employee number full name Basic salary Job salary allowance Medical insurance Accumulation fund Total wage \n");
for(i=0;i<m;i++) /*m Is the number of employees in the input section */
{
printf("\n %02d %-6s %-8d %-8d %-8d %-8d %-8d%-8d ",em[i].num,em[i].name,em[i].jbgz,em[i].zwgz,em[i].jt,em[i].yb,em[i].gjj,em[i].total);
sum+=em[i].total;// Calculate the sum of employees' total wages
suma+=em[i].jbgz;
sumb+=em[i].zwgz;
sumc+=em[i].jt;
sumd+=em[i].yb;
sume+=em[i].gjj;
}
printf("\n\n Average wages of employees : %-8d %-8d %-8d %-8d %-8d%-8d \n",suma/m,sumb/m,sumc/m,sumd/m,sume/m,sum/m);
}
int main()// The main function
{
start();
getch();
menu();
}

You can pay attention to it, and it will be updated continuously in the future 0.0( Thank you first )
边栏推荐
- 【#Unity Shader#自定义材质面板_第二篇】
- [file system] how to run squashfs on UBI
- Differences between in and exists in MySQL
- Make: g++: command not found
- Projects and dependencies in ABP learning solutions
- 【#Unity Shader#Amplify Shader Editor(ASE)_第九篇】
- Tidb database characteristics summary
- Servlet
- C语言课设职工信息管理系统(大作业)
- 三分钟带你快速了解网站开发的整个流程
猜你喜欢
![[ManageEngine Zhuohao] what is network operation and maintenance management and what is the use of network operation and maintenance platform](/img/a4/b1476515260e3af0ca0dcc031deb98.png)
[ManageEngine Zhuohao] what is network operation and maintenance management and what is the use of network operation and maintenance platform

Picture server project test

MongoDB:一、MongoDB是什么?MongoDB的优缺点

ManageEngine卓豪助您符合ISO 20000标准(四)

【自动化运维】自动化运维平台有什么用

To sort out the anomaly detection methods, just read this article!

Solve the problem of garbled files uploaded by Kirin v10

HCM Beginner (I) - Introduction

Promise
![[file system] how to run squashfs on UBI](/img/d7/a4769420c510c47f3c2a615b514a8e.png)
[file system] how to run squashfs on UBI
随机推荐
虚幻 简单的屏幕雨滴后处理效果
Teach you how to implement a deep learning framework
【ManageEngine卓豪】助力黄石爱康医院实现智能批量化网络设备配置管理
What are the functions of LAN monitoring software
【ManageEngine卓豪】局域网监控的作用
Ant new village is one of the special agricultural products that make Tiantou village in Guankou Town, Xiamen become Tiantou village
Mongodb: I. what is mongodb? Advantages and disadvantages of mongodb
Application of IT service management (ITSM) in Higher Education
Freeswitch dial the extension number
【KV260】利用XADC生成芯片温度曲线图
Kubedm builds kubenetes cluster (Personal Learning version)
【ManageEngine卓豪】移动终端管理解决方案,助力中州航空产业数字化转型
Flink practice -- multi stream merge
[self use of advanced mathematics in postgraduate entrance examination] advanced mathematics Chapter 1 thinking map in basic stage
【#Unity Shader#自定义材质面板_第二篇】
[ManageEngine Zhuohao] mobile terminal management solution, helping the digital transformation of Zhongzhou aviation industry
[network security tool] what is the use of USB control software
连续四年入选Gartner魔力象限,ManageEngine卓豪是如何做到的?
JMM详解
UOW of dev XPO comparison