#include "main.h"
int main() {
struct Node *head = (struct Node *) malloc(sizeof(struct Node));
head->next = NULL;
char i;
while (1) {
printf("------------------\n");
printf("1.添加\n");
printf("2.查看\n");
printf("3.删除\n");
printf("4.修改\n");
printf("5.查询\n");
printf("6.排序\n");
printf("0 退出系统\n");
printf("------------------\n");
scanf("%c", &i);
fflush(stdin);
if (i == '1') addStu(head, scanner());
else if (i == '2') ergodicStu(head);
else if (i == '3') delStu(head);
else if (i == '4') updateStu(head);
else if (i == '5') searchManu(head);
else if (i == '6') sortManu(head);
else if (i == '0') return 0;
else printf("输入有误,请重试!\n");
}
}
void addStu(struct Node *head, struct Student *p) {
if (head->next == NULL) {
head->next = p;
} else {
struct Student *temp = head->next;
while (temp->next != NULL) temp = temp->next;
temp->next = p;
}
}
struct Student *scanner() {
struct Student *p = (struct Student *) malloc(sizeof(struct Student));
int ifLegal;
do {
printf("请输入学生的姓名:\n");
ifLegal = scanf("%s", p->name);
fflush(stdin);
if (ifLegal == 0) printf("输入不合法!请重新输入\n");
} while (!ifLegal);
do {
printf("请输入学生的年龄:\n");
ifLegal = scanf("%d", &p->age);
fflush(stdin);
if (p->age <= 0) ifLegal = 0;
if (ifLegal == 0) printf("输入不合法!请重新输入\n");
} while (!ifLegal);
do {
printf("请输入学生的学号:\n");
ifLegal = scanf("%d", &p->num);
fflush(stdin);
if (ifLegal == 0) printf("输入不合法!请重新输入\n");
} while (!ifLegal);
do {
printf("请输入学生的班级:\n");
ifLegal = scanf("%d", &p->class);
fflush(stdin);
if (p->class <= 0) ifLegal = 0;
if (ifLegal == 0) printf("输入不合法!请重新输入\n");
} while (!ifLegal);
do {
printf("请输入高数成绩:\n");
ifLegal = scanf("%f", &p->score[0]);
fflush(stdin);
if (p->score[0] <= 0) ifLegal = 0;
if (ifLegal == 0) printf("输入不合法!请重新输入\n");
} while (!ifLegal);
do {
printf("请输入英语成绩:\n");
ifLegal = scanf("%f", &p->score[1]);
fflush(stdin);
if (p->score[1] <= 0) ifLegal = 0;
if (ifLegal == 0) printf("输入不合法!请重新输入\n");
} while (!ifLegal);
do {
printf("请输入数据结构成绩:\n");
ifLegal = scanf("%f", &p->score[2]);
fflush(stdin);
if (p->score[2] <= 0) ifLegal = 0;
if (ifLegal == 0) printf("输入不合法!请重新输入\n");
} while (!ifLegal);
p->total = p->score[0] + p->score[1] + p->score[2];
p->ave = p->total / 3.0f;
p->next = NULL;
return p;
}
void ergodicStu(struct Node *head) {
if (head->next == NULL) {
printf("无数据\n");
return;
}
struct Student *temp = head->next;
printf("姓名\t年龄\t学号\t班级\t高数\t\t英语\t\t数据结构\t平均分\t总分\n");
while (temp != NULL) {
printf("%s\t%d\t%d\t%d\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n", temp->name, temp->age, temp->num, temp->class,
temp->score[0], temp->score[1], temp->score[2], temp->ave, temp->total);
temp = temp->next;
}
}
void delStu(struct Node *head) {
int ifLegal;
int num;
do {
printf("请输入待删除同学的学号:");
ifLegal = scanf("%d", &num);
fflush(stdin);
if (ifLegal == 0) printf("输入不合法!请重新输入\n");
} while (!ifLegal);
if (head->next == NULL) {
printf("数据不存在!\n");
return;
}
if (head->next->num == num) {
head->next = head->next->next;
printf("删除成功!\n");
return;
}
struct Student *temp = head->next;
while (temp->next != NULL) {
if (temp->next->num == num) {
temp->next = temp->next->next;
printf("删除成功!\n");
return;
}
temp = temp->next;
}
printf("数据不存在!\n");
}
void updateStu(struct Node *head) {
int num;
int ifLegal;
do {
printf("请输入待修改同学的学号:");
ifLegal = scanf("%d", &num);
fflush(stdin);
if (ifLegal == 0) printf("输入不合法!请重新输入\n");
} while (!ifLegal);
if (head->next == NULL) {
printf("数据不存在!\n");
return;
}
struct Student *p = NULL;
if (head->next->num == num) {
p = scanner();
p->next = head->next->next;
head->next = p;
printf("修改成功!\n");
return;
}
struct Student *temp = head->next;
while (temp->next != NULL) {
if (temp->next->num == num) {
p = scanner();
p->next = temp->next->next;
temp->next = p;
printf("修改成功!\n");
return;
}
temp = temp->next;
}
printf("数据不存在!\n");
}
void sortManu(struct Node *head) {
if (head->next == NULL) {
printf("无数据\n");
return;
}
printf("------------------\n");
printf("1.姓名排序\n");
printf("2.学号排序\n");
printf("3.班级排序\n");
printf("4.高数成绩排序\n");
printf("5.英语成绩排序\n");
printf("6.数据结构成绩排序\n");
printf("7.平均成绩排序\n");
printf("8.总成绩排序\n");
printf("------------------\n");
char i;
scanf("%c", &i);
fflush(stdin);
if (i == '1') sortBy(head, ifName);
else if (i == '2') sortBy(head, ifNum);
else if (i == '3') sortBy(head, ifClass);
else if (i == '4') sortBy(head, ifScore0);
else if (i == '5') sortBy(head, ifScore1);
else if (i == '6') sortBy(head, ifScore2);
else if (i == '7') sortBy(head, ifAve);
else if (i == '8') sortBy(head, ifTotal);
else printf("输入有误,请重试!\n");
}
void sortBy(struct Node *head, int(*pFun)(struct Student *)) {
for (struct Student *p = head->next; p != NULL; p = p->next) {
for (struct Student *q = p; q->next != NULL; q = q->next) {
if (pFun(q)) {
char name[25];
int age;
int num;
int class;
float score[3];
float total;
float ave;
strcpy(name, q->name);
strcpy(q->name, q->next->name);
strcpy(q->next->name, name);
age = q->age;
q->age = q->next->age;
q->next->age = age;
num = q->num;
q->num = q->next->num;
q->next->num = num;
class = q->class;
q->class = q->next->class;
q->next->class = class;
score[0] = q->score[0];
q->score[0] = q->next->score[0];
q->next->score[0] = score[0];
score[1] = q->score[1];
q->score[1] = q->next->score[1];
q->next->score[1] = score[1];
score[2] = q->score[2];
q->score[2] = q->next->score[2];
q->next->score[2] = score[2];
total = q->total;
q->total = q->next->total;
q->next->total = total;
ave = q->ave;
q->ave = q->next->ave;
q->next->ave = ave;
}
}
}
ergodicStu(head);
}
int ifName(struct Student *q) {
return strcmp(q->name, q->next->name) <= 0;
}
int ifScore0(struct Student *q) {
return q->score[0] < q->next-
没有合适的资源?快使用搜索试试~ 我知道了~
C语言数据结构期末项目-学生管理系统
共2个文件
h:1个
c:1个
需积分: 0 4 下载量 48 浏览量
2023-09-30
00:59:45
上传
评论 1
收藏 4KB ZIP 举报
温馨提示
学生管理系统是一个基于C语言数据结构的期末项目,旨在帮助学生管理和组织学生信息。该系统可以记录学生的基本信息,如姓名、学号、年龄和成绩等,并提供相应的功能,如添加、删除、查询和修改学生信息。 学生管理系统适用于学习C语言数据结构的学生和对学生信息管理感兴趣的开发者。通过实现这个项目,学生可以加深对C语言数据结构的理解,并学习如何设计和实现一个简单的信息管理系统。 学生管理系统的使用场景包括但不限于: 1. 学生信息管理:学校、教育机构或班级可以使用该系统来管理学生的基本信息和成绩记录。 2. 学生项目作业:学生可以将学生管理系统作为一个实践项目,来应用所学的C语言数据结构知识,并完成期末作业。 3. 学习和练习:对于对数据结构和算法感兴趣的开发者,学生管理系统可以作为一个练习项目,帮助他们巩固和应用所学的知识。 学生管理系统的目标是提供一个简单而实用的学生信息管理工具,帮助用户轻松管理学生信息,实现基本的增删改查操作,并具备一定的数据结构设计和算法实现能力。
资源推荐
资源详情
资源评论
收起资源包目录
C语言数据结构作业-学生管理系统.zip (2个子文件)
C语言数据结构作业-学生管理系统
main.h 1KB
main.c 15KB
共 2 条
- 1
资源评论
wmh1024
- 粉丝: 1799
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功