当前位置:网站首页>手写学生管理系统
手写学生管理系统
2022-07-29 05:07:00 【cpp编程】

#include <stdio.h> #include <stdlib.h> int main(void) { printf("hello world\n"); system("pause"); return 0; }4. 编写功能菜单 初级版 int main(void) { printf(" 学生信息管理系统\n"); printf("1. 输入学生信息\n"); printf("3. 删除学生信息\n"); printf("3. 删除学生信息\n"); printf("4. 修改学生信息\n"); printf("5. 插入学生信息\n"); printf("6. 学生成绩排名\n"); printf("7. 统计学生总数\n"); printf("8. 显示所有信息\n"); printf("0. 退出系统\n"); system("pause"); return 0; }
导入第 3 行工具,初始化窗口大小
void init() { char cmd[128]; sprintf(cmd, "mode con lines=%d cols=%d", WIN_HEIGHT, WIN_WIDTH); system(cmd); }int main(void) { init(); ...... return 0; }创建菜单函数 menu
void menu() { system("cls"); printTableHead(MENU_WIDTH); printTableMidInfo(MENU_WIDTH, "学生信息管理系统"); printTableMidInfo(MENU_WIDTH, ""); const char* subMenus[] = { "1. 输入学生信息", "2. 查找学生信息", "3. 删除学生信息", "4. 修改学生信息", "5. 插入学生信息", "6. 学生成绩排名", "7. 统计学生总数", "8. 显示所有信息", "0. 退出系统 " };int count = sizeof(subMenus) / sizeof(subMenus[0]); for (int i = 0; i < count; i++) { printTableMidInfo(MENU_WIDTH, subMenus[i]); }printTableMidInfo(MENU_WIDTH, ""); printTableTail(MENU_WIDTH); printMidInfo("请选择(0-8): "); }调用 menu 函数
int main(void) { init(); menu(); return 0; }
void init() { char cmd[128]; sprintf(cmd, "mode con lines=%d cols=%d", WIN_HEIGHT, WIN_WIDTH); system(cmd); system("color 1f"); //system("color f0\n"); }5. 菜单选择
int main(void) { init(); menu(); int n; scanf("%d", &n); while (1) { switch (n) { case 1: input();break;
case 2: search();break; case 3: del(); break; case 4: modify(); break; case 5: insert(); break; case 6: order(); break; case 7: total(); break; case 8: show(); break; default:break; }waitConfirm(); menu(); rewind(stdin); // fflush(stdin),在 VS2015 以上无效 scanf("%d", &n); }return 0; }void input() { system("cls"); printf("输入...\n"); }void search() { system("cls"); printf("查询...\n"); }void del() { system("cls"); printf("删除...\n"); }void modify() { system("cls"); printf("修改...\n"); }void insert() { system("cls");
printf("插入...\n"); }void order() { system("cls"); printf("排序...\n"); }void total() { system("cls"); printf("统计...\n"); }void show() { system("cls"); printf("显示...\n"); }void waitConfirm() { rewind(stdin); //flush(stdin)在 VS2015 以上无效,使用 rewind,清空缓存 getch(); }struct student { int num; //学号 char name[16]; int cLang; //C 语言 int algo; //算法 int database; //数据库 int sum; };#define MAX_COUNT 100
struct student stu[MAX_COUNT]; int currentCount = 0;void init() { char cmd[128]; sprintf(cmd, "mode con lines=%d cols=%d", WIN_HEIGHT, WIN_WIDTH); system(cmd); system("color 1f"); //system("color f0\n"); memset(stu, 0, sizeof(stu)); FILE* fp = fopen("data.txt", "rb"); if (fp == NULL) { //printf("文件不存在!\n"); currentCount = 0; return; }int i = 0; while (!feof(fp)) { int ret = fread(&stu[i], sizeof(struct student), 1, fp); if (ret == 1) { i++; } }currentCount = i; }void input() { char str[16]; struct student s; while (1) { system("cls"); printf("输入学生信息(y/n):"); rewind(stdin); //清空输入缓存区 scanf("%s", str); if (strcmp(str, "Y") != 0 && strcmp(str, "y") != 0) { break; }s = inputInfo(); if (searchStu(s.num) >= 0) { printf("学号[%d] 已经存在!\n", s.num); waitConfirm(); continue; }stu[currentCount++] = s; if (!save()) { printf("保存失败!\n"); }else {printf("保存成功!\n"); }waitConfirm(); }printf("\n 结束输入!\n"); }struct student inputInfo() { //可优化成使用指针参数 struct student s; rewind(stdin); //清空输入缓存区 printf("学号:"); scanf("%d", &s.num);
printf("姓名:"); scanf("%s", s.name); printf("C 语言:"); scanf("%d", &s.cLang); printf("算法:"); scanf("%d", &s.algo); printf("数据库:"); scanf("%d", &s.database); s.sum = s.cLang + s.algo + s.database; return s; }int searchStu(int snum) { for (int i = 0; i < currentCount; i++) { if (stu[i].num == snum) { return i; } }return -1; }bool save() { FILE *fp = fopen("data.txt", "wb"); if (fp == NULL) { fclose(fp); return false; }for (int i = 0; i < currentCount; i++) { if (fwrite(&stu[i], sizeof(struct student), 1, fp) != 1) { fclose(fp); return false; } }fclose(fp); return true; }#define RECORDER_PER_PAGE 10 void show() { system("cls"); if (currentCount == 0) { printf("还没有学生信息!\n"); return; }int pageCount = (currentCount + RECORDER_PER_PAGE - 1) / RECORDER_PER_PAGE; char buff[64]; for (int i = 0; i < pageCount; i++) { showPage(i * RECORDER_PER_PAGE, (i + 1) * RECORDER_PER_PAGE - 1); sprintf(buff, "共%d 页 第[%d]页", pageCount, i + 1); printMidInfo(buff); if (i < pageCount - 1) { waitConfirm(); } } }// 表头信息 char head[][COL_LEN_MAX] = { "学号", "姓名", "C 语言", "算法", "数据库", "总分" }; void showPage(int startIndex, int endIndex) { if (endIndex >= currentCount) { endIndex = currentCount - 1; }if (endIndex - startIndex + 1 > RECORDER_PER_PAGE) { endIndex = startIndex + RECORDER_PER_PAGE - 1; }char row[6][COL_LEN_MAX]; system("cls"); printTableHead(TABLE_WIDTH, 6);
printTableRow(TABLE_WIDTH, head, sizeof(head) / sizeof(head[0])); printTableMidLine(TABLE_WIDTH, 6); for (int i = startIndex; i <= endIndex; i++) { sprintf(row[0], "%d", stu[i].num); sprintf(row[1], "%s", stu[i].name); sprintf(row[2], "%d", stu[i].cLang); sprintf(row[3], "%d", stu[i].algo); sprintf(row[4], "%d", stu[i].database); sprintf(row[5], "%d", stu[i].sum); printTableRow(TABLE_WIDTH, row, 6); if (i < endIndex) { printTableMidLine(TABLE_WIDTH, 6); }else {printTableTail(TABLE_WIDTH, 6); } } }void search() { int snum = 0; system("cls"); printf("请输入学号:"); scanf("%d", &snum); int i = searchStu(snum); if (i < 0) { printf("没有找到这名学生!\n"); return; }char row[6][COL_LEN_MAX]; char head[][COL_LEN_MAX] = { "学号", "姓名", "C 语言", "算法", "数据库", "总分" }; printTableHead(TABLE_WIDTH, 6); printTableRow(TABLE_WIDTH, head, sizeof(head) / sizeof(head[0]));
printTableMidLine(TABLE_WIDTH, 6); sprintf(row[0], "%d", stu[i].num); sprintf(row[1], "%s", stu[i].name); sprintf(row[2], "%d", stu[i].cLang); sprintf(row[3], "%d", stu[i].algo); sprintf(row[4], "%d", stu[i].database); sprintf(row[5], "%d", stu[i].sum); printTableRow(TABLE_WIDTH, row, 6); printTableTail(TABLE_WIDTH, 6); }void del() { FILE* fp; int snum = 0; char str[16] = ""; system("cls"); printf("请输入学号:"); scanf("%d", &snum); int i = searchStu(snum); if (i<0) { printf("没有找到这名学生!\n"); return; }printf("找到这条记录,是否删除?(y/n)"); scanf("%s", str); if (strcmp(str, "Y") == 0 || strcmp(str, "y") == 0) { for (int j = i; j < currentCount; j++) { stu[j] = stu[j + 1]; }currentCount--; if (save()) { printf("删除成功!\n"); }
else {printf("保存文件失败!\n"); } }else {printf("取消删除!\n"); } }void modify() { int snum; system("cls"); printf("请输入要修改的学生的学号: "); scanf("%d", &snum); int i = searchStu(snum); if (i < 0) { printf("没有找到这名学生!\n"); return; }printf("找到了这名学生, 可以修改他的信息!\n"); printf("姓名:"); scanf("%s", stu[i].name); printf("C 语言:"); scanf("%d", &stu[i].cLang); printf("算法:"); scanf("%d", &stu[i].algo); printf("数据库:"); scanf("%d", &stu[i].database); stu[i].sum = stu[i].cLang + stu[i].algo + stu[i].database; if (save()) { printf("修改成功!\n"); }else {printf("保存文件失败!\n"); } }int snum; system("cls"); printf("请输入要插入的位置(学号):"); scanf("%d", &snum); int destIndex = searchStu(snum); if (destIndex < 0) { printf("没有这名学生,插入位置错误!\n"); return; }struct student t = inputInfo(); int i = searchStu(t.num); if (i >= 0) { printf("学号[%d]已经存在! \n", t.num); return; }for (int j = currentCount-1; j > destIndex; j--) { stu[j + 1] = stu[j]; }stu[destIndex + 1] = t; currentCount++; if (save()) { printf("插入成功!\n"); } else { printf("保存文件失败!\n"); }void order() {
if (currentCount == 0) { printf("还没有学生记录!\n"); return; }for (int i = 0; i < currentCount - 1; i++) { for (int j = i + 1; j < currentCount; j++) { if (stu[i].sum < stu[j].sum) { struct student t = stu[i]; stu[i] = stu[j]; stu[j] = t; } } }if (!save()) { printf("排序后,保存文件失败!\n"); }else {show(); } }今天的分享就到这里了,大家要好好学C语言/C++哟~
欢迎转行和学习编程的伙伴,利用更多的资料学习成长比自己琢磨更快哦!
对于准备学习C/C++编程的小伙伴,如果你想更好的提升你的编程核心能力(内功)不妨从现在开始!
整理分享(多年学习的源码、项目实战视频、项目笔记,基础入门教程)加君羊获取哦~
C语言C++编程学习交流圈子,企鹅君羊:763855696
边栏推荐
- How to make the characters in the photos laugh? HMS core video editing service one click smile function makes people smile more naturally
- How to add a map to the legendary server
- [untitled]
- 使用Jstack、Jconsole和jvisualvm进行死锁分析
- How to add traffic statistics codes to the legendary Development Zone website
- Mysql的自连接和联合查询
- ARFoundation从零开始5-AR图像跟踪
- Functions in MySQL statements
- 关于servlet中实现网站的页面跳转
- Do you remember the process analysis and function implementation of post notification?
猜你喜欢

How to add a map to the legendary server

传奇开区网站如何添加流量统计代码

Use annotation test in idea

ARFoundation入门教程7-url动态加载图像跟踪库

Activity workflow table structure learning

后置通知的流程分析与功能实现有哪些内容你还记得吗?
![[wechat applet -- solve the alignment problem of the last line of display:flex. (discontinuous arrangement will be divided into two sides)]](/img/ee/b424d876c64dac652d76f9f26e4b20.png)
[wechat applet -- solve the alignment problem of the last line of display:flex. (discontinuous arrangement will be divided into two sides)]

深度学习刷SOTA的一堆trick

Solve the warning prompt of MySQL mapping file

ARFoundation从零开始9-AR锚点(AR Anchor)
随机推荐
How to add a map to the legendary server
How to make the characters in the photos laugh? HMS core video editing service one click smile function makes people smile more naturally
Functions in MySQL statements
深度学习刷SOTA的一堆trick
开源汇智创未来 | 2022开放原子全球开源峰会 openEuler 分论坛圆满召开
[untitled]
学习数据库的第一个程序
TCP three handshakes and four waves
Huawei ilearning AI mathematics foundation course notes
SM integration is as simple as before, and the steps are clear (detailed)
自定义Qml控件:ImageButton
Qml类型:MouseArea
Solve the warning prompt of MySQL mapping file
The person who goes to and from work on time and never wants to work overtime has been promoted in front of me
传奇服务端如何添加地图
Numpy Foundation
源码编译pytorch坑
ThreadPoolExecutor simple to use
【微信小程序--解决display:flex最后一行对齐问题。(不连续排列会分到两边)】
JS daily question (11)