first commit

master
929847918@qq.com 6 years ago
parent 1d787fc460
commit d36fae10f2

@ -0,0 +1,325 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct time
{
int hour;
int minute;
};
struct student
{
int no;
int classno;
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 printf_student(STU *head);
int menu_select();
void student_write(STU *head);
STU *student_read();
int main()
{
STU *head;
int n=1,k=0;
while(n)
{
switch(menu_select())
{
if(k==1)
{
head=student_read();
}
case 1:
{
system("cls");
head=create_student();
student_write(head);
printf("初始化信息成功信息已成功录入student文件\n");
k=1;
break;
}
case 2:
{
system("cls");
end_money(head);
break;
}
case 3:
{
system("cls");
select_no(head);
break;
}
case 4:
{
system("cls");
select_classno(head);
break;
}
case 5:
{
system("cls");
select_name(head);
break;
}
case 7:
{
system("cls");
add_student(head);
break;
}
case 8:
{
system("cls");
delect_student(head);
break;
}
case 0:
{
n=0;
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,*tail;
int no,classno,flag=1;
char name[20];
int begin_hour,begin_minute,end_hour,end_minute;
while(flag)
{
p=(STU*)malloc(sizeof(STU));
printf("请输入学号");
scanf("%d",&no);
printf("请输入班级");
scanf("%d",&classno);
printf("请输入姓名");
scanf("%s",&name);
printf("请输入上机时间");
scanf("%d%d",&begin_hour,&begin_minute);
printf("请输入下机时间");
scanf("%d%d",&end_hour,&end_minute);
p->no=no;
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_minute;
p->next=NULL;
if(head==NULL)
{
head=p;
}
else
{
tail->next=p;
}
tail=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->end.hour-p->begin.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;p=p->next)
{
if(no==p->no)
printf("学号:%d班级%d姓名%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;
int classno;
printf("请输入班级:\n");
scanf("%d",&classno);
for(p=head;p;p=p->next)
{
if(classno==p->classno)
printf("学号:%d班级%d姓名%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班级%d姓名%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,classno,begin_hour,begin_minute,end_hour,end_minute;
char name[20];
scanf("%d%d%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;
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,*q;
int no;
p=head;
printf("请输入学号\n");
scanf("%d",&no);
if(p->next->no==no)
{
q=p->next;
p->next=q->next;
free(q);
}
printf("删除成功!\n");
}
void student_write(STU *head)
{
STU *p;
int i;
p=head;
pf=fopen("student.txt","a+");
if(pf!=NULL)
{
while(p)
{
fprintf(pf,"%d%d%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;
}
}
else
{
printf("error!\n");
exit(0);
}
fclose(pf);
}
STU *student_read()
{
char name[20];
int no,classno,begin_hour,begin_minute,end_hour,end_minute;
STU *head,*p,*q;
pf=fopen("student.txt","a+");
head=p=(STU*)malloc(sizeof(STU));
while(fscanf(pf,"%d%d%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;
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;
}

Binary file not shown.
Loading…
Cancel
Save