当前位置:网站首页>手写学生管理系统
手写学生管理系统
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
边栏推荐
- 【微信小程序--解决display:flex最后一行对齐问题。(不连续排列会分到两边)】
- JS (foreach) return cannot end the function solution
- 网安学习-内网安全1
- AUTOSAR从入门到精通100讲(七十八)-AUTOSAR-DEM模块
- MySQL sorts the queried result set according to the specified sequence
- Open source Huizhi creates the future | the openeuler sub forum of 2022 open atom global open source summit was successfully held
- 后置通知的流程分析与功能实现有哪些内容你还记得吗?
- What servers are needed to build mobile app
- Mysql的自连接和联合查询
- How does WPS use smart fill to quickly fill data? WPS method of quickly filling data
猜你喜欢
![[file download] easyexcel quick start](/img/fd/b3b08c67c5a81f0ab58c20653f9398.png)
[file download] easyexcel quick start

Deadlock analysis using jstack, jconsole, and jvisualvm

7.2-function-overloading

The song of the virtual idol was originally generated in this way!

开源汇智创未来 | 2022开放原子全球开源峰会 openEuler 分论坛圆满召开

三层项目的架构分析及构造方法的参数名称注入

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

How does WPS take quick screenshots? WPS quick screenshot method

Google gtest事件机制

学习数据库的第一个程序
随机推荐
Self join and joint query of MySQL
学习数据库的第一个程序
Youxuan database failed to start and reported network error
Google gtest事件机制
6.2 function-parameters
How does WPS use smart fill to quickly fill data? WPS method of quickly filling data
How to add a map to the legendary server
Spark的算子操作列表
ODOO开发教程之图表
Use annotation test in idea
AttributeError: ‘module‘ object has no attribute ‘create_ connection‘
[sudden] solve remote: support for password authentication was removed on August 13, 2021. please use a perso
Solution | get the relevant information about the current employees' highest salary in each department |
源码编译pytorch坑
Button for QT custom switch effect
Introduction of JDBC preparestatement+ database connection pool
MySQL sorts the queried result set according to the specified sequence
Diagram of odoo development tutorial
[file download] easyexcel quick start
Mysql把查询到的结果集按指定顺寻进行排序