# 实现效果
利用单链表实现,具体功能:
1. 录入学生信息
2. 打印学生信息
3. 统计人数
4. 查找学生信息
5. 修改学生信息
6. 删除学生信息
7. 按成绩排序
# 实现过程
1. 头文件建立:名字与源文件一样,引入stdlib.h stdio.h的文件,再在源文件上引入其头文件。
2. 封装学生和结点数据:
定义学生结构体,用于保存学生信息,并用typedef给struct_student类型起别名为student,方便使用。
定义结构体,用于保存链表中的结点数据,结点需要保存学生信息及下一个结点的地址,并使用typedef给struct_node类型起名为Node,方便使用。
3. 创建头结点
4. 系统功能提示
5. 根据用户输入选择功能
6. 录入学生信息
7. 实现循环录入
8. 程序暂停和清空控制台
9. 打印学生信息
10. 统计学生信息
11. 查找学生信息
12. 学生信息持久化
13. 修改学生信息
14. 删除学生信息
15. 按成绩排序
16. 退出系统
主要过程看代码:
源文件:
#define _CRT_SECURE_NO_WARNINGS
#include"xitong.h"
void welcome() {
printf("********************************\n");
printf("*\t学生成绩管理系统\t*\n");
printf("********************************\n");
printf("*\t请选择功能列表\t\t*\n");
printf("********************************\n");
printf("*\t1.录入学生信息\t\t*\n");
printf("*\t2.打印学生信息\t\t*\n");
printf("*\t3.统计学生人数\t\t*\n");
printf("*\t4.查找学生信息\t\t*\n");
printf("*\t5.修改学生信息\t\t*\n");
printf("*\t6.删除学生信息\t\t*\n");
printf("*\t7.按成绩排序\t\t*\n");
printf("*\t8.退出系统\t\t*\n");
printf("********************************\n");
}
void inputStudent(Node* head) {
Node* fresh = malloc(sizeof(Node));
fresh->next = NULL;
printf("请输入学生的学号,姓名,成绩:");
scanf("%d%s%d", &fresh->student.stuNum, fresh->student.name, &fresh->student.score);
Node* move = head;
while (move->next != NULL) {
move = move->next;
}
move->next = fresh;
saveStudent(head);
system("pause");
system("cls");
}
void printStudent(Node* head)
{
Node* move = head->next;
while (move != NULL) {
printf("学号:%d 姓名:%s 成绩:%d\n",move->student.stuNum, move->student.name, move->student.score);
move = move->next;
}
system("pause");
system("cls");
}
void countStudent(Node* head)
{
int count = 0;
Node* move = head->next;
while (move != NULL) {
count++;
move = move->next;
}
printf("学生的总人数为:%d\n", count);
system("pause");
system("cls");
}
void findStudent(Node* head)
{
printf("请输入要查找的学生的学号:");
int stuNum;
scanf("%d", &stuNum);
Node* move = head->next;
while (move != NULL)
{
if (stuNum == move->student.stuNum)
{
printf("学号:%d 姓名:%s 成绩:%d\n", move->student.stuNum, move->student.name, move->student.score);
system("pause");
system("cls");
return;
}
move = move->next;
}
printf("未找到学生信息\n");
system("pause");
system("cls");
}
void saveStudent(Node* head) {
FILE* file = fopen("./stu.info", "w");;
Node* move = head->next;
while (move != NULL)
{
if (fwrite(&move->student, sizeof(Student), 1, file) != 1)
{
printf("写入失败\n");
return;
}
move = move->next;
}
fclose(file);
}
void loadStudent(Node* head) {
FILE* file = fopen("./stu.info", "r");
if (!file) {
printf("未找到学生信息,跳过读取\n");
return;
}
Node* fresh = malloc(sizeof(Node));
fresh->next = NULL;
Node* move = head;
while (fread(&fresh->student, sizeof(Student), 1, file) == 1) {
move->next = fresh;
move = fresh;
fresh = malloc(sizeof(Student));
fresh->next = NULL;
}
free(fresh);
fclose(file);
printf("读取成功\n");
}
void modifyStudent(Node* head)
{
printf("请输入要修改的学生的学号:");
int stuNum;
scanf("%d", &stuNum);
Node* move = head->next;
while (move != NULL)
{
if (move->student.stuNum == stuNum) {
printf("请输入学生姓名,成绩\n");
scanf("%s%d", move->student.name, &move->student.score);
saveStudent(head);
printf("修改成功\n");
system("pause");
system("cls");
return;
}
move = move->next;
}
printf("未找到学生信息\n");
system("pause");
system("cls");
}
void deleteStudent(Node* head)
{
printf ("请输入要删除的学生学号:");
int stuNum = 0;
scanf("%d", &stuNum);
Node* move = head;
while (move->next != NULL)
{
if (move->next->student.stuNum == stuNum)
{
Node* tmp = move->next;
move->next = move->next->next;
free(tmp); tmp = NULL;
saveStudent(head);
printf("删除成功\n");
system("pause");
system("cls");
return;
}
move = move->next;
}
printf("未找到学生信息\n");
system("pause");
system("cls");
}
void sortStudent(Node* head)
{
Node* save = NULL;
Node* move = NULL;
for (Node* turn = head->next; turn->next != NULL; turn = turn->next)
{
for (Node* move = head->next; move->next != NULL; move = move->next)
{
if (move->student.score > move->next->student.score)
{
Student temp = move->student;
move->student = move->next->student;
move->next->student = temp;
}
}save = move;
}
printStudent(head);
}
int main() {
Node* head = malloc(sizeof(Node));//创建头结点
head->next = NULL;
loadStudent(head);
while (1)
{
welcome();
char c = _getch();
switch (c)
{
case'1':
inputStudent(head);
break;
case'2':
printStudent(head);
break;
case'3':
countStudent(head);
break;
case'4':
findStudent(head);
break;
case'5':
modifyStudent(head);
break;
case'6':
deleteStudent(head);
break;
case'7':
sortStudent(head);
break;
case'8':
system("cls");
printf("bye bye!\n");
exit(0);
break;
default:
printf("请重新输入\n");
break;
}
}
return 0;
}
头文件:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
typedef struct _Student
{
int stuNum;
char name[20];
int score;
}Student;
typedef struct _Node
{
Student student;
struct _Node* next;
}Node;
void welcome();
void inputStudent(Node* head);
void printStudent(Node* head);
void countStudent(Node* head);
void findStudent(Node* head);
void saveStudent(Node* head);
void loadStudent(Node* head);
void modifyStudent(Node* head);
void deleteStudent(Node* head);
void sortStudent(Node* head);
结果:
前端知识补充:
实体字符,HTML Entity
实体字符通常用于在页面中显示一些特殊符号。
1. &单词;
2. &#数字;
- 小于符号
<<<(三种都可以)
- 大于符号
>
- 空格符号
- 版权符号
©
- &符号
&
- &版权
©
# 换行标签
<br/> 可以使段落文字强制换行,是单词break的缩写,意为打断,换行。
加粗:
<strong></strong>或者<b></b>,<strong></strong>语义更强烈
倾斜:
<em></em>或者<i></i>,<em>语义更强烈
删除线:
<del></del>或者<s></s>,<del>语义更强烈
下划线:
<ins></ins>或者<u></u>,<ins>语义更强烈
对站外资源:绝对路径(唯一)(复制地址粘贴即可)
站内资源:相对路径(也可以使用绝对路径)
绝对路径的书写格式:
url地址:
```
协议名://主机名:端口号/path(路径)
schema://host:port/path
```
协议名:http,https,file
https://www.baidu.com:443/index.htm
主机名:域名,IP地址
端口号:如果协议是http协议则默认端口是80;如果是https协议则默认端口是443
当跳转目标和当前页面协议相同时,可以省略协议
2. 相对路径
以./开头,./表示当前资源所在的目录
可以书写../表示返回上一级目录
相对路径中:./可以省略
# 表单元素
- input表单元素:type属性:
button:定义可点击按钮
checkbox:定义复选框
file:定义输入字段和浏览按钮,共文件上传
hidden:定义隐藏的输入字段
image:定义图像形式的提交按钮
password:定义密码字段
radio:定义单选按钮
reset:定义重置按钮
submit:定义提交按钮
text:定义单行的输入字段,可输入文本,默认20个字符
其他属性:
name:由用户自定义input的名称
value:由用户自定义input元素的值
checked:规定其首次被选中
maxlength:正整数,规定输入的字段中的字符的最大长度
name的属性和value的属性主要是给后台用的
name表单元素的名字,要求单选按钮和复选框要有相同的name的值
checked属性主要是针对单选按钮和复选框,主要作用是一打开页面,就要可以默认选中某个元素
maxlength是用户可以在表单元素输入的最大字符数,一般较少使用
<label>标签为input元素定义标注
label:当点击label标签内的文本时,会自动聚焦到选择对应的表单元素上,用来增加用户体验;
其中的for属性应该与相关元素的id属性相同
放假第一周学习的东西主要是学生管理系统,其次就是前端的html的知识复习,补充的知识并不是很多,下一周开始css的复习