实现方式:链表

结构定义

 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语言项目(一):学生信息管理系统的更多相关文章

  1. C语言项目:学生成绩管理系统

    C语言项目:学生成绩管理系统    1.数据结构:学生信息:学号.姓名.年龄.性别.3课成绩    2.功能:   (1)增加学生记录    (2)  删除学生记录    (3)  查找学生信息(学号 ...

  2. 数据结构(c语言)之学生信息管理系统

    程序思维导图 代码表示(代码参考:长春大学-牛言涛老师) 如有错误请指出欢迎交流 #include<stdio.h> #include<malloc.h>//动态存储分配函数头 ...

  3. C语言大作业---学生信息管理系统

    xxxx信息管理系统 简介 因为大作业规定的踩分项就那么多,为了不浪费时间 + 得分,就写成这样.现在看看,命名不规范,书写风格糟糕,全塞在一个源代码中······ 不过,应付大作业是没问题的 实验报 ...

  4. Node.js小项目——学生信息管理系统

    这是迄今为止第一次接触后端的东西,是一个很小的项目,但是对于前端学习入门很好.我是先学了VUE框架再学的Node,学起来比较轻松,不过每个人都有自己的学习方法️ 一.项目描述 学生信息管理系统,可以实 ...

  5. 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 ...

  6. C语言练习-学生信息管理系统

    题目要求: 学生信息管理系统struct studentInfo{ int id; char name[128]; int age; char sex; int c_score; int cpp_sc ...

  7. 【转载】C语言综合实验1—学生信息管理系统

    http://www.cnblogs.com/Anker/archive/2013/05/06/3063436.html 实验题目:学生信息管理系统 实验要求:用户可以选择1-7可以分别进行学生信息的 ...

  8. [项目分享]JSP+Servlet+JDBC实现的学生信息管理系统

    本文存在视频版本,请知悉 项目简介 项目来源于:https://gitee.com/liu_xu111/JavaWeb01 这次分享一个学生管理系统,我感觉这是程序员在大学时期的毕设和课程设计选择最多 ...

  9. 大一C语言结课设计之《学生信息管理系统》

    第一次写这么长的程序,代码仅供參考,有问题请留言. /* ** 学生信息管理系统 ** IDE:Dev-Cpp 4.9.9.2 ** 2014-6-15 */ #include <stdio.h ...

随机推荐

  1. Reading Face, Read Health论文阅读笔记

    摘要: 随着计算技术觉.人工智能和移动技术的发展,利用计算机读脸技术去识别每个人每天的健康是可行的.怎么去设计一个基于FRT(face reading technologies)的用于得到每天的保健实 ...

  2. STM32入门系列-介绍STM32型号与功用

    作为STM32初学者,一般会选择购置一块开发板,因为在开发板上有很多已经集成好的模块,如红外模块.按键模块.LED模块.DAC模块.ADC模块.can模块.485模块.以太网模块.WiFi模块.蜂鸣器 ...

  3. 面试时说Redis是单线程的,被喷惨了!

    Redis是单线程的,这话搁以前,是横着走的,谁都知道的真理.现在不一样,Redis 变了.再说这句话,多少得有质疑的语气来跟你辩驳一番.意志不坚定的,可能就缴械投降,顺着别人走了. 到底是什么样的, ...

  4. 使用MQTT协议的4G DTU模块具有什么优势

    什么是MQTT协议 要了解使用MQTT协议的4G DTU模块具有哪些优势,首先我们需要了解什么是MQTT协议,MQTT协议最早是IBM开发的一个即时通讯协议,它的主要是为大量计算能力有限且工作在低带宽 ...

  5. APIview的使用

    大牛博客: h'ttp://www.cnblogs.com/xiaonq/p/10124104.html 1.ModelViewSet 是对 APIView 封装 2.ModelSerializer ...

  6. 《Clojure编程》笔记 第16章 Clojure与web

    目录 背景简述 第16章 Clojure与web 16.1 术语 16.2 Clojure栈 16.3 基石:Ring 16.3.1 请求与应答 16.3.2 适配函数 16.3.3 处理函数 16. ...

  7. thinkphp之无限分类

    namespace Home\Controller; use Home\Controller; class CategoryController extends Controller { //无限分类 ...

  8. 把数据转化为JSON格式用ajax进行前后端交互

    接着在https://www.cnblogs.com/dong973711/p/10907733.html的基础上做验证. 从前端提交数据 前端页面,submit.html <!DOCTYPE ...

  9. C++ 基础 5:多态

    1 什么是多态 多态按字面的意思就是多种形态.当类之间存在层次结构,并且类之间是通过继承关联时,就会用到多态. C++ 多态意味着由继承而产生的相关的不同的类,调用重写函数时,会根据实际的对象类型来执 ...

  10. cmd,py脚本,py编译的exe,uipath及uibot对它们的调用

    UIPATH调用Python编译程序exe 好处: 1)code不以可编辑的状态被用户接触,对于不懂反编译的一般用户,可提升一定的代码安全性: 2)不需要用户机器上安装 python环境. 3)可以将 ...