当前位置:网站首页>Student attendance system for C language course (big homework)
Student attendance system for C language course (big homework)
2022-07-01 06:26:00 【Ordinary senior】
One 、 Design function ( The article is for reference only )
(1) Determine the interface , Enables the user to select an action item
(2) Input function : Use structure , Ask the user to enter the corresponding information , And save it in the file
(3) Query function : Search by name or student number , Use the loop to find the corresponding structure array elements , Then output the required The information you want
(4) Attendance scoring : The system outputs student scores according to the number of absenteeism of students in the attendance file in the percentage system , Five points will be deducted from truancy ;
Two 、 Function display
3、 ... and 、 Mind mapping
Four 、 Program source code
#include<stdio.h>
#include<string.h> /* The header file .*/
int SIZE; /* Macro definition .*/
int CLASS;
struct student /* Define a structure array , Contains student information .*/
{
char name[9];
char sex[4];
int number;
int count;
int score;
}stu[300];
int main() /* The main function , Selection interface .*/
{
void start();
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\t\t\t######################################\n");
printf("\t\t\t# Student attendance system #\n");
printf("\t\t\t# huan To meet you #\n");
printf("\t\t\t######################################\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\t\t######################################\n");
printf("\t\t\t Please enter the class size :\n");
printf("\t\t######################################\n");
scanf("%d",&SIZE);
printf("\n");
printf("\t\t######################################\n");
printf("\t\t\t Please enter the number of courses :\n");
printf("\t\t######################################\n");
scanf("%d",&CLASS);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
start();
}
void start() /* Auxiliary function of main function --start function .*/
{
char x;
void found();
void search();
void add();
void mark();
printf("######################################\n");
printf("# Please select the required function , Enter the corresponding number : #\n");
printf("# 1. Create a student list #\n");
printf("# 2. Search for student information #\n");
printf("# 3. Simulate the attendance process #\n");
printf("# 4. Calculate attendance score #\n");
printf("# 5. sign out #\n");
printf("# #\n");
printf("######################################\n");
scanf("%S",&x);
switch(x) /* utilize switch Function to realize the selection function of sub function .*/
{
case'1':found();break;
case'2':search();break;
case'3':add1();break;
case'4':mark();break;
case'5':break;
default :printf("**** Incorrect input , Please re-enter :\n");start();
}
}
void found() /* The first sub function --found function , Used to create a student list .*/
{
int a;
printf("####################\n");
printf(" Start building tables .\n");
printf("####################\n");
FILE *fp;
for(a=0;a<SIZE;a++) /* Application for loop , Input student information one by one .*/
{
printf(" Please enter the first %d A student's personal information :\n",a+1);
printf(" full name :");
scanf("%s",stu[a].name);
printf(" Gender :");
scanf("%s",stu[a].sex);
printf(" Student number :");
scanf("%d",&stu[a].number);
stu[a].count=0;
stu[a].score=0;
}
fp=fopen("stud","w"); /* Create a new file , Application for Function to write student information to a file .*/
for(a=0;a<SIZE;a++)
{
if(fwrite(&stu[a],sizeof(struct student),1,fp)!=1)
printf(" File input error .\n");
}
fclose(fp);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf(" The table is as follows :\n");
fp=fopen("stud","r"); /* Read the new file , And the output .*/
printf(" full name \t Gender \t Student number \t Number of missed classes \t Attendance score \n");
printf("----------------------------------------------\n");
for(a=0;a<SIZE;a++)
{
fread(&stu[a],sizeof(struct student),1,fp);
printf("%s \t%s \t%d \t%d \t%d\n",stu[a].name,stu[a].sex,stu[a].number,stu[a].count,stu[a].score);
}
fclose(fp);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("#######################################\n");
printf("# Record it #\n");
printf("# look forward to seeing you next time . #\n");
printf("#######################################\n");
start(); /* Return the auxiliary function of the main function , Main menu .*/
}
void search() /* The second sub function --search function , Used to query student information .*/
{
char b;
void search1();
void search2();
printf("****************************************\n");
printf(" Please select :\n");
printf(" 1. Search by name .\n");
printf(" 2. Search by student ID .\n");
printf("****************************************\n");
scanf("%s",&b);
switch(b) /* Application switch function , Form a selection structure , You can select query types .*/
{
case'1':search1();break; /* In the first 1 Functions of query types .*/
case'2':search2();break; /* In the first 2 Functions of query types .*/
default :printf("**** Incorrect input , Please re-enter :");search();
}
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("#######################################\n");
printf("# To find the end #\n");
printf("# look forward to seeing you next time . #\n");
printf("#######################################\n");
start(); /* Return the auxiliary function of the main function , Main menu .*/
}
void search1() /* The first 1 Functions of query types .*/
{
int c;
char student_name[9];
FILE *fp; /* Open the created file and output it to the screen .*/
fp=fopen("stud","r");
printf(" full name \t Gender \t Student number \t Number of missed classes \t Attendance score \n");
printf("----------------------------------------------\n");
for(c=0;c<SIZE;c++)
{
fread(&stu[c],sizeof(struct student),1,fp);
printf("%s \t%s \t%d \t%d \t%d\n",stu[c].name,stu[c].sex,stu[c].number,stu[c].count,stu[c].score);
}
fclose(fp);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf(" Please enter the name of the student to be queried :");
scanf("%s",student_name);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
for(c=0;c<SIZE;c++) /* Application for Circulation and strcmp The function compares the entered names one by one with the names of students in the list , Output the information of the student after finding the same .*/
{
if(strcmp(student_name,stu[c].name)==0)
{
printf(" Found *******************************************\n");
printf(" full name :%s Gender :%s Student number :%d Number of missed classes :%d\n",stu[c].name,stu[c].sex,stu[c].number,stu[c].count);
}
}
}
void search2() /* The first 2 Functions of query types .*/
{
int c;
int d;
FILE *fp;
fp=fopen("stud","r");
printf(" full name \t Gender \t Student number \t Number of missed classes \t Attendance score \n");
printf("----------------------------------------------\n");
for(c=0;c<SIZE;c++)
{
fread(&stu[c],sizeof(struct student),1,fp);
printf("%s \t%s \t%d \t%d \t%d\n",stu[c].name,stu[c].sex,stu[c].number,stu[c].count,stu[c].score);
}
fclose(fp);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf(" Please enter the student ID you want to query :");
scanf("%d",&d);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
for(c=0;c<SIZE;c++) /* Same as 1 Functions of query types , use for Cycle to compare the entered student ID with the student ID in the list one by one , Output the information of the student after finding the same .*/
{
if(d==stu[c].number)
{
printf(" Found *********************************************\n");
printf(" full name :%s Gender :%s Student number :%d Number of missed classes :%d\n",stu[c].name,stu[c].sex,stu[c].number,stu[c].count);
}
}
}
int add1() /* The third sub function --add function , Used to simulate attendance process .*/
{
int e,f,y;
struct name /* Build another one called name Array of structs .*/
{
char nam[9];
}na[300];
FILE *fp;
fp=fopen("stud","r"); /* Open the created file and output it to the screen .*/
for(e=0;e<SIZE;e++)
{
fread(&stu[e],sizeof(struct student),1,fp);
printf("%s \t%s \t%d \t%d \t%d\n",stu[e].name,stu[e].sex,stu[e].number,stu[e].count,stu[e].score);
}
fclose(fp);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("***************************\n");
printf(" Simulated attendance starts .\n");
printf("***************************\n");
for(e=0;e<CLASS;e++) /* Application for Nesting of loops , towards name Enter the name in the structure , Then compare with the student names in the list one by one .*/
{
printf(" Please enter the first %d The names of the students who have not arrived in the class shall be marked with 'over' end :",e+1);
for(y=0;y<=SIZE;y++)
{
scanf("%s",na[y].nam);
for(f=0;f<SIZE;f++)
{
if(strcmp(na[y].nam,stu[f].name)==0) /* If the name entered is the same as that of a student , In its count Add... To the information of 1.*/
stu[f].count++;
}
if(strcmp(na[y].nam,"over")==0) /* The loop ends , encounter "over", Exit loop .*/
break;
}
}
fp=fopen("stud","w"); /* Write the new list data to the original file .*/
for(e=0;e<SIZE;e++)
{
if(fwrite(&stu[e],sizeof(struct student),1,fp)!=1)
printf(" File input error .\n");
}
fclose(fp);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf(" Simulated attendance completed , give the result as follows :\n");
fp=fopen("stud","r"); /* Open the updated file and output it to the screen .*/
printf(" full name \t Gender \t Student number \t Number of missed classes \n");
printf("-------------------------\n");
for(f=0;f<SIZE;f++)
{
fread(&stu[f],sizeof(struct student),1,fp);
printf("%s \t%s \t%d \t%d\n",stu[f].name,stu[f].sex,stu[f].number,stu[f].count);
}
fclose(fp);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("#######################################\n");
printf("# Attendance check completed #\n");
printf("# look forward to seeing you next time . #\n");
printf("#######################################\n");
start(); /* Return the auxiliary function of the main function .*/
}
void mark() /* The fourth sub function --mark function , Used to calculate attendance score .*/
{
int g;
FILE *fp; /* Open the updated file and output it to the screen .*/
fp=fopen("stud","r+");
printf(" full name \t Gender \t Student number \t Number of missed classes \n");
printf("----------------------------------------------\n");
for(g=0;g<SIZE;g++)
{
fread(&stu[g],sizeof(struct student),1,fp);
printf("%s \t%s \t%d \t%d\n",stu[g].name,stu[g].sex,stu[g].number,stu[g].count);
}
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("********************************\n");
printf(" Scoring start .\n");
printf("********************************\n");
for(g=0;g<SIZE;g++) /* use for Cycle the scoring process .*/
{
stu[g].score=(100-stu[g].count*5); /* Five points will be deducted for missing a class .*/
if(stu[g].score<0)
stu[g].score=0;
}
fclose(fp);
fp=fopen("stud","w"); /* Write the updated student list information into the original file .*/
for(g=0;g<SIZE;g++)
{
if(fwrite(&stu[g],sizeof(struct student),1,fp)!=1)
printf(" File input error .\n");
}
fclose(fp);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf(" give the result as follows :\n");
fp=fopen("stud","r"); /* Open the updated file and output it to the screen .*/
printf(" full name \t Gender \t Student number \t Number of missed classes \t Attendance score \n");
printf("----------------------------------------------\n");
for(g=0;g<SIZE;g++)
{
fread(&stu[g],sizeof(struct student),1,fp);
printf("%s \t%s \t%d \t%d \t%d\n",stu[g].name,stu[g].sex,stu[g].number,stu[g].count,stu[g].score);
}
fclose(fp);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("#######################################\n");
printf("# After scoring #\n");
printf("# look forward to seeing you next time . #\n");
printf("#######################################\n");
start(); /* Return the auxiliary function of the main function , Main menu .*/
}
You can pay attention to it, and it will be updated continuously in the future 0.0( Thank you first )
边栏推荐
- Application of IT service management (ITSM) in Higher Education
- Pychart configuring jupyter
- [summary of knowledge points] chi square distribution, t distribution, F distribution
- [postgraduate entrance examination advanced mathematics Wu Zhongxiang +880 version for personal use] advanced mathematics Chapter II Basic Stage mind map
- [self use of advanced mathematics in postgraduate entrance examination] advanced mathematics Chapter 1 thinking map in basic stage
- High order binary balanced tree
- 分布式锁实现
- Discrimination between left and right limits of derivatives and left and right derivatives
- 【#Unity Shader#自定义材质面板_第一篇】
- How does the port scanning tool help enterprises?
猜你喜欢
[enterprise data security] upgrade backup strategy to ensure enterprise data security
【KV260】利用XADC生成芯片温度曲线图
SQL语句
【ManageEngine卓豪】网络运维管理是什么,网络运维平台有什么用
Make Tiantou village sweet. Is Xianjing taro or cabbage the characteristic agricultural product of Tiantou Village
【Unity Shader 描边效果_案例分享第一篇】
MongoDB:一、MongoDB是什么?MongoDB的优缺点
SystemVerilog learning-08-random constraints and thread control
[unity shader amplify shader editor (ASE) Chapter 9]
Promise
随机推荐
[ManageEngine Zhuohao] what is network operation and maintenance management and what is the use of network operation and maintenance platform
What is a port scanning tool? What is the use of port scanning tools
C语言课设工资管理系统(大作业)
Record MySQL troubleshooting caused by disk sector damage
证券类开户有什么影响 开户安全吗
Picture server project test
Redis安装到Windows系统上的详细步骤
Tidb database characteristics summary
Forkjoin and stream flow test
请求模块(requests)
C语言课设学生考勤系统(大作业)
webapck打包原理--启动过程分析
Diffusion (multi-source search)
Mysql 表分区创建方法
kubeadm搭建kubenetes 集群(个人学习版)
分布式锁实现
High order binary search tree
sql中TCL语句(事务控制语句)
Distributed lock implementation
Projects and dependencies in ABP learning solutions