学习完C语言基础知识点,现在来用单链表、函数、指针的相关知识写一个简单版学生成绩管理系统,主要实现增删改查的基本功能。

主界面:(自己设计)

void main()
{system("cls");printf("\n\n");printf("\t\t\t===========================================\n");printf("\t\t\t|                                         |\n");printf("\t\t\t|          欢迎来到学生成绩管理系统         |\n");printf("\t\t\t|                                         |\n");printf("\t\t\t|=========================================|\n");printf("\t\t\t|            请选择要操作的命令             |\n");printf("\t\t\t|-----------------------------------------|\n");printf("\t\t\t|                                         |\n");printf("\t\t\t|              1.录入学生信息              |\n");printf("\t\t\t|              2.显示学生信息              |\n");printf("\t\t\t|              3.增加学生信息              |\n");printf("\t\t\t|              4.删除学生信息              |\n");printf("\t\t\t|              5.修改学生信息              |\n");printf("\t\t\t|              6.查找学生信息              |\n");printf("\t\t\t|              7.按总分排序                |\n");printf("\t\t\t|                                         |\n");printf("\t\t\t===========================================\n");int Item;//保存操作命令pnode phead=NULL;//定义一个指针while(1){printf("请选择操作命令:");scanf("%d",&Item);system("cls");//清屏switch(Item){case 1://录入学生信息{phead=Input();}break;case 2://显示学生信息{Show(phead);}break;case 3://增加学生信息{Add(phead);}break;case 4://删除学生信息{Delete(phead);}break;case 5://修改学生信息{Change(phead);}break;case 6://查找学生信息{Search(phead);}break;case 7://总分排序{Sort(phead);Show(phead);}break;default:break;}}system("pause");
}

1.定义一个学生结构和一个结点结构,用于存储信息。

学生结构:

//学生结构
struct Student
{char Name[10];int Num;float Computer;float Math;float English;float Total;float Ave;
};

结点结构:

//结点
typedef struct Node
{struct Student st;//数据域struct node *pnext;//指针域
}node, *pnode;//*node等价于struct Student st,pnode等价于struct Node *pNext

2.定义一些函数来处理学生信息。

函数模块:

//函数
pnode Input();//录入学生信息
void Show(pnode phead);//显示学生信息
void Add(pnode phead);//增加学生信息
void Delete(pnode phead);//删除学生信息
void Change(pnode phead);//修改学生信息
void Search(pnode phead);//查找学生信息
void Sort(pnode phead);//总分排序

1)录入学生信息pnode Input()

//录入学生信息
pnode Input()
{int num;//学生的人数node stu;//学生结构pnode phead=(pnode)malloc(sizeof(node));//定义一个头结点并且为头结点分配内存//判断内存是否为空if(NULL==phead){printf("内存分配失败,程序终止!\n");exit(-1);}pnode ptail=phead;//定义一个指向头结点的指针ptail->pnext=NULL;//清空指针域printf("请输入学生的人数:");scanf("%d",&num);int i;for(i=0;i<num;i++){printf("请输入第%d个学生的姓名:",i+1);scanf("%s",stu.st.Name);printf("请输入第%d个学生的学号:",i+1);scanf("%d",&stu.st.Num);printf("请输入第%d个学生的计算机成绩:",i+1);scanf("%f",&stu.st.Computer);printf("请输入第%d个学生的高数成绩:",i+1);scanf("%f",&stu.st.Math);printf("请输入第%d个学生的大英成绩:",i+1);scanf("%f",&stu.st.English);//计算总分stu.st.Total=stu.st.Computer+stu.st.Math+stu.st.English;//计算平均分stu.st.Ave=stu.st.Total/3.0f;//为新节点分配内存pnode pnew=(pnode)malloc(sizeof(node));//判断内存是否为空if(NULL==pnew){printf("内存分配失败,程序终止!\n");exit(-1);}pnew->st=stu.st;//初始化结点的数据域ptail->pnext=pnew;//将新结点挂到老结点后pnew->pnext=NULL;//清空新结点的指针域ptail=pnew;//将ptail移到新结点上}return phead;
}

2)显示学生信息void Show(pnode phead)

//显示学生信息
void Show(pnode phead)
{//定义一个指针用于遍历学生信息pnode p=phead->pnext;printf("姓名  学号 计算机 高数  大英 总分 平均分\n");while(NULL!=p){printf("%s    %d    %g    %g    %g   %g    %g\n",p->st.Name,p->st.Num,p->st.Computer,p->st.Math,p->st.English,p->st.Total,p->st.Ave);p=p->pnext;}
}

3)增加学生信息void Add(pnode phead)

//增加学生信息
void Add(pnode phead)
{pnode p=phead;int i=0;struct Student stu;//学生结构体 int loc;//插入结点的位置printf("请输入插入学生的位置:");scanf("%d",&loc);while(NULL!=p&&i<loc-1){p=p->pnext;i++;}if(NULL==p||i>loc){printf("插入结点的位置不存在!\n");return;}printf("你将在第%d个学生后面插入一个学生\n",loc-1);printf("请输入第%d个学生的姓名:",loc);scanf("%s",stu.Name);printf("请输入第%d个学生的学号:",loc);scanf("%d",&stu.Num);printf("请输入第%d个学生的计算机成绩:",loc);scanf("%f",&stu.Computer);printf("请输入第%d个学生的高数成绩:",loc);scanf("%f",&stu.Math);printf("请输入第%d个学生的大英成绩:",loc);scanf("%f",&stu.English);stu.Total=stu.Computer+stu.Math+stu.English;//计算总分stu.Ave=stu.Total/3.0f;//计算平均分pnode pnew=(pnode)malloc(sizeof(node));if(NULL==pnew){printf("动态内存分配失败,程序终止!\n");exit(-1);}pnew->st=stu;pnode q=p->pnext;p->pnext=pnew;pnew->pnext=q;
}


4)删除学生信息void Delete(pnode phead)

//删除学生信息
void Delete(pnode pHead)
{pnode p = pHead;int i = 0;int loc;printf("请输入你需要删除的学生的编号:");scanf("%d",&loc);while(NULL!=p->pnext&&i<loc-1){p=p->pnext;i++;}if(NULL==p->pnext||i>loc-1){printf("没找到需要删除的学生的编号!\n");return;}pnode q=p->pnext;p->pnext=q->pnext;free(q);q==NULL;printf("你已经成功删除了第%d个学生的信息!\n",loc);
}

5)修改学生信息void Change(pnode phead)

//修改学生信息
void Change(pnode phead)
{char Name[10];printf("请输入你需要修改的学生的姓名:");scanf("%s",&Name);pnode p=phead->pnext;//定义一个指针用于遍历学生信息while(NULL!=p){if(0==strcmp(Name,p->st.Name)){printf("姓名  学号 计算机 高数  大英 总分 平均分\n");printf("修改前的学生信息!\n");printf("%s    %d    %g    %g    %g   %g    %g\n",p->st.Name,p->st.Num,p->st.Computer,p->st.Math,p->st.English,p->st.Total,p->st.Ave);system("pause");system("cls");//清屏printf("请输入新的学生姓名:");scanf("%s",p->st.Name);printf("请输入新的学生学号:");scanf("%d",&p->st.Num);printf("请输入新的学生的计算机成绩:");scanf("%f",&p->st.Computer);printf("请输入新的学生的高数成绩:");scanf("%f",&p->st.Math);printf("请输入新的学生的大英成绩:");scanf("%f",&p->st.English);p->st.Total=p->st.Computer+p->st.Math+p->st.English;//计算总分p->st.Ave=p->st.Total/3.0f;//计算平均分break;}p=p->pnext;}
}



6)查找学生信息void Search(pnode phead)

//查找学生信息
void Search(pnode pHead)
{char Name[10];printf("请输入你需要查找的学生的姓名:");scanf("%s",Name);pnode p=pHead->pnext;printf("姓名  学号 计算机 高数  大英 总分 平均分\n"); while(NULL!=p){if(0==strcmp(Name,p->st.Name)){printf("%s    %d    %g    %g    %g   %g    %g\n",p->st.Name,p->st.Num,p->st.Computer,p->st.Math,p->st.English,p->st.Total,p->st.Ave);}p=p->pnext;}
}

7)按总分排序void Sort(pnode phead)

//总分排序
void Sort(pnode phead)
{pnode p, q;//定义两个指针node temp;for(p=phead->pnext;NULL!=p;p=p->pnext){for(q=p->pnext;NULL!=q;q=q->pnext){if(p->st.Total<q->st.Total)//当前一个学生的总分小于后一个学生的总分时{temp.st=p->st;//交换学生的位置p->st=q->st;q->st=temp.st;}}}
}

完整代码:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//学生结构体
struct Student
{char Name[10];int Num;float Computer;float Math;float English;float Total;float Ave;
};
//结点
typedef struct Node
{struct Student st;//数据域struct node *pnext;//指针域
}node, *pnode;//*node等价于struct Student st,pnode等价于struct Node *pNext //函数
pnode Input();//录入学生信息
void Show(pnode phead);//显示学生信息
void Add(pnode phead);//增加学生信息
void Delete(pnode phead);//删除学生信息
void Change(pnode phead);//修改学生信息
void Search(pnode phead);//查找学生信息
void Sort(pnode phead);//总分排序 void main()
{system("cls");printf("\n\n");printf("\t\t\t============================================\n");printf("\t\t\t|                                          |\n");printf("\t\t\t|          欢迎来到学生成绩管理系统        |\n");printf("\t\t\t|                                          |\n");printf("\t\t\t|==========================================|\n");printf("\t\t\t|            请选择要操作的命令            |\n");printf("\t\t\t|------------------------------------------|\n");printf("\t\t\t|                                          |\n");printf("\t\t\t|              1.录入学生信息              |\n");printf("\t\t\t|              2.显示学生信息              |\n");printf("\t\t\t|              3.增加学生信息              |\n");printf("\t\t\t|              4.删除学生信息              |\n");printf("\t\t\t|              5.修改学生信息              |\n");printf("\t\t\t|              6.查找学生信息              |\n");printf("\t\t\t|              7.按总分排序                |\n");printf("\t\t\t|                                          |\n");printf("\t\t\t============================================\n");int Item;//保存操作命令pnode phead=NULL;//定义一个指针while(1){printf("请选择操作命令:");scanf("%d",&Item);system("cls");//清屏switch(Item){case 1://录入学生信息{phead=Input();}break;case 2://显示学生信息{Show(phead);}break;case 3://增加学生信息{Add(phead);}break;case 4://删除学生信息{Delete(phead);}break;case 5://修改学生信息{Change(phead);}break;case 6://查找学生信息{Search(phead);}break;case 7://总分排序{Sort(phead);Show(phead);}break;default:break;}}system("pause");
}
//录入学生信息
pnode Input()
{int num;//学生的人数node stu;//学生结构pnode phead=(pnode)malloc(sizeof(node));//定义一个头结点并且为头结点分配内存//判断内存是否为空if(NULL==phead){printf("内存分配失败,程序终止!\n");exit(-1);}pnode ptail=phead;//定义一个指向头结点的指针ptail->pnext=NULL;//清空指针域printf("请输入学生的人数:");scanf("%d",&num);int i;for(i=0;i<num;i++){printf("请输入第%d个学生的姓名:",i+1);scanf("%s",stu.st.Name);printf("请输入第%d个学生的学号:",i+1);scanf("%d",&stu.st.Num);printf("请输入第%d个学生的计算机成绩:",i+1);scanf("%f",&stu.st.Computer);printf("请输入第%d个学生的高数成绩:",i+1);scanf("%f",&stu.st.Math);printf("请输入第%d个学生的大英成绩:",i+1);scanf("%f",&stu.st.English);stu.st.Total=stu.st.Computer+stu.st.Math+stu.st.English;//计算总分stu.st.Ave=stu.st.Total/3.0f;//计算平均分pnode pnew=(pnode)malloc(sizeof(node));//为新节点分配内存//判断内存是否为空if(NULL==pnew){printf("内存分配失败,程序终止!\n");exit(-1);}pnew->st=stu.st;//初始化结点的数据域ptail->pnext=pnew;//将新结点挂到老结点后pnew->pnext=NULL;//清空新结点的指针域ptail=pnew;//将ptail移到新结点上}return phead;
}
//显示学生信息
void Show(pnode phead)
{//定义一个指针用于遍历学生信息pnode p=phead->pnext;printf("姓名  学号 计算机 高数  大英 总分 平均分\n");while(NULL!=p){printf("%s    %d    %g    %g    %g   %g    %g\n",p->st.Name,p->st.Num,p->st.Computer,p->st.Math,p->st.English,p->st.Total,p->st.Ave);p=p->pnext;}
}
//增加学生信息
void Add(pnode phead)
{pnode p=phead;int i=0;struct Student stu;//学生结构体 int loc;//插入结点的位置printf("请输入插入学生的位置:");scanf("%d",&loc);while(NULL!=p&&i<loc-1){p=p->pnext;i++;}if(NULL==p||i>loc){printf("插入结点的位置不存在!\n");return;}printf("你将在第%d个学生后面插入一个学生\n",loc-1);printf("请输入第%d个学生的姓名:",loc);scanf("%s",stu.Name);printf("请输入第%d个学生的学号:",loc);scanf("%d",&stu.Num);printf("请输入第%d个学生的计算机成绩:",loc);scanf("%f",&stu.Computer);printf("请输入第%d个学生的高数成绩:",loc);scanf("%f",&stu.Math);printf("请输入第%d个学生的大英成绩:",loc);scanf("%f",&stu.English);stu.Total=stu.Computer+stu.Math+stu.English;//计算总分stu.Ave=stu.Total/3.0f;//计算平均分pnode pnew=(pnode)malloc(sizeof(node));if(NULL==pnew){printf("动态内存分配失败,程序终止!\n");exit(-1);}pnew->st=stu;pnode q=p->pnext;p->pnext=pnew;pnew->pnext=q;
}
//删除学生信息
void Delete(pnode pHead)
{pnode p = pHead;int i = 0;int loc;printf("请输入你需要删除的学生的编号:");scanf("%d",&loc);while(NULL!=p->pnext&&i<loc-1){p=p->pnext;i++;}if(NULL==p->pnext||i>loc-1){printf("没找到需要删除的学生的编号!\n");return;}pnode q=p->pnext;p->pnext=q->pnext;free(q);q==NULL;printf("你已经成功删除了第%d个学生的信息!\n",loc);
}
//修改学生信息
void Change(pnode phead)
{char Name[10];printf("请输入你需要修改的学生的姓名:");scanf("%s",&Name);pnode p=phead->pnext;//定义一个指针用于遍历学生信息while(NULL!=p){if(0==strcmp(Name,p->st.Name)){printf("姓名  学号 计算机 高数  大英 总分 平均分\n");printf("修改前的学生信息!\n");printf("%s    %d    %g    %g    %g   %g    %g\n",p->st.Name,p->st.Num,p->st.Computer,p->st.Math,p->st.English,p->st.Total,p->st.Ave);system("pause");system("cls");//清屏printf("请输入新的学生姓名:");scanf("%s",p->st.Name);printf("请输入新的学生学号:");scanf("%d",&p->st.Num);printf("请输入新的学生的计算机成绩:");scanf("%f",&p->st.Computer);printf("请输入新的学生的高数成绩:");scanf("%f",&p->st.Math);printf("请输入新的学生的大英成绩:");scanf("%f",&p->st.English);p->st.Total=p->st.Computer+p->st.Math+p->st.English;//计算总分p->st.Ave=p->st.Total/3.0f;//计算平均分break;}p=p->pnext;}
}
//查找学生信息
void Search(pnode pHead)
{char Name[10];printf("请输入你需要查找的学生的姓名:");scanf("%s",Name);pnode p=pHead->pnext;printf("姓名  学号 计算机 高数  大英 总分 平均分\n"); while(NULL!=p){if(0==strcmp(Name,p->st.Name)){printf("%s    %d    %g    %g    %g   %g    %g\n",p->st.Name,p->st.Num,p->st.Computer,p->st.Math,p->st.English,p->st.Total,p->st.Ave);}p=p->pnext;}
}
//总分排序
void Sort(pnode phead)
{pnode p, q;//定义两个指针node temp;for(p=phead->pnext;NULL!=p;p=p->pnext){for(q=p->pnext;NULL!=q;q=q->pnext){if(p->st.Total<q->st.Total)//当前一个学生的总分小于后一个学生的总分时{temp.st=p->st;//交换学生的位置p->st=q->st;q->st=temp.st;}}}
}
仅用于本人学习记录,路过的小伙伴有任何问题欢迎评论!

C语言学生成绩管理系统相关推荐

  1. 用C语言学生成绩数据库排序功能设计,[c语言学生成绩管理系统]C语言学生成绩管理系统实验报告...

    篇一 : C语言学生成绩管理系统实验报告 实 验 四:结构体(6学时) 实验目的: 1.更加灵活的使用数组作为函数参数: 2.初步掌握开发一个小型实用系统的基本方法: 3.初步掌握书写程序设计开发文档 ...

  2. c语言按给定成绩查询,C语言学生成绩管理系统(简易版)

    #include #include #include int readstudents(struct students stu[]); //读取学生信息 int readsexcode(struct ...

  3. C语言学生成绩管理系统(课程设计报告书)

    今天再跟大家分享一份课程设计报告:C语言学生成绩管理系统源码 程序设计组成框图: #include<stdio.h> #include<conio.h> #include< ...

  4. C语言学生成绩管理系统源代码

    分享:C语言学生成绩管理系统设计 <C语言程序设计>实训报告 点击查看 ----> C语言学生成绩管理系统(课程设计报告书) 扫描下方公众号,发送 成绩系统 4个字,获取下载源码. ...

  5. c语言成绩管理系统教程,C语言学生成绩管理系统教程.doc

    C语言学生成绩管理系统教程 实训报告 题 目: 学生成绩管理系统院 系: 专 业: 姓 名: 学 号: 指导教师: 日 期: 目录 TOC \o "1-3" \h \z \u HY ...

  6. c语言成绩管理系统报告书,C语言学生成绩管理系统实验报告

    <C语言学生成绩管理系统实验报告>由会员分享,可在线阅读,更多相关<C语言学生成绩管理系统实验报告(22页珍藏版)>请在人人文库网上搜索. 1.学生成绩管理系统实验报告实验名称 ...

  7. C语言 学生成绩管理系统 带登录界面

    C语言 学生成绩管理系统 带登录界面 C语言课程设计 思路 部分展示 代码片段 C语言课程设计 先上要求: 思路 为了方便简单,直接利用结构体数组来存储学生学生,最后根据功能编写函数即可. 部分展示 ...

  8. c语言学生成绩管理系统(增、删、查、改、排序、分析优秀及格率等)

    复制时运行出错请看这里:c语言学生成绩管理系统 添加公众号回复 学管 免费获取源代码 代做可私聊 c语言学生成绩管理系统(增.删.查.改.排序.分析优秀及格率等)详细内容 一.功能描述 实现学生基本信 ...

  9. c语言学生成绩管理系统课设作业,C语言课程设计——学生成绩管理系统

    摘 要 学生成绩管理系统是一个教育单位不可缺少的部分,它的内容对于学校的决策者和管理者来说都至关重要,所以学生成绩管理系统应该能够为用户提供充足的信息和快捷的查询手段.但一直以来人们使用传统人工的方式 ...

  10. 更新学生的成绩C语言,学生成绩管理系统C语言代码实现.pdf

    学生成绩管理系统C语言代码实现 这篇文章主要为大家详细介绍了C语言代码实现学生成绩管理系统,文中示 代码介绍的非常详细,具有一定的参 考价值,感兴趣的小伙伴们可以参考一下 C语言实现了学生成绩管理系统 ...

最新文章

  1. Android百度地图scode,“androidsdk | 百度地图API SDK
  2. DOM中Event 对象如何使用
  3. U盘启动盘制作方法 2种绝招轻松搞定
  4. KindEditor中使用val()获取content内容后图片不显示
  5. No identities are available for signing 的解决办法
  6. (DFS+DP)滑雪(poj1088)
  7. tuning 02 Diagnostic and Tuning Tools
  8. Ubuntu12.04安装配置Nginx Tomcat环境
  9. Flutter之Widget构建过程详解
  10. ps html插件初始化失败,解决PSCC2019无法安装扩展插件怎么办?
  11. 记录在Eclipse中连接JDBC数据库的功能,并且实现增删改查
  12. C# 实现多种语言切换,通过VS实现
  13. 计算机频繁开机是什么原因,电脑频繁自动重启什么原因
  14. SpringBoot2.x 集成 腾讯云短信
  15. 日本官方版灌篮高手结局
  16. 人体姿态识别研究综述(详细归纳!)(转载)
  17. 校企合作,人才共育|岳阳开放大学校长乐艳华一行莅临云畅科技考察交流
  18. python将excel导入生成矩阵
  19. TiDB 5.0 HTAP 架构设计与场景解析
  20. qq密码自动测试软件,QQ2004测试版密码获取演示

热门文章

  1. 剑指Offer_16_合并两个排序的链表
  2. win7怎么安装消息队列 MSMQ
  3. C#中的委托和事件(转)
  4. HTML5_2(视频)
  5. cvHoughLines2() 霍夫线变换
  6. ubuntu16.04安装opencv3.3
  7. ubuntu运行c/c++语言
  8. torch随机数 manual_seed
  9. Qt 应用程序图标设置
  10. linux程序库设置错误,Linux--C库函数ferror中文翻译