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.
238 lines
5.2 KiB
238 lines
5.2 KiB
#include<stdio.h>
|
|
#include<string.h>
|
|
#include<stdlib.h>
|
|
void insert();//录入学生信息
|
|
void findCLASS();//按班级查询
|
|
void findNO();//按学号查询//
|
|
void findNAME();//按姓名查询
|
|
void money();//结账
|
|
void addstu();//添加学生
|
|
void addfile(); //添加到文件
|
|
struct time//时间结构体
|
|
{
|
|
int hour;
|
|
int min;
|
|
};
|
|
struct STUDENT//学生结构体
|
|
{
|
|
|
|
char NO[20];
|
|
char CLASS[20];
|
|
char NAME[20];
|
|
int time_hour;
|
|
int time_min;
|
|
struct time begin,end;//嵌套定义学生结构体
|
|
};
|
|
struct STUDENT stu[30];
|
|
static int i=0;
|
|
|
|
int main()//主函数
|
|
{
|
|
int i;
|
|
for(;;)
|
|
{ //主界面
|
|
printf("\t\t\t*********************\n");
|
|
printf("\t\t\t 菜单 \n");
|
|
printf("\t\t\t1 创建学生信息\n");
|
|
printf("\t\t\t2 按学号查找学生信息\n");
|
|
printf("\t\t\t3 按班级查找学生\n");
|
|
printf("\t\t\t4 按姓名查找学生\n");
|
|
printf("\t\t\t5 上机费用\n");
|
|
printf("\t\t\t6 添加学生信息\n");
|
|
printf("\t\t\t7 添加学生信息到文件\n");
|
|
printf("\t\t\t8 关闭系统");
|
|
printf("\n\n\n\t\t\t输入相应序号进行操作\n\n\t\t\t");
|
|
scanf("%d",&i);
|
|
switch(i)//选择分支结构
|
|
{
|
|
case 1:
|
|
{
|
|
system("cls");
|
|
insert();
|
|
|
|
}break;
|
|
case 2:
|
|
{
|
|
system("cls");
|
|
findNO();
|
|
}break;
|
|
case 3:
|
|
{
|
|
system("cls");
|
|
findCLASS();
|
|
} break;
|
|
case 4:
|
|
{
|
|
system("cls");
|
|
findNAME();
|
|
}break;
|
|
case 5:
|
|
{
|
|
system("cls");
|
|
money();
|
|
}break;
|
|
case 6:
|
|
{
|
|
system("cls");
|
|
addstu();
|
|
}break;
|
|
|
|
case 7:
|
|
{
|
|
system("cls");
|
|
addfile();
|
|
}break;
|
|
case 8:
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
system("pause") ;
|
|
return 0;
|
|
}
|
|
void insert()//录入
|
|
{
|
|
printf("请输入学生学号:\n");
|
|
scanf("%s",&stu[i].NO);
|
|
printf("请输入学生班级:\n");
|
|
scanf("%s",&stu[i].CLASS);
|
|
printf("请输入学生姓名:\n");
|
|
scanf("%s",&stu[i].NAME);
|
|
printf("请输入起始时间:\n");
|
|
scanf("%d:%d",&stu[i].begin.hour,&stu[i].begin.min);
|
|
i=i+1;
|
|
system("pause");
|
|
system("cls");
|
|
}
|
|
void findNO()//学号查找
|
|
{
|
|
int m;
|
|
char no[100];
|
|
printf("输入学号:");
|
|
scanf("%s",&no);
|
|
for(m=0;m<i;m++)
|
|
{
|
|
if(!strcmp(no,stu[m].NO))
|
|
{
|
|
printf("学号是:%s\n",stu[m].NO);
|
|
printf("班级是:%s\n",stu[m].CLASS);
|
|
printf("姓名是:%s\n",stu[m].NAME);
|
|
printf("起始时间是:%d:%d\n",stu[m].begin.hour,stu[m].begin.min);
|
|
|
|
|
|
}
|
|
else printf("查无此人\n");
|
|
system("pause");
|
|
system("cls");
|
|
}
|
|
|
|
}
|
|
void findCLASS()//班级查找
|
|
{
|
|
char class[100];
|
|
int m;
|
|
printf("请输入班级:");
|
|
scanf("%s",&class);
|
|
for(m=0;m<i;m++)
|
|
{
|
|
if(!strcmp(class,stu[m].CLASS))
|
|
{
|
|
printf("学号是:%s\n",stu[m].NO);
|
|
printf("班级是:%ld\n",stu[m].CLASS);
|
|
printf("姓名是:%s\n",stu[m].NAME);
|
|
printf("起始时间是:%d:%d\n",stu[m].begin.hour,stu[m].begin.min);
|
|
|
|
}
|
|
else printf("查无此人\n");
|
|
}
|
|
system("pause");
|
|
system("cls");
|
|
}
|
|
void findNAME()//姓名查找
|
|
{
|
|
char name[100];
|
|
int m;
|
|
printf("请输入姓名:");
|
|
scanf("%s",name);
|
|
for(m=0;m<i;m++)
|
|
{
|
|
if(!strcmp(name,stu[m].NAME))
|
|
{
|
|
printf("学号是:%s\n",stu[m].NO);
|
|
printf("班级是:%s\n",stu[m].CLASS);
|
|
printf("姓名是:%s\n",stu[m].NAME);
|
|
printf("起始时间是:%d:%d\n",stu[m].begin.hour,stu[m].begin.min);
|
|
|
|
}
|
|
else printf("查无此人\n");
|
|
}
|
|
|
|
system("pause");
|
|
system("cls");
|
|
}
|
|
void money()//结账功能
|
|
{
|
|
int m,min0,hour,min1,time;
|
|
char no[100];
|
|
double money;
|
|
printf("请输入学号:");
|
|
scanf("%s",&no);
|
|
for(m=0;m<i;m++)
|
|
{
|
|
if(!strcmp(no,stu[m].NO))
|
|
{
|
|
|
|
printf("请输入截止时间:");
|
|
scanf("%d:%d",&stu[m].end.hour,&stu[m].end.min);
|
|
min0=stu[m].end.min+60-stu[m].begin.min;
|
|
min1=(stu[m].end.hour-(stu[m].begin.hour+1))*60;
|
|
time=min0+min1;
|
|
money=time*0.1;
|
|
printf("起始时间是:%d:%d\n",stu[m].begin.hour,stu[m].begin.min);
|
|
printf("你的学号是:%s\n",stu[m].NO);
|
|
printf("你的班级是:%s\n",stu[m].CLASS);
|
|
printf("你的姓名是:%s\n",stu[m].NAME);
|
|
printf("你需要支付:¥");
|
|
printf("%.2lf\n",money);
|
|
}
|
|
|
|
}
|
|
|
|
system("pause");
|
|
system("cls");
|
|
}
|
|
void addstu()//添加学生
|
|
{
|
|
printf("请输入添加学生信息:\n");
|
|
printf("请输入学生学号:\n");
|
|
scanf("%s",&stu[i].NO);
|
|
printf("请输入学生班级:\n");
|
|
scanf("%s",&stu[i].CLASS);
|
|
printf("请输入学生姓名:\n");
|
|
scanf("%s",&stu[i].NAME);
|
|
printf("请输入起始时间:\n");
|
|
scanf("%d:%d",&stu[i].begin.hour,&stu[i].begin.min);
|
|
FILE *fp;//写入文件
|
|
fp=fopen("账单.txt","ab");
|
|
fwrite(&stu[i],sizeof(struct STUDENT),1,fp);
|
|
printf("\n") ;
|
|
fclose(fp);
|
|
system("pause");
|
|
system("cls");
|
|
|
|
}
|
|
void addfile()//添加到文件
|
|
{ FILE *fp;
|
|
int j;
|
|
fp=fopen("账单.txt","ab");
|
|
for(j=0;j<=i-1;j++)
|
|
fwrite(&stu[j],sizeof(struct STUDENT),1,fp);
|
|
printf("\n") ;
|
|
fclose(fp);
|
|
}
|
|
|