#include <stdio.h>
#include <stdlib.h>
int workertotal=0;
struct WORKER
{
int num;
Char name[50];
Char sex[10];
Char age[30];
Char education[50];
Char money[10];
Char address[50];
Char call[10];
}WORKER[100];
void Add ()
{
int n,i;
printf (" Please enter the number of employees added:");
scanf ("%d", &n);
for (i=1;i<=n;i++) {
printf ("\ n" employee number, name, gender, age, education, salary, address, telephone \ n ");
scanf ("%d%s%s%s%s%s '%s '%s", &worker[i].num,&worker[i].name,&worker[i].sex,&worker[i] . Age,&worker[i].education,&worker[i].money,&worker[i].address,&worker[i].call);
}
Workertotal+=n;
}
void print ()
{
int i;
printf (" all employees in the system \ n");
for (i=1;i<=workertotal;i++) {
printf ('%d%s%s '%s%s%s%s '%s ', worker[i].num,worker[i].name,worker[i].sex,worker[i].age,worker[i].education,worker[ I].money,worker[i].address,worker[i].call);
}
}
int Searchworker ()
{
Char workername[50];
int i;
int total;
printf (" Inquiry by Education :");
printf ("\ n Please enter your education :");
scanf ("%s", &workername);
for (i=1;i<=workertotal;i++)
{
if (strcmp (worker[i].education,workername) ==0)
{
printf ('%d%s%s '%s%s%s%s '%s ', worker[i].num,worker[i].name,worker[i].sex,worker[i].age,worker[i].education,worker[ I].money,worker[i].address,worker[i].call);
Total+=1;
}
}
if (total==0) {
printf (" not found \ n");
}
return 1;
}
int Searchworkerl ()
{
int i,num;
int total;
printf (" Search by Employee number :");
printf ("\ n Please enter the employee number :");
scanf ("%d", &num);
for (i=1;i<=workertotal;i++)
{
if (worker[i].num==num)
{
printf ('%d%s%s '%s%s%s%s '%s ', worker[i].num,worker[i].name,worker[i].sex,worker[i].age,worker[i].education,worker[ I].money,worker[i].address,worker[i].call);
Total+=1;
}
}
if (total==0) {
printf (" not found \ n");
}
return 1;
}
void Deleteworker ()
{
int i,j;
printf (" cancellation of Staff ");
I=searchworker ();
WORKERTOTAL=WORKERTOTAL-1;
if (i!=-1) {
for (j=i;j<=workertotal;j++) {
WORKER[J]=WORKER[J+1];
}
printf (" The worker has written off . \ n");
}
else printf (" no worker . \ n");
}
void Modify ()
{
int workerno,i;
printf (" Employee Number enquiry:");
printf ("\ n Please enter the employee number:");
scanf ("%d", &workerno);
for (i=1;i<=workertotal;i++) {
if (worker[i].num==workerno)
{
printf ("\ n" employee number, name, gender, age, education, salary, address, telephone \ n ");
scanf ('%d%s%s '%s%s%s%s '%s ',&worker[i].num,&worker[i].name,&worker[i].sex,&worker[i].age,& Worker[i].education,&worker[i].money,&worker[i].address,&worker[i].call);
}
}
}
int main ()
{
int flag=1;
while (flag) {
printf ("\t\n\n staff Information Management system \ n");
printf ("\t\n 1. Add employee Information ");
printf ("\t\n 2. View all employee information ");
printf ("\t\n 3. According to the Academic qualifications Inquiry ");
printf ("\t\n 4. Search by employee number ");
printf ("\t\n 5. Delete designated employee information ");
printf ("\t\n 6. Modification of designated staff information ");
printf ("\t\n 0. Exit system \ n ");
printf (" Please select your business, use the number keys to operate :");
scanf ("%d", &flag);
System ("CLS");
Switch (flag) {
Case 1:add ();
Case 2:print ();
Case 3:searchworker ();
Case 4:searchworkerl ();
Case 5:deleteworker ();
Case 6:modify ();
Case 0:exit (0);
}
}
return 0;}
The result is to have a whole framework and overall planning, the system needs the function and function, to the system you want to write a similar outline of things, the system is actually integrated a small C language program, he programmed a small function to apply, through the call of the main function, play the role of the system;
If a system, such as student information management system, need to keep a student's name, gender, age and other information, then set the variable to save a lot of students of this information is a bit inconvenient. Similar to a register, each page can only write the name, if you want to register other information, but also add a register, can only write gender, if the age of registration, but also add a register, can only write age, ..., how inconvenient, but also easy to mess. The solution you must think, how simple, a register this page, at the same time write the name, gender, age is not OK? C language is also the case, if you define a form, a variable record a lot of information at the same time, so in the management system, it is much more convenient. This is the structure.
Structure first to define, because each program with the combination of information is different, such as student information management system, may be the number, name, gender, age, class combination together, so the first line with a struct to tell the program, the following is a struct, the back of the Stu is the structure of the type, A similar integer in int, this stu is your own name.
If you want to design a staff management system,
First of all to determine which applications of the system, such as input function, call function, modify function, delete function, all need to have
Then is to determine what information products, such as employee number, name, gender, age, education, wages, address, telephone, etc.
Defines a struct struct worker and array num, used to store names, work numbers, education, and so on, void add call function, used to invoke employee information.
Void print is an output function that outputs the workers in the system. Searchworker query function, according to education, name, gender and other information to inquire staff information.
Void Deleteworker is a delete function that deletes employee information. Void modify is used to modify employee information. Case is a switch statement used to query different employee information.
Lesson two Homework