#include<bits/stdc++.h>
using namespace std ;
struct student {
char stu_num[10];
char name[20];
char institute[20];
char temperature[8];
char isCough[5];
char time[10];
char data[10];
}stu,a[10];
bool ishealthy(string a ,string b) {
if(a[0]-'3'>0||(a[0]-'3'==0&&a[1]-'7'>0)||(a[0]-'3'==0&&a[1]-'7'==0&&a[3]-'3'>=0)||(b=="1")) {
return true;
} else {
return false;
}
}
bool cmp(student aa,student bb){
string aaa=aa.stu_num;
string bbb=bb.stu_num;
string ccc=aa.data;
string ddd=bb.data;
if(aaa==bbb){
return ccc<ddd;
}
else
return aaa>bbb;
}
void check(){
cout<<stu.stu_num[4]<<stu.stu_num[5]<<endl;
if(stu.stu_num[4]=='0'&&stu.stu_num[5]=='1'){
strcpy(stu.institute,"通信学院");
}
if(stu.stu_num[4]=='0'&&stu.stu_num[5]=='2'){
strcpy(stu.institute,"计算机学院");
}
if(stu.stu_num[4]=='0'&&stu.stu_num[5]=='3'){
strcpy(stu.institute,"光电学院");
}
if(stu.stu_num[4]=='0'&&stu.stu_num[5]=='4'){
strcpy(stu.institute,"自动化学院");
}
printf("%s\n",stu.institute);
}
void WriteInformation() {
stu = {0};
FILE *fp=fopen("C:\\Users\\Administrator\\Desktop\\data.txt","a");
printf("请按照下列提示完成信息录入:\n");
printf("请输入学号:\n");
getchar();
gets(stu.stu_num);
printf("--%s\n\n",stu.stu_num);
printf("请输入姓名:\n");
gets(stu.name);
printf("--%s\n\n",stu.name);
printf("请输入入校时的温度:\n");
gets(stu.temperature);
printf("--%s\n\n",stu.temperature);
printf("是否咳嗽(是:1/否:0):\n");
gets(stu.isCough);
printf("--%s\n\n",stu.isCough);
printf("请输入入校时间:\n");
gets(stu.time);
printf("--%s\n\n",stu.time);
printf("请输入入校日期:\n");
gets(stu.data);
printf("--%s\n\n",stu.data);
check();
printf("%s\n",stu.institute);
if(fp==NULL) {
printf("打开文件失败");
exit(0);
}
fprintf(fp,"%-20s%-20s%-20s%-20s%-20s%-20s%-20s\n",&stu.stu_num,&stu.name,&stu.institute,&stu.temperature,&stu.isCough,&stu.time,&stu.data);
fclose(fp);
}
void chazhao(){
printf("请输入要查找的学号和日期\n");
string xuehao,time="";
cin>>xuehao>>time;
FILE *fp=fopen("C:\\Users\\Administrator\\Desktop\\data.txt","r");
int i=0;
vector<student> ls;
while(fscanf(fp,"%s %s %s %s %s %s %s",&a[1].stu_num,&a[1].name,&a[1].institute,&a[1].temperature,&a[1].isCough,&a[1].time,&a[1].data)!=EOF){
ls.push_back(a[1]);
}
fclose(fp);
sort(ls.begin(),ls.end(),cmp);
for(int i=0;i<ls.size();i++){
string la=ls[i].stu_num;
string ldata=ls[i].data;
if(la==xuehao&&time>ldata){
FILE *fpp=fopen("C:\\Users\\Administrator\\Desktop\\data1.txt","w+");
fprintf(fpp,"%-20s%-20s%-20s%-20s%-20s%-20s%-20s\n",&ls[i].stu_num,&ls[i].name,&ls[i].institute,&ls[i].temperature,&ls[i].isCough,&ls[i].time,&ls[i].data);
fclose(fpp);
}
}
}
void xiugai(){
printf("请输入要修改的学号和日期\n");
string xuehao,time="";
cin>>xuehao>>time;
FILE *fp=fopen("C:\\Users\\Administrator\\Desktop\\data.txt","r");
int i=0;
vector<student> ls;
while(fscanf(fp,"%s %s %s %s %s %s %s",&a[1].stu_num,&a[1].name,&a[1].institute,&a[1].temperature,&a[1].isCough,&a[1].time,&a[1].data)!=EOF){
ls.push_back(a[1]);
}
fclose(fp);
for(int i=0;i<ls.size();i++){
string ax=ls[i].stu_num;
string at=ls[i].data;
if(ax==xuehao&&at==time){
printf("请输入要修改的项\n");
printf("1---学号\n2--姓名\n3--学院\n4--体温\n5--是否咳嗽\n6--时间\n7--日期\n");
int p=0;
scanf("%d",&p);
if(p==1){
char x[20];
printf("请输入内容\n");
scanf("%s",&x);
strcpy(ls[i].stu_num,x);
cout<<ls[i].stu_num<<endl;
}
else if(p==2){
}
else if(p==3){
}
}
}
FILE *fpp=fopen("C:\\Users\\Administrator\\Desktop\\data.txt","w+");
for(int i=0;i<ls.size();i++){
fprintf(fp,"%-20s%-20s%-20s%-20s%-20s%-20s%-20s\n",&ls[i].stu_num,&ls[i].name,&ls[i].institute,&ls[i].temperature,&ls[i].isCough,&ls[i].time,&ls[i].data);
}
}
void menu()
{
printf("--------------------学生返校信息管理系统-----------------------\n");
printf("= =\n");
printf("= ***功能介绍*** =\n");
printf("= =\n");
printf("= 1.录入学生信息 =\n");
printf("= 2.查找学生信息 =\n");
printf("= 3.修改学生信息 =\n");
printf("= 4.按顺序输出某学院学生信息 =\n");
printf("= 5.请求帮助 =\n");
printf("= 6.退出系统 =\n");
printf("= =\n");
printf("= =\n");
printf("============================================================\n");
return ;
}
struct datt{
string startdate;
int loop;
int* nexted;
};
int main() {
int password_time=5;
printf("\n\n");
printf("------------------欢迎使用学生返校健康管理系统--------------\n\n");
printf("请输入登录密码:");
while(password_time>0){
string password ;
cin>>password;
if(password=="123456"){
printf("密码输入正确!\n");
break;
}
else{
password_time--;
printf("密码输入错误,请重新输入,您还有%d次机会\n",password_time);
}
}
if(password_time==0){
printf("五次登录机会已用完,程序自动结束");
return 0;
}
menu();
string choose_judge="y";
printf("欢迎您使用本系统,请输入要进行的操作(数字)") ;
while(choose_judge=="y"){
string choose_sum="";
cin>>choose_sum;
if(choose_sum=="1"){
int Writeflag=1;
while(Writeflag==1) {
WriteInformation();
printf("是否继续录入1/0");
scanf("%d", &Writeflag);
}
}
else if(choose_sum=="2"){
chazhao();
}
else if(choose_sum=="3"){
xiugai();
}
else{
printf("输入错误!请重新输入!\n ");
continue;
}
printf("是否继续使用该系统(y/n):");
cin>>choose_judge;
}
system("cls");
printf("感谢您使用本系统,欢迎下次使用");
return 0;
}
|