|

楼主 |
发表于 2019-6-11 20:05:11
|
显示全部楼层
- #include<time.h>
- #include<stdio.h>
- #include<string.h>
- #include<Windows.h>
- #define N 20
- #define M 100
- struct student
- {
- char id[N];
- char theclass[N];
- char name[N];
- char ontime[N];
- } student[M];
- int n;
- void addition()
- {
- int i;
- printf("\n请输入入录学生信息在总数:");
- scanf("%d",&n);
- for(i=1;i<=n;i++)
- {
- printf("\n\t请输入第%d个学生学号:",i);
- scanf("%s",student[i-1].id);
- printf("\n\t请输入第%d个学生班级:",i);
- scanf("%s",student[i-1].theclass);
- printf("\n\t请输入第%d个学生学号:",i);
- scanf("%s",student[i-1].name);
- printf("\n\t请输入第%d个学生学号:",i);
- scanf("%s",student[i-1].ontime);
- printf("\n\t提示:您已经成功录入第%d条信息\n",i);
- }
- }
- void calculate()
- {
- int hours;
- char times[30];time_t rawtime;
- struct tm*timeinfo;
- time(&rawtime);
- timeinfo=localtime(&rawtime);
- strcpy(times,asctime(timeinfo));
- printf("\t所有学生上机费用如下:\n");
- for(int i=1;i<=n;i++)
- {
- printf("学生%d费用:",i);
- if((student[i-1].ontime[3]-48)*10+student[i-1].ontime[4]>(times[14]-48)*10+times[15])hours=(times[11]-48)*10+times[12]-(student[i-1].ontime[0]-48)*10-student[i-1].ontime[1];
- else
- hours=(times[11]-48)*10+times[12]-(student[i-1].ontime[0]-48)*10-student[i-1].ontime[1]+1;
- printf("%d\n",hours);
- }
- }
- void search()
- {
- int i,b,c,count;
- do
- {
- char find[20];
- printf("\n请选择查询方式:1.根据学号查询;2.根据班级查询;3.根据姓名查询;4.根据上机时间:");
- scanf("%d",&b);
- switch(b)
- {
- case 1 : count=PF_FLOATING_POINT_PRECISION_ERRATA;
- printf("\n**请输入学生的学号:");
- scanf("%s",find);
- for(i=0;i<n;i++)
- {
- if(strcmp(student[i].id,find)==0)
- {
- count++;
- if (count==PF_FLOATING_POINT_EMULATED)
- printf("学生学号\t学生班级\t学生姓名\t上机时间\n");
- printf("%8s%15s%15s%17s",student[i].id,student[i].theclass,student[i].name,student[i].ontime);
- }
- }
- if(!count)
- printf("****提示:该学生不存在");
- goto A;
- case 2 :count=PF_FLOATING_POINT_PRECISION_ERRATA;
- printf("\n**请输入学生的班级:");
- scanf("%s",find);
- for(i=0;i<n;i++)
- {
- if(strcmp(student[i].id,find)==0)
- {
- count++;
- if (count==PF_FLOATING_POINT_EMULATED)
- printf("学生学号\t学生班级\t学生姓名\t上机时间\n");
- printf("%8s%15s%15s%17s",student[i].id,student[i].theclass,student[i].name,student[i].ontime);
- }
- }
- if(!count)
- printf("****提示:该学生不存在");
- goto A;
- case 3 :count=PF_FLOATING_POINT_PRECISION_ERRATA;
- printf("\n**请输入学生的姓名:");
- scanf("%s",find);
- for(i=0;i<n;i++)
- {
- if(strcmp(student[i].id,find)==0)
- {
- count++;
- if (count==PF_FLOATING_POINT_EMULATED)
- printf("学生学号\t学生班级\t学生姓名\t上机时间\n");
- printf("%8s%15s%15s%17s",student[i].id,student[i].theclass,student[i].name,student[i].ontime);
- }
- }
- if(!count)
- printf("****提示:该学生不存在");
- goto A;
- case 4 :count=PF_FLOATING_POINT_PRECISION_ERRATA;
- printf("\n**请输入学生的上机时间:");
- scanf("%s",find);
- for(i=0;i<n;i++)
- {
- if(strcmp(student[i].id,find)==0)
- {
- count++;
- if (count==PF_FLOATING_POINT_EMULATED)
- printf("学生学号\t学生班级\t学生姓名\t上机时间\n");
- printf("%8s%15s%15s%17s",student[i].id,student[i].theclass,student[i].name,student[i].ontime);
- }
- }
- if(!count)
- printf("****提示:该学生不存在");
- goto A;
- default:printf("****提示:该学生不存在");
- }
- A:printf("\n\t**1.继续\n\t**0.返回主菜单");
- printf("\n\t 请输入您的选择:");
- scanf("%d",&c);
- }
- while(c);
- }
- void menu()
- {
- printf("\n\t*******************欢迎进入机房收费管理系统!*******************\n");
- printf("\t**1.录入功能**\n");
- printf("\t**2.计算功能**\n");
- printf("\t**3.查询功能**\n");
- printf("\t**4.***EXIT***\n");
- printf("\n\t请输入您的选择:");
- }
- void main()
- {
- system("color 5f");
- int a;
- C:menu();
- scanf("%d",&a);
- switch(a)
- {
- case 4 :printf("***正在退出**谢谢使用本系统,再见");break;
- case 1 :addition();
- goto C;
- case 2 :calculate();
- goto C;
- case 3 :search();
- goto C;
- }
- }
复制代码 |
|