You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

283 lines
6.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct time {
int hour;
int minute;
};
struct Student {
long int xuehao;
char banji[10];
char name[10];
int time_hour;
int time_minute;
struct time begin,end;
} ;
struct Student student[30];
static int i=0,j;
void save();
void insert();
void end_money();
void delete_student();
void select_xuehao();
void select_name();
void select_banji();
void show();
int main() {
int menu();
int i;
for(;;)
{
printf("\t\t*******************菜单**************\n");
printf("\t\t\n");
printf("\t\t\n");
printf("\t\t***************机房收费管理系统*******\n");
printf("\t\t\n");
printf("\t\t\n");
printf("\t\t1.###############输入学生信息:########\n");
printf("\t\t2.#################上机费用:##########\n");
printf("\t\t3.################删除档案:###########\n");
printf("\t\t4.################按学号查询:#########\n");
printf("\t\t5.################按班级查询:#########\n");
printf("\t\t6.################按姓名查询:#########\n");
printf("\t\t7.################显示学生信息:#######\n");
printf("\t\t8.##################退出系统:#########\n");
printf("\n\n\n\n请在1-8之间选择功能:");
scanf("%d",&i);
switch(i)
{
case 1:
{
system("cls");
insert();
}
break;
case 2:
{
system("cls");
end_money();
}
break;
case 3:
{
system("cls");
delete_student();
}
break;
case 4:
{
system("cls");
select_xuehao();
}
break;
case 5:
{
system("cls");
select_banji();
}
break;
case 6:
{
system("cls");
select_name();
}
break;
case 7:
{
system("cls");
show();
} break;
case 8:
{
exit(0);
}
break;
}
}
printf("\n"); system("pause");
save();
return 0;
}
void insert() {
printf("请输入学号:");
scanf("%ld",&student[i].xuehao);
printf("请输入姓名:");
scanf("%s",student[i].name);
printf("请输入班级:");
scanf("%s",student[i].banji);
printf("请输入上机时间:");
scanf("%d:%d",&student[i].begin.hour,&student[i].begin.minute);
i = i + 1;
printf("人数:%d",i);
j=i;
save();
printf("\n"); system("pause");
system("cls");
}
void end_money() {
int m,minute,hour;
long int xuehao;
printf("请输入学号:");
scanf("%ld",&xuehao);
for(m = 0; m < i; m++)
{
if(student[m].xuehao==xuehao)
{
printf("请输入%ld的下机时间:",xuehao);
scanf("%d:%d",&student[m].end.hour,&student[m].end.minute);
if(student[m].end.minute<student[m].begin.minute)
{
minute=student[m].end.minute+60
-student[m].begin.minute;
hour=student[m].end.hour-1-student[m].begin.hour;
student[m].time_hour = hour;
student[m].time_minute = minute;
}
else
{
minute=student[m].end.minute -student[m].begin.minute;
hour=student[m].end.hour -student[m].begin.hour;
student[m].time_hour = hour;
student[m].time_minute = minute;
}
if(minute > 0)
{
hour = hour + 1;
printf("上机时间为:%d:%d 费用为:%d",student[m].time_hour,student[m].time_minute,hour);
}
else {
printf("上机时间为:%d:%d\n 费用为:%d",student[m].time_hour,student[m].time_minute,hour);
}
}
}
save();
printf("\n"); system("pause");
system("cls");
}
void delete_student()
{
long int xuehao;
int m;
printf("请输入学号:");
scanf("%ld",&xuehao);
if(i==1)
{
if(student[m].xuehao==xuehao)
printf("没有数据!");
}
else{
for(m=0;m<i-1;m++)
if(student[m].xuehao==xuehao)break;
for(;m<i;m++) student[m]=student[m+1];
}
save();
printf("\n");
system("pause");
system("cls");
}
void select_xuehao() {
long int xuehao;
int m;
printf("请输入学号:");
scanf("%ld",&xuehao);
for(m = 0; m < i; m++)
{
if(student[m].xuehao==xuehao)
{
printf("学号:%ld\t",student[m].xuehao);
printf(" 班级:%s\t",student[m].banji);
printf("姓名:%s\t",student[m].name);
printf(" 上机开始时间:%d:%d\t",student[m].begin.hour,student[m].begin.minute);
printf("上机结束时间:%d:%d\t",student[m].end.hour,student[m].end.minute);
printf("上机时间:%d:%d\n\t",student[m].time_hour,student[m].time_minute);
}
else if( m == i)
{
printf("没有该生记录:\n");
}
}
save();
printf("\n"); system("pause");
system("cls");
}
void select_banji() {
char banji[10];
int m;
printf("请输入班级:");
scanf("%s",banji);
for(m = 0; m < i; m++)
{
if(!strcmp(banji,student[m].banji)) {
printf("学号是:%ld\t",student[m].xuehao);
printf("班级是:%s\t",student[m].banji);
printf("姓名是:%s\t",student[m].name);
printf("上机开始时间:%d:%d\t",student[m].begin.hour,student[m].begin.minute);
printf("上机结束时间:%d:%d\t",student[m].end.hour,student[m].end.minute);
printf("上机时间为:%d:%d\n",student[m].time_hour,student[m].time_minute);
}
else if( m == i)
{
printf("没有该生记录:\n");
}
}save();
printf("\n"); system("pause");
system("cls");
}
void select_name()
{char name[10];
int m;
printf("请输入姓名:");
scanf("%s",name);
for(m=0;m<i;m++)
{
if(!strcmp(name,student[m].name))
{
printf("学号为%ld\t",student[m].xuehao);
printf("班级为%s\t",student[m].banji);
printf("姓名为%s\t",student[m].name);
printf("上机开始时间:%d:%d\t",student[m].begin.hour,student[m].begin.minute);
printf("上机结束时间:%d:%d\t",student[m].end.hour,student[m].end.minute);
printf("上机时间为:%d:%d\n",student[m].time_hour,student[m].time_minute);
}
else if(m==i)
{
printf("没有记录:\n");
}
}save();
system("pause");
system("cls");
}
void save()
{
FILE *fp;
int m;
fp=fopen("学生机房管理.txt","w");
for(m=0;m<i;m++)
{
fprintf(fp,"%ld %s %s %d %d %d %d %d %d %d %d\n",student[m].xuehao,student[m].banji,student[m].name,student[m].begin.hour,student[m].begin.minute,student[m].end.hour,student[m].end.minute,student[m].time_hour,student[m].time_minute);
}
fclose(fp);
}
void show()
{
int m;
printf("学号 班级 姓名 上机时间 下机时间 用时\n");
for(m=0;m<i;m++)
{printf("%ld %s %s %d:%d %d:%d %d:%d\n",student[m].xuehao,student[m].banji,student[m].name,student[m].begin.hour,student[m].begin.minute,student[m].end.hour,student[m].end.minute,student[m].time_hour,student[m].time_minute);
}
system("pause");
system("cls");
}