Open likey003 opened 8 months ago
char head[][COL_LEN_MAX] = { "学号","姓名","班级","座位号","上机时长","费用" };//表格的表头信息 int a[MAX_STUDENTNUMBER];//定义数组记录机位是否被占用 int curcount = 0;//记录学生人数 void menu() {//菜单 system("cls");//清屏 printTableHead(WIN_WIDTH);//打印表头 printTableMidInfo(WIN_WIDTH,"机房收费管理系统");//打印居中信息 printTableMidInfo(WIN_WIDTH, " "); const char s[] = { "1.添加学生信息", "2.删除学生信息", "3.修改学生信息", "4.机器使用情况", "5.打印学生总信息及其费用", "6.查询学生信息", "0.退出系统" }; int count = sizeof(s) / sizeof(s[0]); for (int i = 0; i < count; i++) { printTableMidInfo(WIN_WIDTH, s[i]);//利用循环输出菜单 } printTableMidInfo(WIN_WIDTH, " "); printTableTail(WIN_WIDTH); printMidInfo("请输入0-6:"); } void BGM() { mciSendString("open 可不可以.mp3", 0, 0, 0); mciSendString("play 可不可以.mp3", 0, 0, 0); } struct Student { char idnumber[100];//学号 char name[10];//姓名 char clas[20];//班级 int seat;//座位号 int time;//时长 int money;//费用 }stu[MAX_STUDENTNUMBER];//定义学生的结构体数组 void init() { char cmd[128];//设置控制台窗口 sprintf(cmd, "mode con lines=%d cols=%d", WIN_HEIGHT, WIN_WIDTH); system(cmd); system("color e4");//设置背景和文本颜色 menu(); memset(stu, 0, sizeof(stu)); FILE fp = fopen("学生管理", "rb");//保存文件的操作 if (fp == NULL) { curcount = 0; return; } int i = 0; while (!feof) { int ret = fread(&stu, sizeof(struct Student), 1, fp); if (ret) { i++; } } curcount = i;//统计学生人数
} void waitconfirm() { rewind(stdin);//清空缓存区 getch();//不需要按下回车 } int save() { FILE fp= fopen("添加学生信息", "wb");//保存文件的操作 if (fp==NULL) {//判断是否为空 return 0; } for (int i = 0; i <curcount; i++) { if (fwrite(&stu[i], sizeof(struct Student), 1, fp)) { fclose(fp); return 1; } else { fclose(fp); return 0; } } } int searchstudent(const char idnumber) { for ( int i = 0; i < curcount; i++) {//判断是否学号出现相同 if (strcmp(stu[i].idnumber, idnumber) == 0) { return i; } } return -1; } void search() { system("cls"); printf("剩余的空机位有:\n"); for (int i = 1; i < MAX_STUDENTNUMBER; i++) { a[i] = 0; } for (int i = 0; i < curcount; i++) { a[stu[i].seat] = 1; } for (int i = 0; i < MAX_STUDENTNUMBER-1; i++) { if (i % 10 == 0) { printf("\n"); } if(!a[i+1]) printf("%2d ", i+1); } printf("\n已占用的机位有:"); for (int i = 0; i < MAX_STUDENTNUMBER - 1; i++) { if (a[i+1]) printf("%2d ", i+1); } } void add() { while (1) { system("cls"); rewind(stdin);
printf("请输入学号:"); while (1) { scanf("%s", stu[curcount].idnumber); if (searchstudent(stu[curcount].idnumber)>=0) { printf("您输入的学号已存在,请重新输入:"); } else { break; } } printf("请输入姓名:"); scanf("%s", stu[curcount].name); printf("请输入班级:"); scanf("%s", stu[curcount].clas); printf("请输入需要上机的时长(分钟):"); scanf("%d", &stu[curcount].time); search(); printf("\n请输入机位(1-30):"); while (1) { scanf("%d", &stu[curcount].seat); if (stu[curcount].seat < 1 || stu[curcount].seat>30) { printf("你输入的机位不存在,请重新输入机位(1-30):"); continue; } break; } stu[curcount].money = ((stu[curcount].time -1)/ 60)+1;//向上取整 curcount++; if (!save) { printf("保存学生信息失败"); } else { printf("保存学生信息成功\n\n是否继续录入(y/n):"); } waitconfirm(); char str[] = "hfws"; scanf("%s", str); if (strcmp(str, "y") == 0) { continue; } break; }
} void showpage(int start,int end) { if (end >= curcount) {//判断最大编是否大于总人数 end = curcount - 1; } if (end - start + 1 >= perpage) { end = start + perpage - 1; } system("cls"); printTableHead(TABLE_WIDTH, 6);//输出表头 printTableRow(TABLE_WIDTH, head, sizeof(head) / sizeof(head[0]));//将表头信息打入 printTableMidLine(TABLE_WIDTH, 6);//打印表格中线 char r[6][COL_LEN_MAX]; for (int i = start; i <= end; i++) {//将学生信息存入二维数组 sprintf(r[0], "%s", stu[i].idnumber); sprintf(r[1], "%s", stu[i].name); sprintf(r[2], "%s", stu[i].clas); sprintf(r[3], "%d", stu[i].seat); sprintf(r[4], "%d", stu[i].time); sprintf(r[5], "%d", stu[i].money); printTableRow(TABLE_WIDTH, r, 6);//遍历输出 if (i < end) {//判断是否为最后一行,若是最后一行则打印表尾 printTableMidLine(TABLE_WIDTH,6); } else { printTableTail(TABLEWIDTH, 6); } } } void printstdent() { system("cls"); if (curcount == 0) { printf("还没有录入学生信息\n"); return ; } int pagecount = (curcount + perpage - 1) / perpage;//表格页数 char beff[64]; for (int i = 0; i < pagecount; i++) { showpage(iperpage,(i+1) perpage -1);//打印学生信息 sprintf(beff,"共%d页,第[%d]页", pagecount, i + 1);//打印底部页码信息 printMidInfo(beff); if (i < pagecount - 1) { waitconfirm(); } } } void earse() { system("cls"); int k, flag = 0; //k保存下标,flag用于判断信息是否删除成功 char num2[50]; printf("-----------【删除学生信息】-----------\n"); printf("请输入要删除学生的学号:"); scanf("%s", num2); for (int i = 0; i < curcount; i++) { if (strcmp(stu[i].idnumber,num2)==0) { k = i; flag = 1; break; } } if (flag) { for (int j = k; j < curcount - 1; j++)//要删除学生后面的学生往前移一位 { strcpy(stu[j].idnumber, stu[j + 1].idnumber); strcpy(stu[j].name, stu[j + 1].name); strcpy(stu[j].clas, stu[j + 1].clas); stu[j].seat = stu[j + 1].seat; stu[j].time = stu[j + 1].time; stu[j].money = stu[j + 1].money; } curcount--; printf("删除成功\n"); } else { printf("该学号不存在!!!\n"); } } void modify() { system("cls"); printf("-----------【修改学生信息】-----------\n"); printf("请输入要修改学生的座位号:"); int seat,flag=0; scanf("%d", &seat);//先查找要修改的学生信息 for (int i = 0; i <curcount; i++) { if (stu[i].seat == seat) { flag = 1; printf("查到此学生!\n"); printf("请输入修改后的学号!\n"); scanf("%s", stu[i].idnumber); printf("请输入修改后的姓名!\n"); scanf("%s", stu[i].name); printf("请输入修改后的班级!\n"); scanf("%s", stu[i].clas); search(); printf("请输入修改后的座位号!\n"); scanf("%d", &stu[i].seat); printf("修改信息成功\n"); break; } } if (!flag) { printf("该学号不存在!!!"); } } void search() { system("cls"); printf("请输入您需要查询的学生的学号:"); char number[50]; scanf("%s", number); int i = searchstudent(number); if (i>=0) { char r[6][COL_LEN_MAX]; printTableHead(TABLE_WIDTH, 6);//输出表头 printTableRow(TABLE_WIDTH, head, sizeof(head) / sizeof(head[0]));//将表头信息打入 printTableMidLine(TABLE_WIDTH, 6);//打印表格中线 sprintf(r[0], "%s", stu[i].idnumber); sprintf(r[1], "%s", stu[i].name); sprintf(r[2], "%s", stu[i].clas); sprintf(r[3], "%d", stu[i].seat); sprintf(r[4], "%d", stu[i].time); sprintf(r[5], "%d", stu[i].money); printTableRow(TABLE_WIDTH, r, 6);//遍历输出 printTableTail(TABLE_WIDTH, 6); } else { printf("没有查到该学生的信息"); } } int main(void) { init();//创建窗口 BGM(); MessageBox(NULL, TEXT("欢迎来到机房收费管理系统"), TEXT("提示"), MBOK);//弹出提示窗 int n=520; while (1) { scanf("%d", &n); switch (n) { case 1: add();break;//添加学生信息 case 2: earse(); break;//删除学生信息 case 3: modify(); break;//修改学生信息 case 4: search(); break;//机位信息 case 5: printstdent(); break;//打印学生信息 case 6: search(); break;//查询学生信息 case 0: MessageBox(NULL, TEXT("欢迎您的下次使用,最后这是送您的爱心(请耐心等待一会)"), TEXT("提示"), MB_OK); heart(); exit(0); default: printf("请输入有效数字:\t"); break; } waitconfirm();//等待确认 menu();
} system("pause"); return 0;
}
include
include
include
include
include"tablePrint.h"
include
pragma comment(lib,"winmm.lib")
define MAX_STUDENTNUMBER 31//最大学生数量
define perpage 9//表格每页的最大学生数量
char head[][COL_LEN_MAX] = { "学号","姓名","班级","座位号","上机时长","费用" };//表格的表头信息 int a[MAX_STUDENTNUMBER];//定义数组记录机位是否被占用 int curcount = 0;//记录学生人数 void menu() {//菜单 system("cls");//清屏 printTableHead(WIN_WIDTH);//打印表头 printTableMidInfo(WIN_WIDTH,"机房收费管理系统");//打印居中信息 printTableMidInfo(WIN_WIDTH, " "); const char s[] = { "1.添加学生信息", "2.删除学生信息", "3.修改学生信息", "4.机器使用情况", "5.打印学生总信息及其费用", "6.查询学生信息", "0.退出系统" }; int count = sizeof(s) / sizeof(s[0]); for (int i = 0; i < count; i++) { printTableMidInfo(WIN_WIDTH, s[i]);//利用循环输出菜单 } printTableMidInfo(WIN_WIDTH, " "); printTableTail(WIN_WIDTH); printMidInfo("请输入0-6:"); } void BGM() { mciSendString("open 可不可以.mp3", 0, 0, 0); mciSendString("play 可不可以.mp3", 0, 0, 0); } struct Student { char idnumber[100];//学号 char name[10];//姓名 char clas[20];//班级 int seat;//座位号 int time;//时长 int money;//费用 }stu[MAX_STUDENTNUMBER];//定义学生的结构体数组 void init() { char cmd[128];//设置控制台窗口 sprintf(cmd, "mode con lines=%d cols=%d", WIN_HEIGHT, WIN_WIDTH); system(cmd); system("color e4");//设置背景和文本颜色 menu(); memset(stu, 0, sizeof(stu)); FILE fp = fopen("学生管理", "rb");//保存文件的操作 if (fp == NULL) { curcount = 0; return; } int i = 0; while (!feof) { int ret = fread(&stu, sizeof(struct Student), 1, fp); if (ret) { i++; } } curcount = i;//统计学生人数
} void waitconfirm() { rewind(stdin);//清空缓存区 getch();//不需要按下回车 } int save() { FILE fp= fopen("添加学生信息", "wb");//保存文件的操作 if (fp==NULL) {//判断是否为空 return 0; } for (int i = 0; i <curcount; i++) { if (fwrite(&stu[i], sizeof(struct Student), 1, fp)) { fclose(fp); return 1; } else { fclose(fp); return 0; } } } int searchstudent(const char idnumber) { for ( int i = 0; i < curcount; i++) {//判断是否学号出现相同 if (strcmp(stu[i].idnumber, idnumber) == 0) { return i; } } return -1; } void search() { system("cls"); printf("剩余的空机位有:\n"); for (int i = 1; i < MAX_STUDENTNUMBER; i++) { a[i] = 0; } for (int i = 0; i < curcount; i++) { a[stu[i].seat] = 1; } for (int i = 0; i < MAX_STUDENTNUMBER-1; i++) { if (i % 10 == 0) { printf("\n");
} if(!a[i+1]) printf("%2d ", i+1); } printf("\n已占用的机位有:"); for (int i = 0; i < MAX_STUDENTNUMBER - 1; i++) { if (a[i+1]) printf("%2d ", i+1); } } void add() { while (1) { system("cls"); rewind(stdin);
} void showpage(int start,int end) { if (end >= curcount) {//判断最大编是否大于总人数 end = curcount - 1; } if (end - start + 1 >= perpage) { end = start + perpage - 1; } system("cls"); printTableHead(TABLE_WIDTH, 6);//输出表头 printTableRow(TABLE_WIDTH, head, sizeof(head) / sizeof(head[0]));//将表头信息打入 printTableMidLine(TABLE_WIDTH, 6);//打印表格中线 char r[6][COL_LEN_MAX]; for (int i = start; i <= end; i++) {//将学生信息存入二维数组 sprintf(r[0], "%s", stu[i].idnumber); sprintf(r[1], "%s", stu[i].name); sprintf(r[2], "%s", stu[i].clas); sprintf(r[3], "%d", stu[i].seat); sprintf(r[4], "%d", stu[i].time); sprintf(r[5], "%d", stu[i].money); printTableRow(TABLE_WIDTH, r, 6);//遍历输出 if (i < end) {//判断是否为最后一行,若是最后一行则打印表尾 printTableMidLine(TABLE_WIDTH,6); } else { printTableTail(TABLEWIDTH, 6); } } }
void printstdent() { system("cls"); if (curcount == 0) { printf("还没有录入学生信息\n"); return ; } int pagecount = (curcount + perpage - 1) / perpage;//表格页数 char beff[64]; for (int i = 0; i < pagecount; i++) { showpage(iperpage,(i+1) perpage -1);//打印学生信息 sprintf(beff,"共%d页,第[%d]页", pagecount, i + 1);//打印底部页码信息 printMidInfo(beff); if (i < pagecount - 1) { waitconfirm(); } } } void earse() { system("cls"); int k, flag = 0; //k保存下标,flag用于判断信息是否删除成功 char num2[50]; printf("-----------【删除学生信息】-----------\n"); printf("请输入要删除学生的学号:"); scanf("%s", num2); for (int i = 0; i < curcount; i++) { if (strcmp(stu[i].idnumber,num2)==0) { k = i; flag = 1; break; } } if (flag) { for (int j = k; j < curcount - 1; j++)//要删除学生后面的学生往前移一位 { strcpy(stu[j].idnumber, stu[j + 1].idnumber); strcpy(stu[j].name, stu[j + 1].name); strcpy(stu[j].clas, stu[j + 1].clas); stu[j].seat = stu[j + 1].seat; stu[j].time = stu[j + 1].time; stu[j].money = stu[j + 1].money; } curcount--; printf("删除成功\n"); } else { printf("该学号不存在!!!\n"); } } void modify() { system("cls"); printf("-----------【修改学生信息】-----------\n"); printf("请输入要修改学生的座位号:"); int seat,flag=0; scanf("%d", &seat);//先查找要修改的学生信息 for (int i = 0; i <curcount; i++) { if (stu[i].seat == seat) { flag = 1; printf("查到此学生!\n"); printf("请输入修改后的学号!\n"); scanf("%s", stu[i].idnumber); printf("请输入修改后的姓名!\n"); scanf("%s", stu[i].name); printf("请输入修改后的班级!\n"); scanf("%s", stu[i].clas); search(); printf("请输入修改后的座位号!\n"); scanf("%d", &stu[i].seat); printf("修改信息成功\n"); break; } } if (!flag) { printf("该学号不存在!!!"); } } void search() { system("cls"); printf("请输入您需要查询的学生的学号:"); char number[50]; scanf("%s", number); int i = searchstudent(number); if (i>=0) { char r[6][COL_LEN_MAX]; printTableHead(TABLE_WIDTH, 6);//输出表头 printTableRow(TABLE_WIDTH, head, sizeof(head) / sizeof(head[0]));//将表头信息打入 printTableMidLine(TABLE_WIDTH, 6);//打印表格中线 sprintf(r[0], "%s", stu[i].idnumber); sprintf(r[1], "%s", stu[i].name); sprintf(r[2], "%s", stu[i].clas); sprintf(r[3], "%d", stu[i].seat); sprintf(r[4], "%d", stu[i].time); sprintf(r[5], "%d", stu[i].money); printTableRow(TABLE_WIDTH, r, 6);//遍历输出 printTableTail(TABLE_WIDTH, 6); } else { printf("没有查到该学生的信息"); } } int main(void) { init();//创建窗口 BGM(); MessageBox(NULL, TEXT("欢迎来到机房收费管理系统"), TEXT("提示"), MBOK);//弹出提示窗 int n=520; while (1) { scanf("%d", &n); switch (n) { case 1: add();break;//添加学生信息 case 2: earse(); break;//删除学生信息 case 3: modify(); break;//修改学生信息 case 4: search(); break;//机位信息 case 5: printstdent(); break;//打印学生信息 case 6: search(); break;//查询学生信息 case 0: MessageBox(NULL, TEXT("欢迎您的下次使用,最后这是送您的爱心(请耐心等待一会)"), TEXT("提示"), MB_OK); heart(); exit(0); default: printf("请输入有效数字:\t"); break; } waitconfirm();//等待确认 menu();
}