C语言项目(一):学生信息管理系统
实现方式:链表
结构定义
1 typedef struct MyStu MyStudent;
2 typedef struct node Node;
3 typedef Node *pNode;
4
5 struct MyStu {
6 char name [20];
7 int age;
8 long ID;
9 double score;
10 };
11
12 struct node {
13 MyStudent student;
14 pNode next;
15 };
16
17 static pNode head = NULL;
基本功能
1 void InputStudentInformation();
2
3 void PrintStudentInformation();
4
5 void SaveStudentInformation();
6
7 void ReadStudentInformation();
8
9 int CountStudentNumber();
10
11 pNode FindStudent();
12
13 pNode FinePrevious(pNode Cur);
14
15 void ModifyStudentInformation();
16
17 void DeleteStudentInformation();
18
19 void Menu();
20
21 void KeyDown();
22
23 void SubMenu();
界面
 1 void Menu() {
 2     printf("********************************************************\n");
 3     printf("==============欢迎使用高校学生成绩管理系统==============\n");
 4     printf("\t=============请选择功能列表==============\n");
 5     printf("\t**************1.录入学生信息**************\n");
 6     printf("\t**************2.输出学生信息**************\n");
 7     printf("\t**************3.统计学生人数**************\n");
 8     printf("\t**************4.查找学生信息**************\n");
 9     printf("\t**************5.修改学生信息**************\n");
10     printf("\t**************6.删除学生信息**************\n");
11     printf("\t**************0.退 出 系 统**************\n");
12     printf("********************************************************\n");
13 }
菜单实现
 1 void KeyDown() {
 2     int choice;
 3     printf("Function to chose (0~6):\n");
 4     scanf("%d", &choice);
 5     switch (choice) {
 6         case 1:
 7             InputStudentInformation();
 8             SaveStudentInformation();
 9             break;
10         case 2:
11             PrintStudentInformation();
12             break;
13         case 3:
14             printf("Total students is %d\n", CountStudentNumber());
15             break;
16         case 4:
17         {
18             pNode Find = FindStudent();
19             if (Find != NULL) {
20                 printf("NUM:%ld\tNAME:%s\tAGE:%d\tSCORE:%lf",
21                        Find->student.ID,
22                        Find->student.name,
23                        Find->student.age,
24                        Find->student.score);
25             }
26             break;
27         }
28         case 5:
29             ModifyStudentInformation();
30             SaveStudentInformation();
31             break;
32         case 6:
33             DeleteStudentInformation();
34             SaveStudentInformation();
35             break;
36         case 0:
37             printf("Welcome to use again!");
38             exit(0);
39         default:
40             printf("Invalid Input!");
41             break;
42     }
43 }
子菜单
 1 void SubMenu() {
 2     printf("********************************************************\n");
 3     printf("==============欢迎使用高校学生成绩管理系统==============\n");
 4     printf("\t=============请选择功能列表==============\n");
 5     printf("\t**************a.修改姓名**************\n");
 6     printf("\t**************b.修改学号**************\n");
 7     printf("\t**************c.修改年龄**************\n");
 8     printf("\t**************d.修改成绩**************\n");
 9     printf("\t**************q.退出系统**************\n");
10     printf("********************************************************\n");
11 }
打印功能
 1 void PrintStudentInformation() {
 2     system("cls");
 3     printf("********************************************************\n");
 4     printf("==============欢迎使用高校学生成绩管理系统==============\n");
 5     printf("********************************************************\n");
 6     pNode tmp = head->next;
 7     while (tmp != NULL) {
 8         printf("NUM:%ld\tNAME:%s\tAGE:%d\tSCORE:%lf\n",
 9                tmp->student.ID,
10                tmp->student.name,
11                tmp->student.age,
12                tmp->student.score);
13         tmp = tmp->next;
14
15     }
16 }
保存功能
 1 void SaveStudentInformation() {
 2     FILE *fp = fopen(PATH, "w+");
 3     if (!fp) {
 4         printf("FAIL");
 5         exit(0);
 6     }
 7     pNode tmp;
 8     tmp = head->next;
 9     while (tmp != NULL) {
10         fwrite(&tmp->student, sizeof(Node), 1, fp);
11         tmp = tmp->next;
12     }
13     fclose(fp);
14     printf("SAVE DONE!");
15 }
读取功能
 1 void ReadStudentInformation() {
 2     FILE *read = fopen(PATH, "r");
 3     if (!read) {
 4         printf("FAIL");
 5         exit(0);
 6     }
 7     MyStudent stu;
 8     while (fread(&stu, sizeof(MyStudent), 1, read)) {
 9         pNode tmp = (pNode)malloc(sizeof(Node));
10         memcpy(tmp, &stu, sizeof(MyStudent));
11         if (head->next == NULL) {
12             head->next = tmp;
13             tmp->next = NULL;
14         }
15         else {
16             pNode tmp_ = head->next;
17             head->next = tmp;
18             tmp->next = tmp_;
19         }
20     }
21     fclose(read);
22     printf("LOAD DONE!");
23 }
计数功能
 1 int CountStudentNumber() {
 2     int cnt = 0;
 3     pNode tmp;
 4     tmp = head->next;
 5     while (tmp != NULL) {
 6         cnt++;
 7         tmp = tmp->next;
 8     }
 9     return cnt;
10 }
增删改查
  1 void InputStudentInformation() {
  2     pNode NewNode = (pNode)malloc(sizeof(Node));
  3     if (head==NULL) {
  4         head = (pNode)malloc(sizeof(Node));
  5         head->next = NewNode;
  6         NewNode->next = NULL;
  7     }
  8     else {
  9         pNode tmp = head->next;
 10         head->next = NewNode;
 11         NewNode->next = tmp;
 12     }
 13     printf("Name:\n");
 14     scanf("%s", NewNode->student.name);
 15     printf("NUM:\n");
 16     scanf("%ld", &NewNode->student.ID);
 17     printf("AGE:\n");
 18     scanf("%d", &NewNode->student.age);
 19     printf("SCORE:\n");
 20     scanf("%lf", &NewNode->student.score);
 21     printf("DONE");
 22 }
 23 pNode FindStudent() {
 24     printf("Enter student ID:\n");
 25     long id_f;
 26     scanf("%ld", &id_f);
 27     pNode tmp;
 28     tmp = head->next;
 29     while (tmp != NULL) {
 30         if (tmp->student.ID == id_f) {
 31             return tmp;
 32         }
 33         tmp = tmp->next;
 34     }
 35     printf("ERROR ID! \n");
 36     return NULL;
 37 }
 38 pNode FinePrevious(pNode Cur) {
 39     pNode tmp;
 40     tmp = head;
 41     while (tmp != NULL) {
 42         if (tmp->next == Cur) {
 43             return tmp;
 44         }
 45         tmp = tmp->next;
 46     }
 47     return NULL;
 48 }
 49 void ModifyStudentInformation() {
 50     pNode Find = FindStudent();
 51     if (Find == NULL) {
 52         printf("ID ERROR!");
 53         return;
 54     }
 55     SubMenu();
 56     char ch;
 57     scanf("%c", &ch);
 58     switch (ch) {
 59         case 'a':
 60             printf("Enter new name:\n");
 61             scanf("%s", Find->student.name);
 62             printf("MODIFY DONE!\n");
 63             break;
 64         case 'b':
 65             printf("Enter new ID:\n");
 66             scanf("%ld", &Find->student.ID);
 67             printf("MODIFY DONE!\n");
 68             break;
 69         case 'c':
 70             printf("Enter new age:\n");
 71             scanf("%d", &Find->student.age);
 72             printf("MODIFY DONE!\n");
 73             break;
 74         case 'd':
 75             printf("Enter new score:\n");
 76             scanf("%lf", &Find->student.score);
 77             printf("MODIFY DONE!\n");
 78             break;
 79         case 'q':
 80             printf("Welcome to using this system again!");
 81             break;
 82         default:
 83             printf("Invalid Input");
 84             break;
 85     }
 86 }
 87 void DeleteStudentInformation() {
 88     pNode Cur = FindStudent();
 89     if (Cur == NULL) {
 90         return;
 91     }
 92     pNode Prev = FinePrevious(Cur);
 93     if (Cur->next == NULL) {
 94         Prev->next = NULL;
 95         free(Cur);
 96     }
 97     else {
 98         pNode tmp = Cur->next;
 99         Cur->next = NULL;
100         Prev->next = tmp;
101         free(Cur);
102     }
103
104 }
C语言项目(一):学生信息管理系统的更多相关文章
- C语言项目:学生成绩管理系统
		
C语言项目:学生成绩管理系统 1.数据结构:学生信息:学号.姓名.年龄.性别.3课成绩 2.功能: (1)增加学生记录 (2) 删除学生记录 (3) 查找学生信息(学号 ...
 - 数据结构(c语言)之学生信息管理系统
		
程序思维导图 代码表示(代码参考:长春大学-牛言涛老师) 如有错误请指出欢迎交流 #include<stdio.h> #include<malloc.h>//动态存储分配函数头 ...
 - C语言大作业---学生信息管理系统
		
xxxx信息管理系统 简介 因为大作业规定的踩分项就那么多,为了不浪费时间 + 得分,就写成这样.现在看看,命名不规范,书写风格糟糕,全塞在一个源代码中······ 不过,应付大作业是没问题的 实验报 ...
 - Node.js小项目——学生信息管理系统
		
这是迄今为止第一次接触后端的东西,是一个很小的项目,但是对于前端学习入门很好.我是先学了VUE框架再学的Node,学起来比较轻松,不过每个人都有自己的学习方法️ 一.项目描述 学生信息管理系统,可以实 ...
 - C语言小练习之学生信息管理系统
		
C语言小练习之学生信息管理系统 main.c文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2 ...
 - C语言练习-学生信息管理系统
		
题目要求: 学生信息管理系统struct studentInfo{ int id; char name[128]; int age; char sex; int c_score; int cpp_sc ...
 - 【转载】C语言综合实验1—学生信息管理系统
		
http://www.cnblogs.com/Anker/archive/2013/05/06/3063436.html 实验题目:学生信息管理系统 实验要求:用户可以选择1-7可以分别进行学生信息的 ...
 - [项目分享]JSP+Servlet+JDBC实现的学生信息管理系统
		
本文存在视频版本,请知悉 项目简介 项目来源于:https://gitee.com/liu_xu111/JavaWeb01 这次分享一个学生管理系统,我感觉这是程序员在大学时期的毕设和课程设计选择最多 ...
 - 大一C语言结课设计之《学生信息管理系统》
		
第一次写这么长的程序,代码仅供參考,有问题请留言. /* ** 学生信息管理系统 ** IDE:Dev-Cpp 4.9.9.2 ** 2014-6-15 */ #include <stdio.h ...
 
随机推荐
- U138097 小鱼吃大鱼  埃氏筛
			
题目描述 小P同学在养殖一种非常凶狠的鱼,而且与其他鱼类不同,这种鱼越大越温顺,反而小鱼最凶残.当两条鱼相遇时, 小鱼会不断撕咬大鱼,每一口都咬下与它自身等重的肉(小鱼保持体重不变),直到大鱼的体重小 ...
 - 多快好省地使用pandas分析大型数据集
			
1 简介 pandas虽然是个非常流行的数据分析利器,但很多朋友在使用pandas处理较大规模的数据集的时候经常会反映pandas运算"慢",且内存开销"大". ...
 - LoRaWAN和LoRa的区别在那里?
			
有很多人都分不清楚LoRaWAN和LoRa到底有什么区别,甚至有人认为它们是一样的,但其实这两个不一样的. LoRa是一个物理层的协议,而LoRaWAN则指的是MAC层的组网协议.虽然现有的LoRaW ...
 - python爬虫使用scrapy框架
			
scrapy框架提升篇 关注公众号"轻松学编程"了解更多 1.创建启动爬虫脚本 在项目目录下创建start.py文件: 添加代码: #以后只要运行start.py就可以启动爬虫 i ...
 - 【Flutter 实战】pubspec.yaml 配置文件详解
			
老孟导读:pubspec.yaml 文件是 Flutter 中非常重要的配置文件,下面就让我们看看里面各个配置的含义. pubspec.yaml 是 Flutter 项目的配置文件,类似于 Andro ...
 - 849. Maximize Distance to Closest Person ——weekly contest 87
			
849. Maximize Distance to Closest Person 题目链接:https://leetcode.com/problems/maximize-distance-to-clo ...
 - Java_静态代理与Lambda
			
静态代理 要点: 公共接口 真实角色 代理角色 public class StaticProxy { public static void main(String[] args) { You you ...
 - 鸿蒙开发板外设控制 之 实现物理按键的“长按事件”(按键通用框架 V0.0.2)
			
我在之前的帖子<实现按键"按下事件"和"释放事件"的通用框架(V0.0.1)>中阐述了DTButton-V0.0.1的设计思路,并且也在帖子中开源了 ...
 - windows鼠标右键文件太多
			
1.网上找的(已经验证太难找,并没有多大用) 单击Windows的"开始"菜单,单击"运行",在"打开"框中键入"regedit& ...
 - http 怎样关闭
			
如何优雅的关闭关闭这个fd , 如果只是一个简单的fd 直接调用close 就行, 但是如果要是一个框架 那就接到 资源回收复用 内存泄漏等问题: 来看看 ngx 是用怎样的思路处理 事务结束动作: ...