用c语言链表编写一个学生信息系统程序
来源:互联网 发布:ios app跳转淘宝 编辑:程序博客网 时间:2024/04/30 10:21
要求:用c语言链表编写一个学生信息系统程序,要求输出学生的学号,姓名,性别,
还有三门课比如语,数,外的成绩,并且按照要求对其进行排序输出
/*用c语言链表编写一个学生信息系统程序,要求输出学生的学号,姓名,性别,还有三门课比如语,数,外的成绩,并且按照要求对其进行排序输出*/#include <stdio.h>#include <iostream>#include <string.h>#include <stdlib.h>using namespace std;const int n=5;/** nodeEntry : 节点数据类型* nodeADT : 节点结构* linkADT : 链表结构*/typedef struct Student{int num;char name[30];char sex;float score1;//语文float score2;//数学float score3;//英语//struct Student *next;}Student;typedef struct nodeCDT { Student entry; struct nodeCDT *next;}*nodeADT;typedef struct linkCDT { nodeADT head;}*linkADT;/** InitLink : 初始化链表* CreateNode : 创建节点* AppendLink : 添加数据*/void InitLink(linkADT *link) { *link=(linkADT)malloc(sizeof*(*link)); (*link)->head=0;}nodeADT CreateNode(Student entry) { nodeADT p=(nodeADT)malloc(sizeof*p); p->entry=entry,p->next=0; return p;}void AppendLink(linkADT *link,Student entry) { nodeADT newNode=CreateNode(entry),p; if (!*link) InitLink(link); if (!(*link)->head) (*link)->head=newNode; else { for (p=(*link)->head;p->next;p=p->next); p->next=newNode; }}/** SortLink : 排序链表* -------------------* 通过移动每个节点的指针来完成排序*///按学号排序void SortLinkID(linkADT link) { nodeADT pHead,pRear,p,tp; if (!link) return; for (pHead=link->head,pRear=0;pHead;pHead=pHead->next) { for (tp=pHead,p=pHead->next;p;tp=p,p=p->next) if (pHead->entry.num>=p->entry.num) tp->next=p->next,p->next=pHead,pHead=p,p=tp; if (!pRear) link->head=pHead; else pRear->next=pHead; pRear=pHead; }}//按语文成绩排序void SortLinkChinese(linkADT link) { nodeADT pHead,pRear,p,tp; if (!link) return; for (pHead=link->head,pRear=0;pHead;pHead=pHead->next) { for (tp=pHead,p=pHead->next;p;tp=p,p=p->next) if (pHead->entry.score1>=p->entry.score1) tp->next=p->next,p->next=pHead,pHead=p,p=tp; if (!pRear) link->head=pHead; else pRear->next=pHead; pRear=pHead; }}//按数学成绩排序void SortLinkMath(linkADT link) { nodeADT pHead,pRear,p,tp; if (!link) return; for (pHead=link->head,pRear=0;pHead;pHead=pHead->next) { for (tp=pHead,p=pHead->next;p;tp=p,p=p->next) if (pHead->entry.score2>=p->entry.score2) tp->next=p->next,p->next=pHead,pHead=p,p=tp; if (!pRear) link->head=pHead; else pRear->next=pHead; pRear=pHead; }}//按英语成绩排序void SortLinkEnglish(linkADT link) { nodeADT pHead,pRear,p,tp; if (!link) return; for (pHead=link->head,pRear=0;pHead;pHead=pHead->next) { for (tp=pHead,p=pHead->next;p;tp=p,p=p->next) if (pHead->entry.score3>=p->entry.score3) tp->next=p->next,p->next=pHead,pHead=p,p=tp; if (!pRear) link->head=pHead; else pRear->next=pHead; pRear=pHead; }}//按姓名的字典序进行排序void SortLinkName(linkADT link) { nodeADT pHead,pRear,p,tp; if (!link) return; for (pHead=link->head,pRear=0;pHead;pHead=pHead->next) { for (tp=pHead,p=pHead->next;p;tp=p,p=p->next) if (pHead->entry.name[0]>=p->entry.name[0]) tp->next=p->next,p->next=pHead,pHead=p,p=tp; if (!pRear) link->head=pHead; else pRear->next=pHead; pRear=pHead; }}//按姓名的长度进行排序void SortLinkNameLength(linkADT link) { nodeADT pHead,pRear,p,tp; if (!link) return; for (pHead=link->head,pRear=0;pHead;pHead=pHead->next) { for (tp=pHead,p=pHead->next;p;tp=p,p=p->next) if (strlen(pHead->entry.name)>=strlen(p->entry.name)) tp->next=p->next,p->next=pHead,pHead=p,p=tp; if (!pRear) link->head=pHead; else pRear->next=pHead; pRear=pHead; }}// PrintLink : 打印链表void PrintLink(linkADT link) { nodeADT p=link->head;cout<<"学号"<<" "<<"姓名"<<"\t"<<"性别"<<"\t"<<"语文"<<"\t"<<"数学"<<"\t"<<"英语"<<endl; for (;p;p!=NULL,p=p->next){cout<<p->entry.num<<" "<<p->entry.name<<"\t"<<p->entry.sex<<"\t"<<p->entry.score1<<"\t"<<p->entry.score2<<"\t"<<p->entry.score3<<endl;} printf("\n");}/* 测试 */int main() { linkADT link=0; Student stu[n]={{1002,"Gao Min",'M',80,80,80},{1008,"Wen LR",'M',79,80,70},{1000,"Wan Huang",'F',72,94,87},{1006,"Zhang Xin",'F',90,90,90},{1001,"Liu qing",'M',89,90,92}};int i; for (i=0;i<n;AppendLink(&link,*(stu+i++))); cout<<"请选择:"<<endl;cout<<"1、按照学号升序排序"<<endl;cout<<"2、按照姓名字符长度升序排序"<<endl;cout<<"3、按照姓名字典序升序排序"<<endl;cout<<"4、按照语文成绩升序排序"<<endl;cout<<"5、按照数学成绩升序排序"<<endl;cout<<"6、按照英语升序排序"<<endl;//cout<<"7、未排序数据"<<endl;cout<<"0、退出"<<endl;//cout<<"未排序数据:"<<endl;//PrintLink(link);int n;while(~scanf("%d",&n)){if(n==0) break;else if(n==1){cout<<"按照学号升序排序:"<<endl;SortLinkID(link);PrintLink(link);}else if(n==2){cout<<"按照姓名字符长度升序排序:"<<endl;SortLinkNameLength(link);PrintLink(link);}else if(n==3){cout<<"按照姓名字典序升序排序:"<<endl;SortLinkName(link);PrintLink(link);}else if(n==4){cout<<"按照语文成绩升序排序:"<<endl;SortLinkChinese(link);PrintLink(link);}else if(n==5){cout<<"按照数学成绩升序排序:"<<endl;SortLinkMath(link);PrintLink(link);}else if(n==6){cout<<"按照英语升序排序:"<<endl;SortLinkEnglish(link);PrintLink(link);}else cout<<"输入错误,请重新输入!"<<endl;}return 0;}
0 0
- 用c语言链表编写一个学生信息系统程序
- C语言实现学生信息系统
- 学生信息系统的c程序
- c语言使用链表编写一个可以实现班级学生管理系统,增加,删除,修改学生信息
- 学生信息系统简单实现C语言
- C语言编写《学生信息管理系统》之链表
- 用c语言编写学生成绩管理系统
- 用 c编写的一个学生成绩管理系统
- c语言题目----请编写一个小型学生管理系统
- 用C语言编写一个计算薪水的程序
- 用C语言编写一个输出最大值的程序
- 用 C 语言编写一个单片机流水灯程序
- 《C语言编写 学生成绩管理系统》
- 编写C语言程序 输出一个菱形
- 用C语言编写一个包含链表的初始化、插入、删除、查找等基本操作的程序。
- 用java基础语言编写一个班级学生管理系统
- C语言:学生信息管理程序
- C语言 编写一个c程序判断回文字符串。
- javax.servlet.jsp.PageContext cannot be resolved to a type
- 系统调用 5--write
- Java内部类(二)局部内部类
- 谈Python多线程及程序锁
- 系统调用 6--lseek
- 用c语言链表编写一个学生信息系统程序
- CSMAR数据库券商名称简写归类
- 2014年11月日本6日跟团游小结
- 系统调用 7--综合实例1(文件复制)
- hdoj 2588 GCD
- iBeacon技术解析
- hdu 5272 Dylans loves numbers
- Tutorial 7 Rotation Transformation
- 系统调用 8--综合实例(txt_to_txt)