Programming problems : Attendance system for College Students

1 Problem description

The system requires a simple implementation , Practical student attendance system program , The main functions include adding attendance data , delete , modify , lookup , Statistics , sort , Output, etc . All statistical data should be saved in the file system , In case the system runs next time . Through this topic , Good command of documents , array , Various operations of pointer , And the application of some basic algorithms .

2 Functional requirements

Code to provide the following basic functions .

(1) Attendance data is composed of multiple data records , Its information includes : Student number ( only ), full name , class , Attendance date ( It consists of month and day ) wait .

(2) Data storage form : All information should be saved in text or binary file .

(3) Functions to be implemented

a New student information data ( Avoid duplicate records , If in , No more ).

b Find data ( According to student number , full name , Check attendance date, etc ).

c Modify student records ( You can find it first , Revise again ).

d Delete student records ( Please refer to the modification above ).

e   Display student attendance data list ( Some or all of them can be displayed ).

f   sort ( According to student number , full name , Attendance date sorting ).

g data statistics ( Statistical analysis of attendance data , After statistics , Attendance details can be obtained through the attendance system , Daily attendance report , Attendance summary , Attendance exception form , Leave summary, etc ).

h   Save data to a file and read data from the file .

(4) Interface function requirements :

1) Friendly interface , Realize a function control menu .

2) Each operation is selected from this menu , Using the loop structure, the program can be operated many times .

remarks :

(1) Data integrity assurance . for example : Student number and name must be strict , standard .

(2) Flexible report format is required , Various forms , The content is clear , Please think about it by yourself , Design .

(3) Attendance symbol : Out Diligence √    Wide open course X    matter false △    illness false ○    late reach +   Good morning! retreat –

(4) No less than ten attendance periods .

3 Other requirements

(1) Beautiful interface , Convenient interaction .

(2) Detailed notes : Each function has annotation function , For parameters , The return value should also be used in the form of comments ; Key statement segments require annotation .

(3) The level of procedure is clear , Strong readability .

(4) variable , Function naming conforms to the specification .

(5) If possible , Available MFC And other development tools , Realize color or graphic operation interface .

4 development environment

You can choose TC2.0,TC3.0,VC++6.0,vs2010 And other development environment , Or discuss with the teacher , Choose familiar development tools and platforms .

 
#include<stdio.h> #include<string.h> #include<stdlib.h> #define maxsize 15
#define maxnum 1000 typedef struct { char Student_ID[maxsize]; char
Name[maxsize]; char Class_Number[maxsize]; char Attandance_date[maxsize]; char
Attandance_Result[maxsize]; } student; student Students[maxnum]; int num = 0;
char buf[maxsize]; /* Realize the function of entering and exiting at the end of each input , Better implementation of interaction with users */ void wait_for_Enter() {
getchar(); getchar(); }
/* In order to sort the dates , My idea is for months , Direct use atoi Cut it out and turn it into a month , For days , You need to use the following function to calculate */ int convert(char
str[]) { int i,j,res = 0, cnt = 0; for (i = strlen(str) - 3; i >= 0; i--) { if
(str[i] >= '0'&&str[i] <= '9') res *= 10, res += (str[i] - '0'); else break; }
return res;// Return days , Which is the day of the month , for example 11 month 5 day , What's coming back is 5;5 month 23 day , What's coming back is 23 }
/* This function implements the student Type variable b All information assigned to student Variable of type a*/ void copy(student *a,student *b) {
strcpy(a->Student_ID , b->Student_ID); strcpy(a->Name , b->Name);
strcpy(a->Class_Number , b->Class_Number); strcpy(a->Attandance_Result ,
b->Attandance_Result); strcpy(a->Attandance_date , b->Attandance_date); }
/* The purpose of this function is to realize the function that the existing students cannot be added again */ bool judge(char *ID) { int i; for (i = 0; i <
num; i++) { if (strcmp(Students[i].Student_ID, ID) == 0) return false; } return
true; } /* Input function , To simplify the code */ void setInfo(char pinfo[], char desinfo[]) {
printf("%s:", pinfo); scanf("%s", desinfo); } /* Output details of each student */ void
PrintAllInformation() { int i;
printf("------------------------------------\n"); for (i = 0; i < num; i++)
printf("%s %s %s %s %s\n", Students[i].Student_ID, Students[i].Name,
Students[i].Class_Number, Students[i].Attandance_date,
Students[i].Attandance_Result);
printf("------------------------------------\n"); printf(" Printing succeeded ! Press enter to return \n");
wait_for_Enter(); } /* Output some information of each student */ void PrintPartInformation() { int i;
printf("------------------------------------\n"); for (i = 0; i < num; i++)
printf("%s %s %s\n", Students[i].Name, Students[i].Attandance_date,
Students[i].Attandance_Result);
printf("------------------------------------\n"); printf(" Printing succeeded ! Press enter to return \n");
wait_for_Enter(); } /* The function is to add students to the system */ void ADD() { char ID[maxsize];
printf(" Please enter the student number :"); scanf("%s", ID); if (!judge(ID)) { printf(" This person already exists \n");
printf(" Add complete ! Please press enter to return \n"); wait_for_Enter(); return; }
strcpy(Students[num].Student_ID, ID); setInfo(" Please enter the name of the student ", Students[num].Name);
setInfo(" Please enter the class of the student ", Students[num].Class_Number); setInfo(" Please enter the attendance date of the student ",
Students[num].Attandance_date); setInfo(" Please input the student's attendance result Diligence √ Wide open course X matter false △ illness false ○ late reach
+ Good morning! retreat –", Students[num].Attandance_Result); num++;// Add one to the number of students
printf(" Added successfully ! Press enter to return \n"); wait_for_Enter(); } /* This function realizes the function of searching , According to the student number , full name , Check the attendance date */
void Find() { int i, op, flag = -1; char information[maxsize]; printf("<1> Search by student number
<2> Search by name <3> Search by attendance date \n"); scanf("%d", &op); if (op == 1) { printf(" Please input the student number :");
scanf("%s", information); for (i = 0; i < num; i++) { if (strcmp(information,
Students[i].Student_ID) == 0) printf("%s %s %s %s %s\n\n",
Students[i].Student_ID, Students[i].Name, Students[i].Class_Number,
Students[i].Attandance_date, Students[i].Attandance_Result), flag = 1; } } else
if (op == 2) { printf(" Please input the student's name :"); scanf("%s", information); for (i = 0; i <
num; i++) { if (strcmp(information, Students[i].Name) == 0) printf("%s %s %s %s
%s\n\n", Students[i].Student_ID, Students[i].Name, Students[i].Class_Number,
Students[i].Attandance_date, Students[i].Attandance_Result), flag = 1; } } else
{ printf(" Please input attendance date :"); scanf("%s", information); for (i = 0; i < num; i++) { if
(strcmp(information, Students[i].Attandance_date) == 0) printf("%s %s %s %s
%s\n\n", Students[i].Student_ID, Students[i].Name, Students[i].Class_Number,
Students[i].Attandance_date, Students[i].Attandance_Result), flag = 1;; } } if
(flag == -1) printf(" This information does not exist !\n"); printf(" Search complete ! Press enter to return \n"); wait_for_Enter(); }
/* This function is to modify the existing information in the system , Similar to the above search , You can also select the information you want to modify according to different information */ void Change() { int
i, j = -1; char op[2], information[maxsize], find[maxsize]; printf("<1> Modify by student number
<2> Modify by name <3> Modify by attendance date \n"); scanf("%s", op); if (op[0] == '1') setInfo(" Please input the student number ",
information); else if (op[0] == '2') setInfo(" Please input the student's name ", information); else
setInfo(" Please enter the assessment date ", information); strcpy(find, information); if(op[0]=='1') for
(i = 0; i < num; i++) { if (strcmp(find, Students[i].Student_ID) == 0) j = i; }
else if(op[0]=='2') for (i = 0; i < num; i++) { if (strcmp(find,
Students[i].Name) == 0) j = i; } else for (i = 0; i < num; i++) { if
(strcmp(find, Students[i].Attandance_date) == 0) j = i; } if (j == -1) {
printf(" There is no information to look for !\n"); printf(" Modification completed ! Press enter to return \n"); wait_for_Enter(); return; }
setInfo("<1> Revision of student number <2> Change name <3> Modify attendance date ", op); if (op[0] == '1') {
setInfo(" Please input the new student number after modification ", information); strcpy(Students[j].Student_ID,
information); } else if (op[0] == '2') { setInfo(" Please enter the new name after modification ", information);
strcpy(Students[j].Name, information); } else { setInfo(" Please enter the new assessment date after modification ",
information); strcpy(Students[j].Attandance_date, information); }
printf(" Modification completed ! Press enter to return !\n"); wait_for_Enter(); }
/* This function is to delete the information of students who already exist in the system , The idea is the number of students num--, Everyone's information in the back moves forward one place , Realize the coverage of information */ void
Delete() { int i, j,flag = -1; char op[2],information[maxsize];
setInfo(" Please input :<1> Delete by student number <2> Delete by name ", op); if (op[0] == '1') { setInfo(" Please input student number ",
information); for (i = 0; i < num; i++) { if (strcmp(Students[i].Student_ID,
information) == 0) { flag = 1; for (j = i + 1; j < num; j++) {
copy(&Students[i], &Students[j]); } } } } else { setInfo(" Please enter your name ", information);
for (i = 0; i < num; i++) { if (strcmp(Students[i].Name, information) == 0) {
flag = 1; for (j = i + 1; j < num; j++) { copy(&Students[i], &Students[j]); } }
} } if (flag == -1) { printf(" This information does not exist !\n"); printf(" Deletion complete ! Press enter to return \n");
wait_for_Enter(); return ; } num--; printf(" This information does not exist !\n");
printf(" Deletion complete ! Press enter to return \n"); wait_for_Enter(); } /* This function implements the function 5 Output the existing information in the system */
void Print() { int op;
printf(" Please select \n<1> Partial printing ( Output student name and attendance date and attendance status )\n<2> print all ( Output all information of all students ):"); scanf("%d",
&op); if (op == 1) PrintPartInformation(); else PrintAllInformation(); }
/* Exchange the values of all members of two variables , Because all the members are char array , So it's used strcmp function . This function mainly serves for sorting , Exchange with pointer */ void
exchange(student *a, student *b) { char tmp[maxsize]; strcpy(tmp,
a->Student_ID); strcpy(a->Student_ID, b->Student_ID); strcpy(b->Student_ID,
tmp); strcpy(tmp, a->Name); strcpy(a->Name, b->Name); strcpy(b->Name, tmp);
strcpy(tmp, a->Class_Number); strcpy(a->Class_Number, b->Class_Number);
strcpy(b->Class_Number, tmp); strcpy(tmp, a->Attandance_Result);
strcpy(a->Attandance_Result, b->Attandance_Result);
strcpy(b->Attandance_Result, tmp); strcpy(tmp, a->Attandance_date);
strcpy(a->Attandance_date, b->Attandance_date); strcpy(b->Attandance_date,
tmp); return; } /* Implementation function 6 sort , According to the student number , full name , Sort attendance date , Bubble sort is used to sort the required information */ void Order()
{ int op, i, j; char tmp[maxsize]; printf(" Please input :<1> Sort by student number from small to large <2> By student name ASCLL Code sort
<3> Sort by attendance date from small to large :\n"); scanf("%d", &op); if (op == 1) { for (i = 0; i < num; i++)
{ for (j = i+1; j < num; j++) { if (strcmp(Students[i].Student_ID,
Students[j].Student_ID) > 0) { exchange(&Students[i], &Students[j]); } } } }
else if (op == 2) { for (i = 0; i < num; i++) { for (j = i+1; j < num; j++) {
if (strcmp(Students[i].Name, Students[j].Name) > 0) { exchange(&Students[i],
&Students[j]); } } } } else { int month_1, month_2, day_1, day_2; for (i = 0; i
< num; i++) { month_1 = atoi(Students[i].Attandance_date); day_1 =
convert(Students[i].Attandance_date); for (j = i+1; j < num; j++) { month_2 =
atoi(Students[j].Attandance_date); day_2 =
convert(Students[j].Attandance_date); if(month_1>month_2)
exchange(&Students[i], &Students[j]); else if(month_1==month_2&&day_1>day_2)
exchange(&Students[i], &Students[j]); } } } printf(" Sorted successfully ! Press enter to return \n");
wait_for_Enter(); } /* Output attendance list , What is the specific value of attendance list , It's according to my personal understanding , If there's something wrong with my understanding , You can ask me to change it again */ void
Detail_Print() { int i, j; char tmp[maxsize]; int month_1, month_2, day_1,
day_2; for (i = 0; i < num; i++) { month_1 = atoi(Students[i].Attandance_date);
day_1 = convert(Students[i].Attandance_date); for (j = 0; j < num; j++) {
month_2 = atoi(Students[j].Attandance_date); day_2 =
convert(Students[j].Attandance_date); if (month_1 < month_2)
exchange(&Students[i], &Students[j]); else if (month_1 == month_2 && day_1 <
day_2) exchange(&Students[i], &Students[j]); } }
printf("------------------------------------\n"); printf(" Attendance list :\n");
printf("%s:\n", Students[0].Attandance_date); printf("%s %s %s %s\n",
Students[0].Student_ID, Students[0].Name, Students[0].Class_Number,
Students[0].Attandance_Result); strcmp(tmp, Students[0].Attandance_date); for
(i = 1; i < num; i++) { if (strcmp(Students[i].Attandance_date, tmp) != 0) {
printf("%s:\n", Students[i].Attandance_date); strcmp(tmp,
Students[i].Attandance_date); } printf("%s %s %s %s\n", Students[i].Student_ID,
Students[i].Name, Students[i].Class_Number, Students[i].Attandance_Result); }
printf("------------------------------------\n"); printf(" Printing succeeded ! Press enter to return \n");
wait_for_Enter(); } /* Daily attendance report */ void Daily_Print() { int i; char
information[maxsize]; setInfo(" Please enter the date you want to view ", information);
printf("------------------------------------\n"); printf("%s Check on work attendance :\n",
information); for (i = 0; i < num; i++) { if (strcmp(information,
Students[i].Attandance_date) == 0) printf("%s %s %s %s\n",
Students[i].Student_ID, Students[i].Name, Students[i].Class_Number,
Students[i].Attandance_Result); }
printf("------------------------------------\n"); printf(" Printing succeeded ! Press enter to return \n");
wait_for_Enter(); } /* Attendance exception form , Output all not ‘ check mark ’ Information about the people who are in charge */ void Informal_Print() { int i,
cnt = 0; printf("------------------------------------\n"); printf(" Attendance exception form :\n");
for (i = 0; i < num; i++) { if (strcmp(Students[i].Attandance_Result, "√") !=
0) printf("%s %s %s %s %s\n", Students[i].Student_ID, Students[i].Name,
Students[i].Class_Number, Students[i].Attandance_date,
Students[i].Attandance_Result), cnt++; } printf(" Abnormal attendance :%d people \n", cnt);
printf("------------------------------------\n"); printf(" Printing succeeded ! Press enter to return \n");
wait_for_Enter(); } /* Leave exception form , Output the information of all the people who ask for leave */ void AskForLeave_Print() { int i, cnt
= 0; printf("------------------------------------\n"); printf(" Leave exception form \n"); for
(i = 0; i < num; i++) { if (strcmp(Students[i].Attandance_Result, "○") == 0 ||
strcmp(Students[i].Attandance_Result, "○") == 0) printf("%s %s %s %s %s\n",
Students[i].Student_ID, Students[i].Name, Students[i].Class_Number,
Students[i].Attandance_date, Students[i].Attandance_Result), cnt++; }
printf(" Number of people asking for leave :%d people \n", cnt); printf("------------------------------------\n");
printf(" Printing succeeded ! Press enter to return \n"); wait_for_Enter(); } /* Event function 7 Data statistics */ void Statistics()
{ char op[2]; setInfo(" Please select \n<1> Attendance list \n<2> Daily attendance report \n<3> Attendance exception form \n<4> Leave summary ",op); if
(op[0] == '1') { Detail_Print(); } else if (op[0] == '2') { Daily_Print(); }
else if (op[0] == '3') { Informal_Print(); } else { AskForLeave_Print(); } }
int main() { int i, a, b = 1; FILE *fp= fopen("Manage.txt", "at+"); if (!fp) {
printf(" error ! fail to open file \n"); exit(0); } fscanf(fp, "%d", &num);// Read in the number of students already in the system
printf(" The number of students stored in the current system :%d people \n", num); for (i = 0; i < num; i++) {// Reading information of students in the system
fscanf(fp, "%s%s%s%s%s", &Students[i].Student_ID, &Students[i].Name,
&Students[i].Class_Number, &Students[i].Attandance_date,
&Students[i].Attandance_Result); } fclose(fp); while (b != 0) {
printf("==============================================================================\n\n");
printf(" Attendance system for College Students \n\n");
printf("==============================================================================\n\n");
printf("<1> New student data <2> Find student data <3> Modify student records \n"); printf("<4> Delete student records <5> Display the data list of student attendance
<6> Sorts the specified data \n"); printf("<7> Data statistics <8> quit\n\n"); scanf("%d", &a); switch
(a) { case 1: ADD(); break; case 2: Find(); break; case 3: Change(); break;
case 4: Delete(); break; case 5: Print(); break; case 6: Order(); break; case
7: Statistics(); break; case 8: printf(" Exited \n"); b = 0; break; }
system("cls");// Screen clearing function , In order to make the interface more beautiful } // Input the information into the file at the end , Reserved for next operation FILE
*F=fopen("Manage.txt","wt");// Note that this is wt Write only open or create a text file , Write data only fprintf(F, "%d\n",
num); for (int i = 0; i < num; i++) { fprintf(F, "%s %s %s %s %s\n",
Students[i].Student_ID, Students[i].Name, Students[i].Class_Number,
Students[i].Attandance_date, Students[i].Attandance_Result); } fclose(F);
// End of file operation return 0; }

-------------------------------------------------------------------------------------------------------------------------------------------

2020.6.14 A little update :

Many private letters from my friends ask me why I can't run on my own machine , The possible reason is that I wrote this program with .cpp Suffix named c++ file , And you use it .c Suffix named c Language files , There are many differences between the two , for example c There is no language bool Of a variable of type , So you may report an error on your machine .

You can put .c File change to .cpp Run the file again , perhaps bool Variable of type int Type 0 and 1 Instead , There is absolutely no problem with this program .

tips: If you think it's useful , You can like it , More collections than likes , Online humble QAQ

Technology