当前位置:网站首页>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 )
边栏推荐
猜你喜欢

Distributed lock implementation

lxml模块(数据提取)

图片服务器项目测试

B-tree series
![[unity shader ablation effect _ case sharing]](/img/e3/464f1cf426e8c03ce3d538ed9cf4bc.png)
[unity shader ablation effect _ case sharing]

FPGA - clocking -02- clock wiring resources of internal structure of 7 Series FPGA

Redis安装到Windows系统上的详细步骤

Excel visualization

Make Tiantou village sweet. Is Xianjing taro or cabbage the characteristic agricultural product of Tiantou Village

Understanding of C manualresetevent class
随机推荐
C语言课设销售管理系统设计(大作业)
What are the functions of LAN monitoring software
数据库产生死锁了请问一下有没有解决办法
Record MySQL troubleshooting caused by disk sector damage
Minio error correction code, construction and startup of distributed Minio cluster
分布式锁实现
DHT11 temperature and humidity sensor
SystemVerilog learning-06-class encapsulation
[ManageEngine Zhuohao] helps Julia college, the world's top Conservatory of music, improve terminal security
To sort out the anomaly detection methods, just read this article!
Record currency in MySQL
[unity shader custom material panel part I]
[leetcode] day91- duplicate elements exist
【ManageEngine卓豪】用统一终端管理助“欧力士集团”数字化转型
One of the characteristic agricultural products that make Tiantou village, Guankou Town, Xiamen into a "sweet" village is
【自动化运维】自动化运维平台有什么用
Make: g++: command not found
Understanding of C manualresetevent class
端口扫描工具对企业有什么帮助?
kubeadm搭建kubenetes 集群(个人学习版)