|
|
@ -0,0 +1,335 @@
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct time
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int hour;
|
|
|
|
|
|
|
|
int minute;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct student
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int no;
|
|
|
|
|
|
|
|
char classno[20];
|
|
|
|
|
|
|
|
char name[20];
|
|
|
|
|
|
|
|
struct time begin,end;
|
|
|
|
|
|
|
|
struct student *next;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FILE *pf;
|
|
|
|
|
|
|
|
typedef struct student STU;
|
|
|
|
|
|
|
|
STU *create_student();
|
|
|
|
|
|
|
|
void end_money(STU *head);
|
|
|
|
|
|
|
|
void select_no(STU *head);
|
|
|
|
|
|
|
|
void select_classno(STU *head);
|
|
|
|
|
|
|
|
void select_name(STU *head);
|
|
|
|
|
|
|
|
void add_student(STU *head);
|
|
|
|
|
|
|
|
void delect_student(STU *head);
|
|
|
|
|
|
|
|
void change_student(STU *head);
|
|
|
|
|
|
|
|
void printf_student(STU *head);
|
|
|
|
|
|
|
|
int menu_select();
|
|
|
|
|
|
|
|
void show_all(STU *head);
|
|
|
|
|
|
|
|
void student_file(STU *head);
|
|
|
|
|
|
|
|
STU *studebt_open();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
STU *head;
|
|
|
|
|
|
|
|
int n=1;
|
|
|
|
|
|
|
|
while(n)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch(menu_select())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
head=create_student();
|
|
|
|
|
|
|
|
student_file(head);
|
|
|
|
|
|
|
|
printf("初始化信息成功!(信息已成功录入student文件)\n");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
head=studebt_open();
|
|
|
|
|
|
|
|
end_money(head);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
head=studebt_open();
|
|
|
|
|
|
|
|
select_no(head);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
head=studebt_open();
|
|
|
|
|
|
|
|
select_classno(head);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
head=studebt_open();
|
|
|
|
|
|
|
|
select_name(head);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
head=studebt_open();
|
|
|
|
|
|
|
|
change_student(head);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
head=studebt_open();
|
|
|
|
|
|
|
|
add_student(head);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
head=studebt_open();
|
|
|
|
|
|
|
|
delect_student(head);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 9:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
head=studebt_open();
|
|
|
|
|
|
|
|
show_all(head);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
n=0;
|
|
|
|
|
|
|
|
student_file(head);
|
|
|
|
|
|
|
|
printf("本次操作成功,已录入在案!\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
system("pause");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int menu_select()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
printf("\t\t**************************************\t\t\n");
|
|
|
|
|
|
|
|
printf("1.__初始化学生信息\n");
|
|
|
|
|
|
|
|
printf("2.__结账\n");
|
|
|
|
|
|
|
|
printf("3.__按学号查询\n");
|
|
|
|
|
|
|
|
printf("4.__按班级查询\n");
|
|
|
|
|
|
|
|
printf("5.__按姓名查询\n");
|
|
|
|
|
|
|
|
printf("6.__修改学生上机档案\n");
|
|
|
|
|
|
|
|
printf("7.__增添学生信息\n");
|
|
|
|
|
|
|
|
printf("8.__删除学生信息\n");
|
|
|
|
|
|
|
|
printf("9.__显示全部上机学生信息\n");
|
|
|
|
|
|
|
|
printf("0.__退出系统\n");
|
|
|
|
|
|
|
|
printf("\t\t*****请选择想要实现的功能序号*****\t\t\n");
|
|
|
|
|
|
|
|
scanf("%d",&i);
|
|
|
|
|
|
|
|
return i;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
STU *create_student()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
STU *p,*head;
|
|
|
|
|
|
|
|
int no,flag=1;
|
|
|
|
|
|
|
|
char classno[20],name[20];
|
|
|
|
|
|
|
|
int i,n,begin_hour,begin_minute,end_hour,end_minute;
|
|
|
|
|
|
|
|
while(flag)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
p=(STU*)malloc(sizeof(STU));
|
|
|
|
|
|
|
|
printf("请输入学号");
|
|
|
|
|
|
|
|
scanf("%d",&no);
|
|
|
|
|
|
|
|
printf("请输入班级");
|
|
|
|
|
|
|
|
scanf("%s",&classno);
|
|
|
|
|
|
|
|
printf("请输入姓名");
|
|
|
|
|
|
|
|
scanf("%s",&name);
|
|
|
|
|
|
|
|
printf("请输入上机时间");
|
|
|
|
|
|
|
|
scanf("%d%d",&begin_hour,&begin_minute);
|
|
|
|
|
|
|
|
printf("请输入下机时间");
|
|
|
|
|
|
|
|
scanf("%d%d",&end_hour,&end_minute);
|
|
|
|
|
|
|
|
p->next=NULL;
|
|
|
|
|
|
|
|
head->next=p;
|
|
|
|
|
|
|
|
head=p;
|
|
|
|
|
|
|
|
printf("停止输入请按0继续输入请按1\n");
|
|
|
|
|
|
|
|
scanf("%d",&flag);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return head;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void end_money(STU *head)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
STU *p;
|
|
|
|
|
|
|
|
float m,k=0.1;
|
|
|
|
|
|
|
|
int minute,hour;
|
|
|
|
|
|
|
|
int no;
|
|
|
|
|
|
|
|
printf("请输入学号:\n");
|
|
|
|
|
|
|
|
scanf("%d",&no);
|
|
|
|
|
|
|
|
for(p=head;p;p=p->next)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(no==p->no)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(p->end.minute<p->begin.minute){
|
|
|
|
|
|
|
|
p->begin.hour--;
|
|
|
|
|
|
|
|
minute=p->end.minute+60-p->begin.minute;
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
minute=p->end.minute-p->begin.minute;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
hour=p->begin.hour-p->end.hour;
|
|
|
|
|
|
|
|
minute=hour*60+minute;
|
|
|
|
|
|
|
|
m=minute*k;
|
|
|
|
|
|
|
|
printf("本次上机时间为%d分钟,消费金额为%f元(注:上机0.1元/分钟)\n",minute,m);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void select_no(STU *head)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
STU *p;
|
|
|
|
|
|
|
|
int no;
|
|
|
|
|
|
|
|
printf("请输入学号:\n");
|
|
|
|
|
|
|
|
scanf("%d",&no);
|
|
|
|
|
|
|
|
for(p=head;p->next;p=p->next)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(no==p->no)
|
|
|
|
|
|
|
|
printf("学号:%d班级:%s姓名:%s上机时间:%d:%d下机时间:%d:%d\n",p->no,p->classno,p->name,p->begin.hour,p->begin.minute,p->end.hour,p->end.minute);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void select_classno(STU *head)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
STU *p;
|
|
|
|
|
|
|
|
char classno[20];
|
|
|
|
|
|
|
|
printf("请输入班级:\n");
|
|
|
|
|
|
|
|
scanf("%s",&classno);
|
|
|
|
|
|
|
|
for(p=head;p;p=p->next)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(strcmp(classno,p->classno)==0)
|
|
|
|
|
|
|
|
printf("学号:%s班级:%s姓名:%s上机时间:%d:%d下机时间:%d:%d\n",p->no,p->classno,p->name,p->begin.hour,p->begin.minute,p->end.hour,p->end.minute);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void select_name(STU *head)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
STU *p;
|
|
|
|
|
|
|
|
char name[20];
|
|
|
|
|
|
|
|
printf("请输入姓名:\n");
|
|
|
|
|
|
|
|
scanf("%s",&name);
|
|
|
|
|
|
|
|
for(p=head;p;p=p->next)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(strcmp(name,p->name)==0)
|
|
|
|
|
|
|
|
printf("学号:%d班级:%s姓名:%s上机时间:%d:%d下机时间:%d:%d\n",p->no,p->classno,p->name,p->begin.hour,p->begin.minute,p->end.hour,p->end.minute);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void change_student(STU *head)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
STU *p;
|
|
|
|
|
|
|
|
int no;
|
|
|
|
|
|
|
|
printf("请输入该学生的学号:\n");
|
|
|
|
|
|
|
|
scanf("%d",&no);
|
|
|
|
|
|
|
|
for(p=head;p;p=p->next)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(no==p->no)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("请输入修改后的上机时间、下机时间:\n");
|
|
|
|
|
|
|
|
scanf("%d%d%d%d",&p->begin.hour,&p->begin.minute,&p->end.hour,&p->end.minute);
|
|
|
|
|
|
|
|
printf("%d%d%d%d",p->begin.hour,p->begin.minute,p->end.hour,p->end.minute);
|
|
|
|
|
|
|
|
printf("修改成功!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void show_all(STU *head)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
STU *p;
|
|
|
|
|
|
|
|
for(p=head;p;p=p->next){
|
|
|
|
|
|
|
|
printf("学号:%d班级:%s姓名:%s上机时间:%d:%d下机时间:%d:%d\n",p->no,p->classno,p->name,p->begin.hour,p->begin.minute,p->end.hour,p->end.minute);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void add_student(STU *head)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
STU *p,*q;
|
|
|
|
|
|
|
|
int no,begin_hour,begin_minute,end_hour,end_minute;
|
|
|
|
|
|
|
|
char classno[20],name[20];
|
|
|
|
|
|
|
|
scanf("%d%s%s%d%d%d%d",&no,&classno,&name,&begin_hour,&begin_minute,&end_hour,&end_hour);
|
|
|
|
|
|
|
|
for(p=head;p;p=p->next)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(p->next->next==NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
p->no=no;
|
|
|
|
|
|
|
|
strcpy(p->classno,classno);
|
|
|
|
|
|
|
|
strcpy(p->name,name);
|
|
|
|
|
|
|
|
p->begin.hour=begin_hour;
|
|
|
|
|
|
|
|
p->begin.minute=begin_minute;
|
|
|
|
|
|
|
|
p->end.hour=end_hour;
|
|
|
|
|
|
|
|
p->end.minute=end_hour;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void delect_student(STU *head)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
STU *p;
|
|
|
|
|
|
|
|
int no;
|
|
|
|
|
|
|
|
printf("请输入学号\n");
|
|
|
|
|
|
|
|
scanf("%d",&no);
|
|
|
|
|
|
|
|
for(p=head;p;p=p->next)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(p->next->no==no){
|
|
|
|
|
|
|
|
p=p->next;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void student_file(STU *head)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
STU *p;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
p=head->next;
|
|
|
|
|
|
|
|
pf=fopen("student.txt","w+");
|
|
|
|
|
|
|
|
if(pf!=NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
while(p)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fprintf(pf,"%d%s%s%d%d%d%d",p->no,p->classno,p->name,p->begin.hour,p->begin.minute,p->end.hour,p->end.minute);
|
|
|
|
|
|
|
|
p=p->next;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(pf,"\n");
|
|
|
|
|
|
|
|
fclose(pf);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
STU *studebt_open()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
char classno[20],name[20];
|
|
|
|
|
|
|
|
int no,begin_hour,begin_minute,end_hour,end_minute;
|
|
|
|
|
|
|
|
STU *head,*p,*q;
|
|
|
|
|
|
|
|
pf=fopen("student.txt","r");
|
|
|
|
|
|
|
|
head=p=(STU*)malloc(sizeof(STU));
|
|
|
|
|
|
|
|
while(fscanf(pf,"%d%s%s%d%d%d%d",&no,&classno,&name,&begin_hour,&begin_minute,&end_hour,&end_minute)!=EOF)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
q=(STU*)malloc(sizeof(STU));
|
|
|
|
|
|
|
|
q->no=no;
|
|
|
|
|
|
|
|
strcpy(q->classno,classno);
|
|
|
|
|
|
|
|
strcpy(q->name,name);
|
|
|
|
|
|
|
|
q->begin.hour=begin_hour;
|
|
|
|
|
|
|
|
q->begin.minute=begin_minute;
|
|
|
|
|
|
|
|
q->end.hour=end_hour;
|
|
|
|
|
|
|
|
q->end.minute=end_minute;
|
|
|
|
|
|
|
|
p->next=q;
|
|
|
|
|
|
|
|
p=q;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(pf);
|
|
|
|
|
|
|
|
return head;
|
|
|
|
|
|
|
|
}
|