背景描述:在网上接了个单,写一个大作业程序,也是我的第一个千行程序。发在博客上以作纪念。
注:由于是在clion上写的,故有一个cmakelist.
注:作者英语不太好,所以说有表达错误的地方包容一下
主要的设计框架遵循下图:
1.Cmakelist.txt
cmake_minimum_required(VERSION 3.21)
project(jiehuo C)
set(CMAKE_C_STANDARD 11)
add_executable(jiehuo main.c headfile.h administrator.c students.c main_oriented.c)
2.headfile.h (头文件,声明了自定义的函数,以及一些全局变量)
#ifndef JIEHUO_HEADFILE_H //条件编译
#define JIEHUO_HEADFILE_H
extern int n_students; //声明全局变量
extern int n_daily_check;
extern int n_imu;
extern int n_ap;
extern int n_nat;
extern int students_cnt; //此是专门用于学生端的一个数据
//对象
typedef struct apply{ //离校申请
int start_time[3]; //year,month,day 起始时间
int end_time[3]; //year,month,day 结束时间
char number[10]; //学号
char cause[25]; //理由
char start_place[20]; //出发地
char end_place[20]; //目的地
char opinion[25]; //审核状态
char result[25]; //审核结果
}Apply;
typedef struct numcleic_test{ //核酸检测
int year; //日期
int month;
int day;
char number[10]; //学号
char place[10]; //地点
char result; //检测结果(用阴性和阳性的英文首字母表示)
}NAT;
typedef struct daily_check{ //每日健康检测
int year; //日期
int month;
int day;
float tempture[3]; //体温:morning,afternoon,evening
char number[10]; //学号
char cough; //是否咳嗽(Y/n)
char fever; //是否发烧(Y/n)
}DC;
typedef struct immune{ //疫苗接种
int year; //日期
int month;
int day;
int times_num; //第几次接种疫苗
char number[10]; //学号
char place[10]; //接种地点
char type[10]; //疫苗类型
}Immune;
typedef struct students{ //学生
char password[7]; //密码
char tel[11]; //电话
char number[10]; //学号
char email[10]; //电子邮箱
char department[10]; //院系
char class[10]; //班级
char name[10]; //名字
char address[10]; //地址
}Students;
//全部的函数声明
//main_oriented
void menu();
int check_password_admin();
int check_password_students(Students *students);
void load_students(Students *students);
void load_DC(DC *daily_check);
void load_Imu(Immune *imu);
void load_Nat(NAT *nat);
void load_AP(Apply *ap);
void save_students(Students *students);
void save_DC(DC *daily_check);
void save_Imu(Immune *imu);
void save_Nat(NAT *nat);
void save_AP(Apply *ap);
//administrator
int administrator_system(Apply *ap,Students *students,NAT *nat,Immune *immune,DC *daily_check);
//students
int students_system(Apply *ap,Students *students,NAT *nat,Immune *immune,DC *daily_check);
#endif //JIEHUO_HEADFILE_H
3.main.c (主程序)
//administrator password: 123456
#include <stdio.h>
#include "headfile.h" //引用头文件
#define MAX_SIZE 40 //最大容量
int n_students; //全局变脸,确定每种数据的条数
int n_daily_check;
int n_imu;
int n_nat;
int n_ap;
int students_cnt;
int main() {
Students students[MAX_SIZE]; //定义几种数据类型的结构体数组
NAT nat[MAX_SIZE];
DC daily_check[MAX_SIZE];
Immune imu[MAX_SIZE];
Apply ap[MAX_SIZE];
load_students(students); //加载文件数据
load_AP(ap);
load_DC(daily_check);
load_Imu(imu);
load_Nat(nat);
while(1) {
menu(); //输出菜单
printf("enter your choice :\n");
int choice;
scanf("%d",&choice);
switch (choice) { //选择结构
case 1:
if(check_password_admin() == 0) { //密码登录系统
administrator_system(ap, students, nat, imu, daily_check); //进入管理员端
} else {
printf("Wrong password!\n");
}
break;
case 2:
if(check_password_students(students) == 0) { //密码登录系统
students_system(ap, students, nat, imu, daily_check); //进入学生端
} else {
printf("Wrong ID or password!\n");
}
break;
case 3: //保存文件数据
save_AP(ap);
save_DC(daily_check);
save_Imu(imu);
save_Nat(nat);
save_students(students);
printf("exit successfully!\n");
return 0;
default:
break;
}
}
}
4.main_oriented.c (主函数中要用到的一些函数)
#include "headfile.h"
#include <stdio.h>
#include <string.h>
void menu() { //主菜单
printf("*****************************************************\n");
printf(" 1.Administrator login \n");
printf(" 2.Students login \n");
printf(" 3.log out \n");
printf("*****************************************************\n");
printf("\n\n\n\n");
}
int check_password_admin() { //管理员密码验证
printf("\nPlease enter password : (6 numbers)\n");
char password[7];
scanf("%s",password);
if(strcmp(password,"123456") == 0) { //默认管理员密码为123456
printf("login...\n");
return 0;
} else {
return 1;
}
}
int check_password_students(Students *students) { //学生学号以及密码验证
char ID[10];
char password[7];
printf("\nPlease enter ID : \n");
scanf("%s",ID);
printf("\nPlease enter password : (6 numbers)\n");
scanf("%s",password);
students_cnt = n_students; //计数器,用于判断找不到的时候
for(int i = 0;i < n_students;i++) {
if(strcmp(ID,students[i].number) == 0) { //判断学号是否正确
students_cnt = i;
break;
}
}
if(students_cnt == n_students) { //学号不正确则退出
return 1;
}
if(strcmp(students[students_cnt].password,password) == 0) { //判断密码是否正确
printf("login...\n");
return 0;
} else {
return 1;
}
}
void load_students(Students *students) { //加载学生类数据文件
FILE *fp;
if((fp = fopen("../students.txt","r")) == NULL) { //判断打开是否成功
printf("Students open failed!\n");
} else {
fscanf(fp,"%d",&n_students); //读取学生数量
for(int i = 0;i < n_students;i++) { //读取每一条学生数据
fscanf(fp,"%s %s %s %s %s %s %s %s",students[i].number,students[i].password,
students[i].name,students[i].tel,students[i].email,students[i].department,
students[i].class,students[i].address);
}
printf("students load successfully!\n");
fclose(fp); //关闭文件
}
}
void load_DC(DC *daily_check) { //加载每日健康表类数据文件(类似学生)
FILE *fp;
if((fp = fopen("../DC.txt","r")) == NULL) {
printf("Dc open failed!\n");
} else {
fscanf(fp,"%d",&n_daily_check);
for(int i = 0;i < n_daily_check;i++) {
fscanf(fp,"%s %d %d %d %f %f %f %c %c",daily_check[i].number,&daily_check[i].year,
&daily_check[i].month,&daily_check[i].day,&daily_check[i].tempture[0],&daily_check[i].tempture[1],
&daily_check[i].tempture[2],&daily_check[i].cough,&daily_check[i].fever);
}
printf("DC load successfully!\n");
fclose(fp);
}
}
void load_Imu(Immune *imu) { //加载疫苗数据文件(类似学生)
FILE *fp;
if((fp = fopen("../DC.txt","r")) == NULL) {
printf("Imu open failed!\n");
} else {
fscanf(fp,"%d",&n_imu);
for(int i = 0;i < n_imu;i++) {
fscanf(fp,"%s %d %d %d %d %s %s",imu[i].number,&imu[i].times_num,&imu[i].year,&imu[i].month,
&imu[i].day,imu[i].place,imu[i].type);
}
printf("Imu load successfully!\n");
}
}
void load_Nat(NAT *nat) { //加载核酸检测类数据文件(类似学生)
FILE *fp;
if((fp = fopen("../NAT.txt","r")) == NULL) {
printf("Nat open failed!\n");
} else {
fscanf(fp,"%d",&n_nat);
for(int i = 0;i < n_nat;i++) {
fscanf(fp,"%s %d %d %d %d %c %c",nat[i].number,&nat[i].year,&nat[i].month,
&nat[i].month,&nat[i].day,nat[i].place,&nat[i].result);
}
printf("NAT load successfully!\n");
fclose(fp);
}
}
void load_AP(Apply *ap) { //加载离校申请类数据文件(类似学生)
FILE *fp;
if((fp = fopen("../AP.txt","r")) == NULL) {
printf("Apply open failed!\n");
} else {
fscanf(fp,"%d",&n_ap);
for(int i = 0;i < n_ap;i++) {
fscanf(fp,"%s %s %d %d %d %d %d %d %s %s %s %s",
ap[i].number,ap[i].cause,&ap[i].start_time[0],&ap[i].start_time[1],
&ap[i].start_time[2],&ap[i].end_time[0],&ap[i].end_time[1],&ap[i].end_time[2],
ap[i].start_place,ap[i].end_place,ap[i].opinion,ap[i].result);
}
printf("NAT load successfully!\n");
fclose(fp);
}
}
void save_students(Students *students) { //保存学生类数据文件
FILE *fp;
if((fp = fopen("../students.txt","w")) == NULL) { //判断文件是否打开并且覆盖原文件
printf("Students open failed!\n");
} else {
fprintf(fp,"%d\n",n_students); //输入学生数量
for(int i = 0;i < n_students;i++) { //输入每一条学生类数据
fprintf(fp,"%s %s %s %s %s %s %s %s\n",students[i].number,students[i].password,
students[i].name,students[i].tel,students[i].email,students[i].department,
students[i].class,students[i].address);
}
printf("students save successfully!\n");
fclose(fp);
}
}
void save_DC(DC *daily_check) { //保存每日健康检测类数据文件(类似学生)
FILE *fp;
if((fp = fopen("../DC.txt","w")) == NULL) {
printf("DC open failed!\n");
} else {
fprintf(fp,"%d\n",n_daily_check);
for(int i = 0;i < n_daily_check;i++) {
fprintf(fp,"%s %d %d %d %f %f %f %c %c\n",daily_check[i].number,daily_check[i].year,
daily_check[i].month,daily_check[i].day,daily_check[i].tempture[0],daily_check[i].tempture[1],
daily_check[i].tempture[2],daily_check[i].cough,daily_check[i].fever);
}
printf("DC save successfully!\n");
fclose(fp);
}
}
void save_Imu(Immune *imu) { //保存疫苗接种类数据文件(类似学生)
FILE *fp;
if((fp = fopen("../DC.txt","w")) == NULL) {
printf("Imu open failed!\n");
} else {
fprintf(fp,"%d\n",n_imu);
for(int i = 0;i < n_imu;i++) {
fprintf(fp,"%s %d %d %d %d %s %s\n",imu[i].number,imu[i].times_num,imu[i].year,imu[i].month,
imu[i].day,imu[i].place,imu[i].type);
}
printf("Imu save successfully!\n");
}
}
void save_Nat(NAT *nat) { //保存核酸检测类数据文件(类似学生)
FILE *fp;
if((fp = fopen("../NAT.txt","w")) == NULL) {
printf("Nat open failed!\n");
} else {
fprintf(fp,"%d\n",n_nat);
for(int i = 0;i < n_nat;i++) {
fprintf(fp,"%s %d %d %d %s %c\n",nat[i].number,nat[i].year,nat[i].month,
nat[i].day,nat[i].place,nat[i].result);
}
printf("NAT load successfully!\n");
fclose(fp);
}
}
void save_AP(Apply *ap) { //保存离校申请类数据文件(类似学生)
FILE *fp;
if((fp = fopen("../AP.txt","w")) == NULL) {
printf("Apply open failed!\n");
} else {
fprintf(fp,"%d\n",n_ap);
for(int i = 0;i < n_ap;i++) {
fprintf(fp,"%s %s %d %d %d %d %d %d %s %s %s %s\n",
ap[i].number,ap[i].cause,ap[i].start_time[0],ap[i].start_time[1],
ap[i].start_time[2],ap[i].end_time[0],ap[i].end_time[1],ap[i].end_time[2],
ap[i].start_place,ap[i].end_place,ap[i].opinion,ap[i].result);
}
printf("NAT save successfully!\n");
fclose(fp);
}
}
5.administrator.c (管理员端的实现)
#include "headfile.h"
#include <string.h>
#include <stdio.h>
//students_information_system
void meun_1() { //分菜单
printf("*****************************************************\n");
printf(" 1.Add \n");
printf(" 2.Delete \n");
printf(" 3.Back \n");
printf("*****************************************************\n");
printf("\n\n\n\n");
}
void add(Students *students) { //依次录入学生的每一个信息
n_students++;
printf("students number:\n");
scanf("%s",students[n_students-1].number);
printf("students password:\n");
scanf("%s",students[n_students-1].password);
printf("students name:\n");
scanf("%s",students[n_students-1].name);
printf("students tel:\n");
scanf("%s",students[n_students-1].tel);
printf("students email:\n");
scanf("%s",students[n_students-1].email);
printf("students department:\n");
scanf("%s",students[n_students-1].department);
printf("students class:\n");
scanf("%s",students[n_students-1].class);
printf("students address:\n");
scanf("%s",students[n_students-1].address);
printf("Add successfully!\n");
printf("\n\n\n");
}
void Delete(Apply *ap,Students *students,NAT *nat,Immune *immune,DC *daily_check) { //删除
printf("enter students number:\n");
char number[10]; //输入学号
scanf("%s",number);
for(int i = 0;i < n_ap;i++) { //以下是依据学号删除所有的学生信息
if(strcmp(number,ap[i].number) == 0) { //比较学号是否相同
for(int j = i;j < n_ap - 1;j++) {
ap[j] = ap[j+1];
}
n_ap--;
i--;
}
}
for(int i = 0;i < n_imu;i++) {
if(strcmp(number,immune[i].number) == 0) {
for(int j = i;j < n_imu - 1;j++) {
immune[j] = immune[j+1];
}
n_imu--;
i--;
}
}
for(int i = 0;i < n_nat;i++) {
if(strcmp(number,nat[i].number) == 0) {
for(int j = i;j < n_nat - 1;j++) {
nat[j] = nat[j+1];
}
n_nat--;
i--;
}
}
for(int i = 0;i < n_daily_check;i++) {
if(strcmp(number,daily_check[i].number) == 0) {
for(int j = i;j < n_daily_check - 1;j++) {
daily_check[j] = daily_check[j+1];
}
n_daily_check--;
i--;
}
}
for(int i = 0;i < n_students;i++) {
if(strcmp(number,students[i].number) == 0) {
for(int j = i;j < n_students - 1;j++) {
students[j] = students[j + 1];
}
n_students--;
printf("Delete successfully!\n");
break;
}
}
}
int students_information_system(Apply *ap,Students *students,NAT *nat,Immune *immune,DC *daily_check) { //分函数
while(1) { //无尽循环
meun_1(); //输出菜单
printf("enter your choice :\n");
int choice;
scanf("%d",&choice);
switch (choice) { //输入选择来执行不同函数
case 1:
add(students);
break;
case 2:
Delete(ap,students,nat,immune,daily_check);
break;
case 3:
printf("Back successfully!\n");
return 0;
default:
break;
}
}
}
//check_all_information
void meun_2() { //分菜单
printf("*****************************************************\n");
printf(" 1.Show daily health records \n");
printf(" 2.Show NAT records \n");
printf(" 3.Show immune records \n");
printf(" 4.Show applications \n");
printf(" 5.Show all students \n");
printf(" 6.Back \n");
printf("*****************************************************\n");
printf("\n\n\n\n");
}
void daily_health_records(DC *daily_check) { //展示每日健康记录
printf(" Daily Healthy Records \n");
printf("****************************************************************************************\n");
printf("ID Year Month Day t:mor t:after t:evening cough fever\n");
int cnt = 0; //计数器,判断是否有记录
for(int i = 0;i < n_daily_check;i++) { //输出所有的记录
printf("%s %d %d %d %f %f %f %c %c",
daily_check[i].number,daily_check[i].year,daily_check[i].month,daily_check[i].day,
daily_check[i].tempture[0],daily_check[i].tempture[1],daily_check[i].tempture[2],
daily_check[i].cough,daily_check[i].fever);
cnt++;
}
if(cnt == 0) { //若无记录的操作
printf("Not Found!\n");
}
printf("****************************************************************************************\n");
}
void NAT_records(NAT *nat) { //展示核酸检测记录(同上)
printf(" NAT Records \n");
printf("****************************************************************************************\n");
printf("ID Year Month Day Place Result \n");
int cnt = 0;
for(int i = 0;i < n_nat;i++) {
printf("%s %d %d %d %s %c \n",
nat[i].number,nat[i].year,nat[i].month,nat[i].day,nat[i].place,nat[i].result);
cnt++;
}
if(cnt == 0) {
printf("Not Found!\n");
}
printf("****************************************************************************************\n");
}
void Immune_records(Immune *immune) { //展示疫苗接种记录(同上)
printf(" Immune Records \n");
printf("****************************************************************************************\n");
printf("ID Times_num Year Month Day Place Type \n");
int cnt = 0;
for(int i = 0;i < n_imu;i++) {
printf("%s %d %d %d %d %s %s \n",
immune[i].number,immune[i].times_num,immune[i].year,immune[i].month,immune[i].day,
immune[i].place,immune[i].type);
cnt++;
}
if(cnt == 0) {
printf("Not Found!\n");
}
printf("****************************************************************************************\n");
}
void applications(Apply *ap) { //展示离校申请记录(同上)
printf(" Applications \n");
printf("*******************************************************************************************\n");
printf("ID Cause S:Year Month Day E:Year Month Day Start_P End_P Opinion Result\n");
int cnt = 0;
for(int i = 0;i < n_ap;i++) {
printf("%s %s %d %d %d %d %d %d %s %s %s %s \n",
ap[i].number,ap[i].cause,ap[i].start_time[0],ap[i].start_time[1],ap[i].start_time[2],ap[i].end_time[0],
ap[i].end_time[1],ap[i].end_time[2],ap[i].start_place,ap[i].end_place,ap[i].opinion,ap[i].result);
cnt++;
}
if(cnt == 0) {
printf("Not Found!\n");
}
printf("*******************************************************************************************\n");
}
void show_students(Students *students) { //展示学生记录(同上)
printf(" All Students \n");
printf("****************************************************************************************\n");
printf("ID Password Name Tel Email Depart Class Address\n");
int cnt = 0;
for(int i = 0;i < n_students;i++) {
printf("%s %s %s %s %s %s %s %s\n",
students[i].number,students[i].password,students[i].name,students[i].tel,
students[i].email,students[i].department,students[i].class,students[i].address);
cnt++;
}
if(cnt == 0) {
printf("Not Found!\n");
}
printf("****************************************************************************************\n");
}
int check_all_information(Apply *ap,Students *students,NAT *nat,Immune *immune,DC *daily_check) { //分函数
while(1) { //无尽循环
meun_2();
printf("enter your choice: \n");
int choice;
scanf("%d",&choice);
switch (choice) { //输入不同的选择执行不同功能
case 1:
daily_health_records(daily_check);
break;
case 2:
NAT_records(nat);
break;
case 3:
Immune_records(immune);
break;
case 4:
applications(ap);
break;
case 5:
show_students(students);
break;
case 6:
printf("Back Successfully!\n");
return 0;
default:
break;
}
}
}
//inquiring_system
void menu_3() { //分菜单
printf("*****************************************************\n");
printf(" 1.Check tempture \n");
printf(" 2.Check cough \n");
printf(" 3.Check fever \n");
printf(" 4.Back \n");
printf("*****************************************************\n");
printf("\n\n\n\n");
}
void check_temp(DC *daily_check) { //异常体温查询
int counter = 0; //计数器
printf(" Tempture ( > 37.3) \n");
printf("*****************************************************\n");
for(int i = 0;i < n_daily_check;i++) {
int cnt = 0;
for(int j = 0;j < 3;j++) { //判断体温是否大于37.3
if(daily_check[i].tempture[j] > 37.3) {
cnt++;
}
}
if(cnt != 0) { //有则输出
printf("ID : %s Date :(%d %d %d) Temp: (M:%f A:%f E:%f)\n",daily_check[i].number,daily_check[i].year,
daily_check[i].month,daily_check[i].day,daily_check[i].tempture[0],daily_check[i].tempture[1],
daily_check[i].tempture[2]);
counter++;
}
}
if(counter == 0) { //无则输出正常
printf("Normal!\n");
}
printf("*****************************************************\n");
}
void check_cough(DC *daily_check) { //咳嗽症状查询(同上)
int counter = 0;
printf(" Cough \n");
printf("*****************************************************\n");
for(int i = 0;i < n_daily_check;i++) {
if(daily_check[i].cough == 'Y' || daily_check[i].cough == 'y') {
printf("ID : %s Date :(%d %d %d) Cough = yes\n",daily_check[i].number,
daily_check[i].year,daily_check[i].month,daily_check[i].day);
counter++;
}
}
if(counter == 0) {
printf("Normal!\n");
}
printf("*****************************************************\n");
}
void check_fever(DC *daily_check) { //发烧症状查询(同上)
int counter = 0;
printf(" Fever \n");
printf("*****************************************************\n");
for(int i = 0;i < n_daily_check;i++) {
if(daily_check[i].fever == 'Y' || daily_check[i].fever == 'y') {
printf("ID : %s Date :(%d %d %d) Fever = yes\n",daily_check[i].number,
daily_check[i].year,daily_check[i].month,daily_check[i].day);
counter++;
}
}
if(counter == 0) {
printf("Normal!\n");
}
printf("*****************************************************\n");
}
int inquiring_system(DC *daily_check) { //分函数
while(1) { //无尽循环
menu_3(); //输出菜单
printf("enter your choice:\n");
int choice;
scanf("%d",&choice);
switch (choice) { //依据选择来进行操作
case 1:
check_temp(daily_check);
break;
case 2:
check_cough(daily_check);
break;
case 3:
check_fever(daily_check);
break;
case 4:
printf("Back successfully!\n");
return 0;
default:
break;
}
}
}
//statistics_analysis_system
void menu_4() { //分菜单
printf("*****************************************************\n");
printf(" 1.NAT times \n");
printf(" 2.Immune times \n");
printf(" 3.Apply times \n");
printf(" 4.Back \n");
printf("*****************************************************\n");
printf("\n\n\n\n");
}
void NAT_times(Students *students,NAT *nat) { //查询核酸记录少于五次的记录
printf(" NAT Times ( < 5) \n");
printf("*****************************************************\n");
printf("ID Times \n");
int counter = 0; //计数器
for(int i = 0;i < n_students;i++) {
int cnt = 0; //有则输出
for(int j = 0;j < n_nat;j++) {
if(strcmp(students[i].number,nat[j].number) == 0) {
cnt++;
}
}
if(cnt < 5) {
printf("%s %d \n",
students[i].number,cnt);
counter++;
}
}
if(counter == 0) { //没有记录
printf("Not Found!\n");
}
printf("*****************************************************\n");
}
void Immune_times(Students *students,Immune *immune) { //查询疫苗接种少于2次的记录(同上)
printf(" Immune Times ( < 5) \n");
printf("*****************************************************\n");
printf("ID Times \n");
int counter = 0;
for(int i = 0;i < n_students;i++) {
int cnt = 0;
for(int j = 0;j < n_imu;j++) {
if(strcmp(students[i].number,immune[j].number) == 0) {
cnt++;
}
}
if(cnt < 2) {
printf("%s %d \n",
students[i].number,cnt);
counter++;
}
}
if(counter == 0) {
printf("Not Found!\n");
}
printf("*****************************************************\n");
}
void Apply_times(Students *students,Apply *ap) { //查询离校申请多于5次的记录(同上)
printf(" Apply Times ( > 3) \n");
printf("*****************************************************\n");
printf("ID Times \n");
int counter = 0;
for(int i = 0;i < n_students;i++) {
int cnt = 0;
for(int j = 0;j < n_ap;j++) {
if(strcmp(students[i].number,ap[j].number) == 0) {
cnt++;
}
}
if(cnt > 3) {
printf("%s %d \n",
students[i].number,cnt);
counter++;
}
}
if(counter == 0) {
printf("Not Found!\n");
}
printf("*****************************************************\n");
}
int statistics_analysis_system(Apply *ap,Students *students,NAT *nat,Immune *immune) { //分函数(和其他分函数结构相同)
while(1) {
menu_4();
printf("enter your choice:\n");
int choice;
scanf("%d",&choice);
switch (choice) {
case 1:
NAT_times(students,nat);
break;
case 2:
Immune_times(students,immune);
break;
case 3:
Apply_times(students,ap);
break;
case 4:
printf("Back Successfully!\n");
return 0;
default:
break;
}
}
}
//applications_system
void menu_5() { //分菜单
printf("*****************************************************\n");
printf(" 1.Processing Applications \n");
printf(" 2.Back \n");
printf("*****************************************************\n");
printf("\n\n\n\n");
}
void process_ap(Apply *ap) { //处理离校申请
applications(ap); //展示所有的离校申请记录
printf("Edit NO.__ application.\n"); //选择编辑第几条记录
int num;
char opinion;
scanf("%d",&num);
printf("Agree or Not? (Y / N)\n"); //是否同意
scanf("%c",&opinion);
char temp1[10] = {"Finished"}; //编辑状态
char temp2[10] = {"Agree"};
char temp3[10] = {"Unapproved"};
strcpy(ap[num-1].opinion,temp1);
if(opinion == 'y' || opinion == 'Y' ) {
strcpy(ap[num-1].result,temp2);
} else {
strcpy(ap[num-1].result,temp3);
}
printf("Edit Successfully!\n");
}
int applications_system(Apply *ap) { //分函数(和其他分函数结构相同)
while(1) {
menu_5();
printf("enter your choice:\n");
int choice;
scanf("%d",&choice);
switch (choice) {
case 1:
process_ap(ap);
break;
case 2:
printf("Back Successfully!\n");
return 0;
default:
break;
}
}
}
//main
void main_menu() { //主菜单
printf("*****************************************************\n");
printf(" 1.students information system \n");
printf(" 2.check all information \n");
printf(" 3.inquiring system \n");
printf(" 4.statistics analysis system \n");
printf(" 5.applications for leaving \n");
printf(" 6.log out \n");
printf("*****************************************************\n");
printf("\n\n\n\n");
}
int administrator_system(Apply *ap,Students *students,NAT *nat,Immune *immune,DC *daily_check) { //主函数(和其他分函数的结构相同)
while(1) {
printf("Welcome,administrator!\n");
main_menu();
printf("enter your choice :\n");
int choice;
scanf("%d",&choice);
switch (choice) {
case 1:
students_information_system(ap,students,nat,immune,daily_check);
break;
case 2:
check_all_information(ap,students,nat,immune,daily_check);
break;
case 3:
inquiring_system(daily_check);
break;
case 4:
statistics_analysis_system(ap,students,nat,immune);
break;
case 5:
applications_system(ap);
break;
case 6:
printf("log out successfully!\n");
return 0;
default:
break;
}
}
}
6.students.c (学生端的实现)
#include "headfile.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//Edit system
void menu1() { //分菜单
printf("*****************************************************\n");
printf(" 1.Edit password \n");
printf(" 2.Edit telephone \n");
printf(" 3.Edit email \n");
printf(" 4.Edit address \n");
printf(" 5.Back \n");
printf("*****************************************************\n");
printf("\n\n\n\n");
}
void e_password(Students *students) { //编辑密码
printf("Please verify your password: (6 numbers)\n"); //验证密码
char password[7];
char make_sure[7];
scanf("%s",password);
if(strcmp(students[students_cnt].password,password) == 0) { //判断密码是否正确
printf("Please enter your new password: (6 numbers)\n"); //输入新密码
scanf("%s",password);
printf("Please enter again:\n"); //二次输入
scanf("%s",make_sure);
if(strcmp(make_sure,password) == 0) { //判断两次输入是否相同
strcpy(students[students_cnt].password,password);
printf("Edit Successfully!\n");
} else {
printf("Different password!\n");
}
} else {
printf("Wrong Password!\n");
}
}
void e_tel(Students *students) { //编辑电话
char tele[11];
printf("Please enter new telephone:\n");
scanf("%s",tele);
strcpy(students[students_cnt].tel,tele);
printf("Edit Successfully!\n");
}
void e_email(Students *students) { //编辑邮箱
char email[10];
printf("Please enter new email:\n");
scanf("%s",email);
strcpy(students[students_cnt].email,email);
printf("Edit Successfully!\n");
}
void e_address(Students *students) { //编辑地址
char address[10];
printf("Please enter your new address:\n");
scanf("%s",address);
strcpy(students[students_cnt].address,address);
printf("Edit Successfully!\n");
}
int Edit_infor(Students *students) { //分函数
while(1) { //无尽循环
menu1(); //输出菜单
printf("enter your choice:\n");
int choice;
scanf("%d",&choice);
switch (choice) { //依据选择做出不同操作
case 1:
e_password(students);
break;
case 2:
e_tel(students);
break;
case 3:
e_email(students);
break;
case 4:
e_address(students);
break;
case 5:
printf("Back Successfully!\n");
return 0;
default:
break;
}
}
}
//Fill information
void menu2() { //分菜单
printf("*****************************************************\n");
printf(" 1.Daily check \n");
printf(" 2.N.A.T. \n");
printf(" 3.Immune \n");
printf(" 4.Ask for leaving \n");
printf(" 5.Back \n");
printf("*****************************************************\n");
printf("\n\n\n\n");
}
void fill_DC(DC *daily_check,Students *students) { //填写每日健康检测数据
strcpy(daily_check[n_daily_check].number,students[students_cnt].number);
printf("Date: (Year,Month,Day)\n");
scanf("%d,%d,%d",&daily_check[n_daily_check].year,&daily_check[n_daily_check].month,
&daily_check[n_daily_check].day);
printf("Tempture : (Morning,Afternoon,Evening)\n");
scanf("%f,%f,%f",&daily_check[n_daily_check].tempture[0],&daily_check[n_daily_check].tempture[1],
&daily_check[n_daily_check].tempture[2]);
printf("Cough: (Y/n)\n");
scanf("%c",&daily_check[n_daily_check].cough);
printf("Fever: (Y/n)\n");
scanf("%c",&daily_check[n_daily_check].fever);
printf("Fill Successfully!\n");
n_daily_check++;
}
void fill_NAT(NAT *nat,Students *students) { //填写核酸检测数据
strcpy(nat[n_nat].number,students[students_cnt].number);
printf("Date: (Year,Month,Day)\n");
scanf("%d,%d,%d",&nat[n_nat].year,&nat[n_nat].month,&nat[n_nat].day);
printf("Place: \n");
scanf("%s",nat[n_nat].place);
printf("Result: (Y/n)\n");
scanf("%c",&nat[n_nat].result);
printf("Fill Successfully!\n");
n_nat++;
}
void fill_Imu(Immune *immune,Students *students) { //填写疫苗接种类数据
strcpy(immune[n_imu].number,students[students_cnt].number);
printf("NO.__ imu:\n");
scanf("%d",&immune[n_imu].times_num);
printf("Date: (Year,Month,Day)\n");
scanf("%d,%d,%d",&immune[n_imu].year,&immune[n_imu].month,&immune[n_imu].day);
printf("Place:\n");
scanf("%s",immune[n_imu].place);
printf("Type:\n");
scanf("%s",immune[n_imu].type);
printf("Fill Successfully!\n");
n_imu++;
}
void fill_apply(Apply *apply,Students *students) { //填写离校申请数据
strcpy(apply[n_ap].number,students[students_cnt].number);
printf("Reason:\n");
scanf("%s",apply[n_ap].cause);
printf("Start Date: (Year,Month,Day)\n");
scanf("%d,%d,%d",&apply[n_ap].start_time[0],&apply[n_ap].start_time[1],&apply[n_ap].start_time[2]);
printf("End Date: (Year,Month,Day)\n");
scanf("%d,%d,%d",&apply[n_ap].end_time[0],&apply[n_ap].end_time[1],&apply[n_ap].end_time[2]);
printf("Start place:\n");
scanf("%s",apply[n_ap].start_place);
printf("End place:\n");
scanf("%s",apply[n_ap].end_place);
char now[25] = {"Waiting for Checking!"};
char result[25] = {"Not Found!"};
strcpy(apply[n_ap].opinion,now);
strcpy(apply[n_ap].result,result);
printf("Fill Successfully!\n");
n_ap++;
}
int Fill_records(Apply *ap,Students *students,NAT *nat,Immune *immune,DC *daily_check) { //分函数(和其他分函数结构相同)
while(1) {
menu2();
printf("enter your choice:\n");
int choice;
scanf("%d",&choice);
switch (choice) {
case 1:
fill_DC(daily_check,students);
break;
case 2:
fill_NAT(nat,students);
break;
case 3:
fill_Imu(immune,students);
break;
case 4:
fill_apply(ap,students);
break;
case 5:
printf("Back Successfully!\n");
return 0;
default:
break;
}
}
}
//Check history
void menu3() { //分菜单
printf("*****************************************************\n");
printf(" 1.Check applications \n");
printf(" 2.Check daily health \n");
printf(" 3.Check immune records \n");
printf(" 4.Check N.A.T. records \n");
printf(" 5.Check By Time \n");
printf(" 6.Back \n");
printf("*****************************************************\n");
printf("\n\n\n\n");
}
void check_ap(Apply *ap,Students *students) { //查看离校申请记录
printf(" My Applications \n");
printf("*******************************************************************************************\n");
printf("ID Cause S:Year Month Day E:Year Month Day Start_P End_P Opinion Result\n");
int cnt = 0; //计数器
for(int i = 0;i < n_ap;i++) {
if(strcmp(ap[i].number,students[students_cnt].number) == 0) { //判断是否为该学生的记录
printf("%s %s %d %d %d %d %d %d %s %s %s %s \n",
ap[i].number, ap[i].cause, ap[i].start_time[0], ap[i].start_time[1], ap[i].start_time[2],
ap[i].end_time[0],
ap[i].end_time[1], ap[i].end_time[2], ap[i].start_place, ap[i].end_place, ap[i].opinion,
ap[i].result);
cnt++;
}
}
if(cnt == 0) { //若没有记录
printf("Not Found!\n");
}
printf("*******************************************************************************************\n");
}
void check_DC(DC *daily_check,Students *students) { //查看每日健康检测记录(同上)
printf(" My Daily Healthy Records \n");
printf("****************************************************************************************\n");
printf("ID Year Month Day t:mor t:after t:evening cough fever\n");
int cnt = 0;
for(int i = 0;i < n_daily_check;i++) {
if(strcmp(daily_check[i].number,students[students_cnt].number) == 0) {
printf("%s %d %d %d %f %f %f %c %c",
daily_check[i].number, daily_check[i].year, daily_check[i].month, daily_check[i].day,
daily_check[i].tempture[0], daily_check[i].tempture[1], daily_check[i].tempture[2],
daily_check[i].cough, daily_check[i].fever);
cnt++;
}
}
if(cnt == 0) {
printf("Not Found!\n");
}
printf("****************************************************************************************\n");
}
void check_Imu(Immune *immune,Students *students) { //查看疫苗接种记录(同上)
printf(" My Immune Records \n");
printf("****************************************************************************************\n");
printf("ID Times_num Year Month Day Place Type \n");
int cnt = 0;
for(int i = 0;i < n_imu;i++) {
if(strcmp(immune[i].number,students[students_cnt].number) == 0) {
printf("%s %d %d %d %d %s %s \n",
immune[i].number, immune[i].times_num, immune[i].year, immune[i].month, immune[i].day,
immune[i].place, immune[i].type);
cnt++;
}
}
if(cnt == 0) {
printf("Not Found!\n");
}
printf("****************************************************************************************\n");
}
void check_NAT(NAT *nat,Students *students) { //查看核酸检测记录(同上)
printf(" My NAT Records \n");
printf("****************************************************************************************\n");
printf("ID Year Month Day Place Result \n");
int cnt = 0;
for(int i = 0;i < n_nat;i++) {
if(strcmp(nat[i].number,students[students_cnt].number) == 0) {
printf("%s %d %d %d %s %c \n",
nat[i].number, nat[i].year, nat[i].month, nat[i].day, nat[i].place, nat[i].result);
cnt++;
}
}
if(cnt == 0) {
printf("Not Found!\n");
}
printf("****************************************************************************************\n");
}
void check_By_Time(Apply *ap,Students *students,NAT *nat,Immune *immune,DC *daily_check) { //按时间查看记录
int year,month,day;
printf("Please enter Date: (Year,Month,Day)\n");
scanf("%d,%d,%d",&year,&month,&day); //输入日期
printf(" My Daily Healthy Records \n"); //输出每一种该时间的记录
printf("****************************************************************************************\n");
printf("ID Year Month Day t:mor t:after t:evening cough fever\n");
int cnt_1 = 0;
for(int i = 0;i < n_daily_check;i++) {
if(year == daily_check[i].year && month == daily_check[i].month && day == daily_check[i].day) {
printf("%s %d %d %d %f %f %f %c %c",
daily_check[i].number, daily_check[i].year, daily_check[i].month, daily_check[i].day,
daily_check[i].tempture[0], daily_check[i].tempture[1], daily_check[i].tempture[2],
daily_check[i].cough, daily_check[i].fever);
cnt_1++;
}
}
if(cnt_1 == 0) {
printf("Not Found!\n");
}
printf("****************************************************************************************\n");
printf("\n");
printf(" My NAT Records \n");
printf("****************************************************************************************\n");
printf("ID Year Month Day Place Result \n");
int cnt_2 = 0;
for(int i = 0;i < n_nat;i++) {
if(year == nat[i].year && month == nat[i].month && day == nat[i].day) {
printf("%s %d %d %d %s %c \n",
nat[i].number, nat[i].year, nat[i].month, nat[i].day, nat[i].place, nat[i].result);
cnt_2++;
}
}
if(cnt_2 == 0) {
printf("Not Found!\n");
}
printf("****************************************************************************************\n");
printf("\n");
printf(" My Immune Records \n");
printf("****************************************************************************************\n");
printf("ID Times_num Year Month Day Place Type \n");
int cnt_3 = 0;
for(int i = 0;i < n_imu;i++) {
if(year == immune[i].year && month == immune[i].month && day == immune[i].day) {
printf("%s %d %d %d %d %s %s \n",
immune[i].number, immune[i].times_num, immune[i].year, immune[i].month, immune[i].day,
immune[i].place, immune[i].type);
cnt_3++;
}
}
if(cnt_3 == 0) {
printf("Not Found!\n");
}
printf("****************************************************************************************\n");
printf("\n");
}
int check_history(Apply *ap,Students *students,NAT *nat,Immune *immune,DC *daily_check) { //分函数(和其他分函数结构相同)
while(1) {
menu3();
printf("enter your choice:\n");
int choice;
scanf("%d",&choice);
switch (choice) {
case 1:
check_ap(ap,students);
break;
case 2:
check_DC(daily_check,students);
break;
case 3:
check_Imu(immune,students);
break;
case 4:
check_NAT(nat,students);
break;
case 5:
check_By_Time(ap,students,nat,immune,daily_check);
case 6:
printf("Back Successfully!\n");
return 0;
default:
break;
}
}
}
//main
void mainmenu() { //主菜单
printf("*****************************************************\n");
printf(" 1.Edit Information \n");
printf(" 2.Fill Records \n");
printf(" 3.Check history \n");
printf(" 4.log out \n");
printf("*****************************************************\n");
printf("\n\n\n\n");
}
int students_system(Apply *ap,Students *students,NAT *nat,Immune *immune,DC *daily_check) { //主函数
while(1) {
printf("Welcome,%s!\n",students[students_cnt].name);
mainmenu(); //输出菜单
printf("enter your choice :\n");
int choice;
scanf("%d",&choice);
switch (choice) { //按选择做出不同操作
case 1:
Edit_infor(students);
break;
case 2:
Fill_records(ap,students,nat,immune,daily_check);
break;
case 3:
check_history(ap,students,nat,immune,daily_check);
break;
case 4:
printf("log out successfully!\n");
return 0;
default:
break;
}
}
}
注:很多注释我认为在程序里面已经写的很清楚了,另外排版的地方有些做的不是很好,还有就是很多地方其实都是重复造轮子,个人认为最难的地方其实是在框架设计的方面。