学生成绩管理系统C(链表)语言
#include"stdio.h"
#include"stdlib.h"
#include"string.h" //用于调用一些函数
struct person {
char name[];
int ID;
int chinese;
int english;
int math;
struct person *next; //连接处的指针
}; //由于create里面就有initialize所以先把initialize放在前面 void initialize(struct person *p, int num) { //初始化链表里面的值
printf("innitialize person %d\n name is:", num); //num用于计入输入的第几个同学
scanf_s("%s", &p->name, sizeof(p->name));
getchar();
printf("ID:");
scanf_s("%d", &p->ID);
getchar();
printf("chinese:");
scanf_s("%d", &p->chinese);
getchar();
printf("math:");
scanf_s("%d", &p->math);
getchar();
printf("english:");
scanf_s("%d", &p->english);
getchar();
} struct person *create(int len) {
int num = ;
struct person *h = , *c, *pre = ;
while (num < len) {
c = (struct person*)malloc(sizeof(struct person)); //malloc取内存 sizeof为这个内存的大小 然后转化成指针
if (num == ) { h = c; pre = c; } // 如果num=0 h存下了首地址 为以后拿做准备
c->next = NULL;
if (num) {
pre->next = c; //pre为前一块内存的地址 把后一块的首地址赋给前一块的尾
pre = c; //收尾连接后 pre指前一块的功能就完成了 然后再指向现在的内存 为下一次拿内存、赋地址做准备
}
initialize(c, num); //每取一块地址就去输入一次
++num;
}return h;
}
void traverse(struct person *head) {
int index = ; // 用于计数第几个学生
while (head != NULL) { //同样一直到后面没有地址结束
printf("name is: %s\t ID is:%d\t chinese is:%d\t englishi is:%d\t math is:%d\n", head->name, head->ID, head->chinese, head->english, head->math);
head = head->next; //前一个输完后就要指向下一块地址
++index;
}
} int getlength(struct person *head) {
int num = ;
while (head != NULL) { //当head指向后面没有了 它就是NULL 结束
++num;
head = head->next; //如果head 不是NULL ++num后要把head指针指向最后
}return num;
} //增加学生信息
void append_node(struct person *h) {
struct person *t = h, *p;
while (t->next != NULL) {
t = t->next;
}p = (struct person *)malloc(sizeof(struct person));
initialize(p, );
p->next = NULL;
t->next = p;
traverse(h);
} //删除
struct person * delete_ID(struct person *head, int ID, int len) {
struct person *t = head;
struct person *temp;
for (int i = ; i < (len - ); ++i) {
if (i == ) {
if (head->ID == ID) { head = head->next; free(t); traverse(head); return head; }
if ((t->next)->ID == ID) {
temp = t->next;
t->next = (t->next)->next;
free(temp); traverse(head); return head;
}
}
if (i != ) {
if ((t->next)->ID == ID) {
temp = t->next;
t->next = (t->next)->next;
free(temp); traverse(head); return head;
}t = t->next;
}
}return head;
} //学号查询
void search_ID(struct person *head, int ID) {
while (head != NULL) {
if (head->ID == ID) {
printf("name is: %s\t ID is:%d\t chinese is:%d\t englishi is:%d math is:%d\n", head->name, head->ID, head->chinese, head->english, head->math);
}head = head->next;
}
} //姓名查询
void search_name(struct person *head, char name[]) {
while (head != NULL) {
if ((strcmp(head->name, name)) == ) { printf("name is: %s\t ID is:%d\t chinese is:%d\t englishi is:%d math is:%d\n", head->name, head->ID, head->chinese, head->english, head->math); }
head = head->next;
}
} //指定学生修改
void change(struct person *head, char name[]) {
while (head != NULL) {
if (strcmp(head->name, name) == ) {
printf(" name is:");
scanf_s("%s", &head->name, sizeof(head->name));
getchar();
printf("ID:");
scanf_s("%d", &head->ID);
getchar();
printf("chinese:");
scanf_s("%d", &head->chinese);
getchar();
printf("english:");
scanf_s("%d", &head->english);
getchar();
printf("math:");
scanf_s("%d", &head->math);
getchar();
}
head = head->next;
}
traverse(head);
}
//数学分数平均数
int average_math(struct person *head, int len) {
int i = , sum = , average;
struct person *t = head;
while (t != NULL) {
sum += t->math;
t = t->next;
}
average = (sum / len);
return average;
}
//英语分数平均数
int average_english(struct person *head, int len) {
int i = , sum = , average;
struct person *t = head;
while (t != NULL) {
sum += t->english;
t = t->next;
}
average = (sum / len);
return average;
} //语文分数平均数
int average_chinese(struct person *head, int len) {
int sum = , average;
struct person *t = head;
while (t != NULL) {
sum += t->chinese;
t = t->next;
}
average = (sum / len);
return average;
} //成绩区间统计
int statistics_math(struct person*head, int min, int max) {
int conter = ;
while (head!= NULL) {
if (head->math >= min&&head->math <= max) {
++conter;
printf("name:%s math score:%d\n", head->name, head->math);
}head = head->next;
}return conter;
} int statistics_chinese(struct person*head, int min, int max) {
int conter = ;
while (head != NULL) {
if (head->chinese >= min&&head->chinese <= max) {
++conter;
printf("name:%s chinese score:%d\n", head->name, head->chinese);
}head = head->next;
}return conter;
}
int statistics_english(struct person*head, int min, int max) {
int conter = ;
while (head != NULL) {
if (head->english >= min&&head->english <= max) {
++conter;
printf("name:%s english score:%d\n", head->name, head->english);
}head = head->next;
}return conter;
} //某名学生的平均成绩
int average_name(struct person*head, char name[]) {
int av = ;
while (head != NULL) {
if (strcmp(head->name, name) == ) { av += head->math; av += head->chinese; av += head->english; }
head = head->next;
}
av = av / ;
return av;
} //排序数学
void rank_math(struct person *h, int len) {
struct person *t = h, *pre = h;
int i, math, chinese, english,ID;
char name[];
t = t->next;
for (i = ; i < (len - ); ++i) {
while (t != NULL) {
if ((t->math) >(pre->math)) {
ID = t->ID; t->ID = pre->ID; pre->ID = ID;
math = t->math; t->math = pre->math; pre->math = math;
strcpy_s(name, t->name); strcpy_s(t->name, pre->name); strcpy_s(pre->name, name);
chinese = t->chinese; t->chinese = pre->chinese; pre->chinese = chinese;
english = t->english; t->english = pre->english; pre->english = english;
}
t = t->next;
}pre = pre->next; t = pre->next;
}
traverse(h);
}
//排序语文
void rank_chinese(struct person *h, int len) {
struct person *t = h, *pre = h;
int i, math, chinese, english,ID;
char name[];
t = t->next;
for (i = ; i < (len - ); ++i) {
while (t != NULL) {
if ((t->chinese) >(pre->chinese)) {
ID = t->ID; t->ID = pre->ID; pre->ID = ID;
math = t->math; t->math = pre->math; pre->math = math;
strcpy_s(name, t->name); strcpy_s(t->name, pre->name); strcpy_s(pre->name, name);
chinese = t->chinese; t->chinese = pre->chinese; pre->chinese = chinese;
english = t->english; t->english = pre->english; pre->english = english;
}
t = t->next;
}pre = pre->next; t = pre->next;
}
traverse(h);
} //排序英语
void rank_english(struct person *h, int len) {
struct person *t = h, *pre = h;
int i, math, chinese, english,ID;
char name[];
t = t->next;
for (i = ; i < (len - ); ++i) {
while (t != NULL) {
if ((t->english) >(pre->english)) {
ID = t->ID; t->ID = pre->ID; pre->ID = ID;
math = t->math; t->math = pre->math; pre->math = math;
strcpy_s(name, t->name); strcpy_s(t->name, pre->name); strcpy_s(pre->name, name);
chinese = t->chinese; t->chinese = pre->chinese; pre->chinese = chinese;
english = t->english; t->english = pre->english; pre->english = english;
}
t = t->next;
}pre = pre->next; t = pre->next;
}
traverse(h);
} void release(struct person *head) {
struct person *n; //需要一个指针存着下一个地址
while (head != NULL) {
n = head->next; //把n指向下一块要释放的地址
free(head);
head = n; //然后再把head从前一个地址移到下一个地址
}
}
//取长度
int getlen(struct person *head) {
int conter = ;
struct person*t = head;
while (t != NULL) {
++conter;
t = t->next;
}
return conter;
}
//存入文件
void openfile(struct person *head, int len) {
FILE *fp;
struct person*t = head;
errno_t err;
int temp;
char str[];
char s[];
if ((err = fopen_s(&fp, "D:\\学生信息", "w")) != )
{
printf("文件打开错误\n");
}
else
{
printf("文件打开成功\n");
}
for (int i = ; i < len; ++i) {
strcpy_s(str, t->name);
fputs("name:", fp);
fputs(str, fp);
fputs(": ", fp); fputs("ID:", fp);
sprintf_s(s, "%d", t->ID);
fputs(s, fp);
fputs(" ", fp); sprintf_s(s, "%d", t->chinese);
fputs("chinese:", fp);
fputs(s, fp);
fputs(" ", fp); sprintf_s(s, "%d", t->math);
fputs("math:", fp);
fputs(s, fp);
fputs(" ", fp); sprintf_s(s, "%d", t->english);
fputs("english:", fp);
fputs(s, fp);
fputs("\n", fp);
t = t->next;
}
return;
} void menu(struct person *head, int len) {
int m = ;
int min, max;
int ID = ;
int conter = ;
char name[];
while () {
printf(" 请选择您需要的操作:\n");
printf(" 0. 遍历学生信息\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(" 9. 语文平均分\n");
printf(" 10. 数学平均分\n");
printf(" 11. 英语平均分\n");
printf(" 12. 某个学生的三科平均成绩\n");
printf(" 13. 按语文成绩从高到低排序\n");
printf(" 14. 按数学成绩从高到低排序\n");
printf(" 15. 按英语成绩从高到底排序\n");
printf(" 16. 结束功能并把信息写入文件中\n");
scanf_s("%d", &m);
switch (m) {
case : traverse(head); break;
case : append_node(head); break;
case : {printf("要删除学生信息的学号:");
scanf_s("%d", &ID);
head=delete_ID(head, ID, getlen(head)); }break;
case : {printf("需要修改学生信息的同学姓名:");
scanf_s("%s", &name, sizeof(name));
change(head, name); }break;
case : {printf("search by name:");
scanf_s("%s", &name, sizeof(name));
search_name(head, name); }break;
case : {printf("学号查询:");
scanf_s("%d", &ID);
search_ID(head, ID); }break;
case : {printf("请输入语文成绩的区间:");
printf("min=");
scanf_s("%d", &min);
printf("max=");
scanf_s("%d", &max);
printf("语文成绩在区间%d到%d之间的学生:%d人\n", min, max, statistics_chinese(head, min, max)); }break;
case : {printf("请输入数学成绩的区间:");
printf("min=");
scanf_s("%d", &min);
printf("max=");
scanf_s("%d", &max);
printf("数学成绩在区间%d到%d之间的学生:%d人\n", min, max, statistics_math(head, min, max)); }break;
case : {printf("请输入英语成绩的区间:");
printf("min=");
scanf_s("%d", &min);
printf("max=");
scanf_s("%d", &max);
printf("英语成绩在区间%d到%d之间的学生:共有%d人\n", min, max, statistics_english(head, min, max)); }break;
case : { printf("average of chinese is%d", average_chinese(head, getlen(head))); }break;
case : { printf("average of math is%d", average_math(head, getlen(head))); }break;
case : { printf("average of english is%d", average_english(head, getlen(head))); }break;
case : {printf("请输入学生的姓名:");
scanf_s("%s", &name, sizeof(name));
printf("%s 的平均成绩为:%d", name, average_name(head, name)); }break;
case : {printf("按照语文成绩从高到底排序:");
rank_chinese(head, getlen(head)); }break;
case : {printf("按照数学成绩从高到底排序:");
rank_math(head, getlen(head)); }break;
case : {printf("按照英语成绩从高到底排序:");
rank_english(head, getlen(head)); }break;
case : openfile(head, getlen(head)); return;
}
}
} int main() {
struct person *head;
int len;
int min, max;
int ID = ;
char name[];
printf("请输入学生信息");
printf("学生人数:");
scanf_s("%d", &len); //输入要取的地址多少
head = create(len); // 创建地址 在create里面就有初始复制函数嵌套
traverse(head); //遍历
menu(head, getlen(head));
release(head); //释放内存
system("pause");
return ;
}
学生成绩管理系统C(链表)语言的更多相关文章
- 【学生成绩管理系统】 大二c语言作业
几年前写的了,只能在命令行窗口运行,虽然比较挫,还是有一定参考价值... #include <cstdio> #include <conio.h> #include <i ...
- [项目记录] 用c语言完成的一个学生成绩管理系统
一.要求: 学生成绩管理系统 某班有最多不超过30人(具体人数由键盘输入)参加期末考试,最多不超过6门(具体门数由键盘输入).使用链表编程实现如下菜单驱动的学生成绩管理系统. 从文件读入每个学生个人信 ...
- C语言项目:学生成绩管理系统
C语言项目:学生成绩管理系统 1.数据结构:学生信息:学号.姓名.年龄.性别.3课成绩 2.功能: (1)增加学生记录 (2) 删除学生记录 (3) 查找学生信息(学号 ...
- C语言实现---学生成绩管理系统
C语言实现了学生成绩管理系统,可以进行学生成绩的增加,删除,更新,查询,计算和展示. 完整代码如下: #include<stdio.h> #include<stdlib.h> ...
- 第一次写C语言小程序,可以初步理解学生成绩管理系统的概念
1 成绩管理系统概述 1.1 管理信息系统的概念 管理信息系统(Management Information Systems,简称MIS),是一个不断发展的新型学科,MIS的定义随着科技的进步也在 ...
- C语言利用结构体数组实现学生成绩管理系统
这篇文章主要为大家详细介绍了C语言利用结构体数组实现学生成绩管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 要求: 某班有最多不超过30人(具体人数由键盘输入) ...
- 《C语言编写 学生成绩管理系统》
/* (程序头部凝视開始) * 程序的版权和版本号声明部分 * Copyright (c) 2011, 烟台大学计算机学院学生 * All rights reserved. * 文件名: 学生成绩管理 ...
- C语言练手自己编写学生成绩管理系统
#include<stdio.h> #include<stdlib.h> /*定义学生结构体*/ struct Student { ]; ]; float Mark1; flo ...
- 《C语言 学生成绩管理系统》
/* (盯着先拔头筹程序) * 该计划的版权声明和版本号 * Copyright (c) 2011, 烟台大学计算机学院学生的学校 * All rights reserved. * 文件名: 学生成绩 ...
- 学生成绩管理系统(C++指针、链表、文件及面向对象的运用)
学生成绩管理系统 功能页面显示: 实现源码: #include<iostream> #include<fstream> #include<cstring> # ...
随机推荐
- BestCoder Round #60/HDU 5505 暴力数学
GT and numbers 问题描述 给出两个数NN和MM. NN每次可以乘上一个自己的因数变成新的NN. 求最初的NN到MM至少需要几步. 如果永远也到不了输出-1−1. 输入描述 第一行读入一个 ...
- How do browser cookie domains work?
https://stackoverflow.com/questions/1062963/how-do-browser-cookie-domains-work 答案一 Although there is ...
- How to: Set Properties of Web Application Projects
https://msdn.microsoft.com/library/aa983454(v=vs.100).aspx ASP.NET Web application projects share th ...
- JSP-Runoob:JSP 文件上传
ylbtech-JSP-Runoob:JSP 文件上传 1.返回顶部 1. JSP 文件上传 JSP 可以与 HTML form 标签一起使用,来允许用户上传文件到服务器.上传的文件可以是文本文件或图 ...
- bzoj4082
贪心+倍增 首先如果这个问题在序列上,好像可以按右端点排序,然后从起点开始向能到的最远的地方走. 但是环上不可以,因为随即一个起点可能不是最小的. 然后神思路来了:我们先将环展开倍增,再将区间按右端点 ...
- PCB NOSQL MongoDb MI流程指示数据存储结构
一.MI流程指示结构 二.产品型号树结构(即盲埋孔板型号结构) 三.MI流程指示UI 小结:1.MI流程指示使用的表非常之多(30多张表),存储的数据分散到各个表中,而NOSQL 一个产品型号一条记录 ...
- 类型判断----小白讲解typeof,instanceof,Object.prototype.toString.call()
1.typeof只能判断基本类型数据, 例子: typeof 1 // "number" typeof '1' // "string" typeof true ...
- flask 初始
一.flask安装 这里提供两种安装方式: 第一种: pip3 install flask 第二种: pip3 install -i https://pypi.douban.com/simple/ f ...
- 332 Reconstruct Itinerary 重建行程单
Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], r ...
- sql语句优化:用join取代not in
不要太多使用not in查询,最好用表连接来取代它.如: select ID,name from Table_A where ID not in (select ID from Table_B) 这句 ...