C语言程序设计-基于链表的学生成绩管理系统
学生个人信息成绩管理系统(c语言动态链表不限定输入学生人数可查询保存的信息)

struct stu *creat(void) //创建链表的函数,并输入学生信息
{
n=0;
head=NULL;
do
{ p1=(struct stu * ) malloc(LEN);
if(n==1) a=head;
else a=a->next;
if (strcmp (x,a->college)==0)
printf("输出:%12d%10s%18s%10s%10s%5.1f\n",a->num,a->name,a->college,a->Class,a->subject,a->score);
n=i=0;
if (head2!=NULL)
do
{ n=n+1;
i=i+1;
if(n==1) a=head2;
else a=a->next;
if(i==1) sumnum=a->score;
//主模块
#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#define LEN sizeof(struct stu)
struct stu
printf("输出:%12d%10s%18s%10s%10s%5.1f\n",a->num,a->name,a->college,a->Class,a->subject,a->score);
C语言程序设计报告-基于链表的学生信息管理系统

《C语言程序设计实训2》报告设计题目:基于链表的学生信息管理系统学院名称:信息科学技术学院专业:网络工程班级:二班姓名:学号:指导教师:提交日期:一、 实验内容:编写并调试程序,实现学校各专业班级学生信息的管理。
要求一个工程下多个文件。
main 函数以单独的文件main.cpp 存放。
在头文件student.h 中定义学生信息的结构体类型,包括:学号、姓名、专业、班级、3门成绩;和符号常量N (学生数)。
(同一班级的学生可以属于不同的专业,同一专业的学生可以属于不同的班级)。
全局类型的定义如下:二、实验要求:(1) main 函数:以菜单形式将各项功能提供给用户,根据用户的选择,调用相应的函数。
(2) 定义函数STU *CreateList (char * filename ):从二进制文件“studentInfo.dat ”中依次读取12个学生的数据(在文件中学生信息按学号由低到高依次存放),建立带头结点(特殊结点,不放学生信息)的、有序的单链表(链表中各学生信息按学号由低到高依次存放), 返回表头指针。
每次从文件中读一个学生的信息,并将该学生信息插入到链表的表尾。
设置头结点的目的:在链表中第一个学生结点之前插入或者是删除第一个学生结点的时候不必做特殊处理)更灵活的方法:从文件中循环读数据时,根据当前学生信息的next成员的值,决定是否进行下次循环,如果next==NULL,则表明读到最后一个学生信息,循环结束。
(3)定义函数void Output (STU *head):以指向链表头结点的指针为参数,将链表中所有学生的信息表格化输出。
定义函数void OutOneNode(STU *p): 输出参数所指的链表中一个结点的信息。
(4)STU *Max(STU *head):查找总成绩最高的学生,返回指向该学生结点的指针。
考虑特殊情况,找到两个及以上相同最高分同学的情况,如何处理?(5)定义函数STU *Search_num(STU * head ,char *num ):查找指定的学生,返回指向该学生结点的指针。
C语言课程设计—学生成绩管理系统

#include ”stdio.h”#include ”string.h”#include "stdlib.h"#include "conio.h"#include ”string.h”#include "fcntl。
h"typedef struct student{int num;char grade[10];char classroom[10];char name[10];float score_math;float score_chinese;float score_english;float average;float sum;}STU;typedef struct Node{STU data;struct Node *next;}*linklist;void menu();char *loginpassword(char password[],int n);//登录验证密码函数声明//linklist createstulist(linklist head);//创建学生链表即学生信息录入函数声明// void printstulist(linklist head);//学生信息输出函数声明//void searchstu_namelist(linklist head);//学生信息查询函数声明(按姓名)// void searchstu_numlist(linklist head);//学生信息查询函数声明(按学号) linklist modifystulist(linklist head);//学生信息修改函数声明//linklist delatestulist(linklist head);//学生信息删除函数声明//void savestulist(linklist head);//学生信息保存到文件函数声明// linklist loadstulist();//从文件中读取学生信息函数声明// void sortstulist(linklist head); //成绩排名函数(按年级)声明//void sort(STU stu[],int flag); //学生分班函数声明//void sortstuclass(linklist head); //成绩排名函数(按班级)声明////*************************************//void main(){char admin[]=”zhangqiong";char password[]=”123456";char person[20];char password1[10];int i;printf(”********************************************************************************\n”);printf("\t\t **********欢迎来到学生成绩管理系统**********\n\n");printf(”********************************************************************************\n\n”);printf(”\t\t\t\t用户登录\n\n\n\n");for(i=0;i<3;i++){printf("用户名:”);gets(person);fflush(stdin);printf(”\n\n\n”);loginpassword(password1,10);printf("\n\n\n”);if(strcmp(admin,person)==0&&strcmp(password,password1)==0){printf(”\t\t\t\t成功登录,亲!\n”);printf("\n\n”);printf(”按任意键继续!”);getch();menu();break;}elseprintf("\t用户名或者密码输入错误\n”);}if(i==3)printf("\t对不起,您今天输入次数太多,已被强制退出!\n”);}//**********************************************************////**********************************************************//char *loginpassword(char password[],int n)//登录密码函数,隐藏密码可见//{int i=0;int m=0;char ch;printf("用户密码:”);while((ch=getch())!='\r’&&m〈n){password[i++]=ch;printf(”*");}password[i]='\0';return password;}//***************************************************// void menu()//主界面函数//{system("cls");linklist L;L=(linklist)malloc(sizeof(Node));L—>next=NULL;int ch;do{printf(”\t -——-----—-******——--——--—---******—————-————-******-—-—-—-—-—\n\n");printf("\t\t\t**********学生成绩管理系统***********\n\n”);printf("\t ——----——--******-—-——------—******—---———--—-******—---———-——\n\n\n\n\n");printf("\t1。
学生成绩管理系统(链表版)

《C语言应用》实验报告题目学生成绩管理系统(链表版)(1)能完成学生成绩的插入、查询、修改、删除、输出等功能;(2)采用单链表存储结构实现;(3)所有数据以外部文件方式保存第2章第2章总体设计2。
1 系统的程序流程图绘制一个系统的总体程序流程图,主要展示系统从开始以后,可以经过哪些流程,最后结束。
按姓名修改某位同学的成绩按姓名修改某位同学的成绩输出链表内容输出链表内容2。
2系统的全局变量和常量系统全局变量int n;char a;头文件:#include "stdio.h"#include ”time。
h"#include "string。
h”#include ”stdlib.h"#include ”conio。
h"2。
3系统的函数介绍把系统中的每个函数的原型列出来,解释一下函数的返回值及形式参数的含义;最后,再介绍一下每个函数的功能。
void Create(int n)//创建链表void List()//输出链表内容void list()//输出链表所有内容void save()//文件保存void save1() //文件保存void read()//文件读取void read1()//文件读取void SA VE(){ //保存到可浏览文件void SA VE1() //保存到可浏览文件void sort_data_copy(Lstu *p,Lstu *s)//交换排序时的值void sort()//对初始成绩进行排序void sort1()//对所有数据进行排序void search_print(Lstu *p)//输出查找信息void search_choose()//选择按分数段查找方式void search()//查找void modify_choose(Lstu *p,int n)//选择修改方式void modify()//按姓名修改void Insert()//按序号插入void del() //按姓名删除void statistics()//成绩统计int menu() //菜单(主界面)第3章第3章详细设计按函数,写出函数的原型声明,并画出每个函数的程序流程图。
C语言学生成绩管理系统(单向链表)

本系统实现了学生管理系统的数据新建、插入、删除、遍历、保存到文件、文件读取、数据排序、数据销毁等操作;
*************************************************************************************/
//file_ctrl.c
Student *Readfile(); //------
void Savetofile(Student *head,char *filename);//fwrite保存学生信息到文件
void SavetoFile2(Student *head,char *filename);//fprintf保存学生信息到文件
case 5: head=Sortbyno(head); //按学号排序
printf("---当前链表为:---\n");
Printinfo(head);break;
}
return 0;
}
/*************************************************************************************/
void Help()
{
printf("\n---很无语,你不知道怎么操作---\n");
}
/*========================
主函数
==========================*/
C语言写的学生成绩管理系统(链表)

#include<stdio.h>#include<string.h>#include<stdlib.h>struct stud{long num;char name[20];float sx;float dx;float ts;float dl;float cx;float zf;float pj;};struct studcode{struct stud student;struct studcode *next;};void menu();void input(struct studcode **);void output(struct studcode *);void binsearch(struct studcode *);void insert(struct studcode **);void delet(struct studcode **);void good(struct studcode *);void fail(struct studcode *);void sort(struct studcode *);void back();void main(){char choose;int flag=1;struct studcode *head;head=NULL;printf("请先录入学生成绩信息\n");printf("输入学生学号姓名高数、英语读写、英语听说、计算机导论和程序设计的成绩\n");input(&head);while (flag){system("cls");menu();printf("请选择:");getchar();choose=getchar();switch(choose){case '1':output(head);back();break;case '2':binsearch(head);back();break;case '3':insert(&head);output(head);back();break;case '4':delet(&head);output(head);back();break;case '5':good(head);back();break;case '6':fail(head);back();break;case '7':sort(head);output(head);back();break;case '0':flag=0;printf("\n *** The End! ***\n");printf("\n ####感谢使用,欢迎再次登录,拜拜!####\n");break;default: printf("\n Wrong Selection !(选择错误,请重选)\n");back();}}}void menu(){printf(" \n 学生成绩统计与分析系统\n");printf(" \n 菜单\n\n");printf(" \n 1. 显示所有学生的信息\n");printf(" \n 2. 查找某学号的学生信息\n");printf(" \n 3. 插入某学生的信息 \n");printf(" \n 4. 删除某学号学生的信息\n");printf(" \n 5. 统计各门课程成绩在90分以上学生所占百分比\n");printf(" \n 6. 统计各门课程成绩在60分以下学生所占百分比 \n");printf(" \n 7. 按总分降序排序,依高低排出名次 \n");printf(" \n 0. 退出 \n\n");}void back(){int x;printf("\n");do{printf("按1返回菜单界面:");scanf("%d",&x);}while(x!=1);}void input(struct studcode **headp){struct studcode *p;while(1){p=(struct studcode *)malloc(sizeof(struct studcode));scanf("%ld",&p->student.num);if(p->student.num==0) break;scanf("%s%f%f%f%f%f",&p->,&p->student.sx,&p->student.dx,&p->stu dent.ts,&p->student.dl,&p->student.cx);p->student.zf=p->student.sx+p->student.dx+p->student.ts+p->student.dl+p->st udent.cx;p->student.pj=p->student.zf/5;p->next=*headp;*headp=p;}}void output(struct studcode *head){struct studcode *p;p=head;printf("学号\t姓名\t高数\t读写\t听说\t导论\t程序\t总分\t平均分\n");while(p!=NULL){printf("%-ld\t%-4s\t%-0.2f\t%-0.2f\t%-0.2f\t%-0.2f\t%-0.2f\t%-0.2f\t%-0.2f\ n",p->student.num,p->,p->student.sx,p->student.dx,p->student.ts,p-> student.dl,p->student.cx,p->student.zf,p->student.pj);p=p->next;}printf("\n");}void binsearch(struct studcode *head){struct studcode *p;int k=1;long x;p=head;printf("请输入需要查找的学生的学号:");scanf("%ld",&x);printf("\n");while(p!=NULL){if(p->student.num==x){printf("该学生信息如下:\n");printf("学号\t姓名\t高数\t读写\t听说\t导论\t程序\t总分\t平均分\n");printf("%-ld\t%-4s\t%-0.2f\t%-0.2f\t%-0.2f\t%-0.2f\t%-0.2f\t%-0.2f\t%-0.2f\n",p ->student.num,p->,p->student.sx,p->student.dx,p->student.ts,p->student.dl,p->stude nt.cx,p->student.zf,p->student.pj);k=0;break;}p=p->next;}if(k) printf("没有此学生的信息\n");}void insert(struct studcode **headp){struct studcode *p;p=(struct studcode *)malloc(sizeof (struct studcode));printf("请输入你想插入的学生的信息\n");scanf("%ld%s%f%f%f%f%f",&p->student.num,&p->,&p->student.sx,&p->student.dx,&p->student.ts,&p->student.dl,&p->student.cx);p->student.zf=p->student.sx+p->student.dx+p->student.ts+p->student.dl+p->st udent.cx;p->student.pj=p->student.zf/5;p->next=*headp;*headp=p;printf("*****插入成功*****\n");}void delet(struct studcode **headp){struct studcode *p,*last;long x;p=*headp;printf("请输入你要删除的学生的学号:");scanf("%ld",&x);while(p->student.num!=x&&p->next!=NULL){last=p;p=p->next;}if(p->student.num==x){if(p==*headp)*headp=p->next;elselast->next=p->next;free(p);printf("\n*****删除成功*****\n");}else printf("\n***删除失败,无该学生信息***\n");}void good(struct studcode *head){struct studcode *p;int x1,x2,x3,x4,x5,k;float y1,y2,y3,y4,y5;x1=x2=x3=x4=x5=k=0;p=head;while(p!=NULL){k++;if(p->student.sx>=90) x1++;if(p->student.dx>=90) x2++;if(p->student.ts>=90) x3++;if(p->student.dl>=90) x4++;if(p->student.cx>=90) x5++;p=p->next;}y1=(float)x1/k;y2=(float)x2/k;y3=(float)x3/k;y4=(float)x4/k;y5=(float)x5/k;printf("高数\t读写\t听说\t导论\t程序\n");printf("%-0.2f\t%-0.2f\t%-0.2f\t%-0.2f\t%-0.2f\n",y1,y2,y3,y4,y5); }void fail(struct studcode *head){struct studcode *p;int x1,x2,x3,x4,x5,k;float y1,y2,y3,y4,y5;x1=x2=x3=x4=x5=k=0;p=head;while(p!=NULL){k++;if(p->student.sx<60) x1++;if(p->student.dx<60) x2++;if(p->student.ts<60) x3++;if(p->student.dl<60) x4++;if(p->student.cx<60) x5++;p=p->next;}y1=(float)x1/k;y2=(float)x2/k;y3=(float)x3/k;y4=(float)x4/k;y5=(float)x5/k;printf("高数\t读写\t听说\t导论\t程序\n");printf("%-0.2f\t%-0.2f\t%-0.2f\t%-0.2f\t%-0.2f\n",y1,y2,y3,y4,y5); }void sort(struct studcode *head){struct stud temp;int i,j,n;struct studcode *p,*p1,*p2;n=0;p=head;while(p!=NULL){n++;p=p->next;}for(p1=head,i=0;i<n-1;i++,p1=p1->next)for(p2=p1->next,j=i+1;j<n;j++,p2=p2->next)if(p1->student.zf<p2->student.zf){temp=p2->student;p2->student=p1->student;p1->student=temp;}printf("\n*****排序成功*****\n"); }。
C语言程序设计基于链表的学生成绩管理系统

华北科技学院计算机系综合性实验实验报告课程名称C语言程序设计实验学期2011至2012学年第二学期学生所在系部计算机系年级2011专业班级计算机科学与技术B-111学生姓名学号任课教师实验成绩计算机系制实验报告须知1、学生上交实验报告时,必须为打印稿(A4纸)。
页面空间不够,可以顺延。
2、学生应该填写的内容包括:封面相关栏目、实验地点、时间、目的、设备环境、内容、结果及分析等。
3、教师应该填写的内容包括:实验成绩、教师评价等。
4、教师根据本课程的《综合性实验指导单》中实验内容的要求,评定学生的综合性实验成绩;要求在该课程期末考试前将实验报告交给任课教师。
综合性实验中,所涉及的程序,文档等在交实验报告前,拷贝给任课教师。
任课教师统一刻录成光盘,与该课程的期末考试成绩一同上交到系里存档。
5、未尽事宜,请参考该课程的实验大纲和教学大纲。
《C语言程序设计》课程综合性实验报告开课实验室:基础五2012年7月6日代码:#include"stdio.h" #include"stdlib.h" #include<string.h> #include"conio.h" structxs{intxh;charxm[20];intgs,yy,wl;structxs*next; };intnum=0; structxs*init(){structxs*hd;hd=(structxs*)malloc(sizeof(structxs));hd->next=NULL;returnhd;}voidfr(structxs*hd){structxs*p;p=hd->next;while(hd->next!=NULL){p=hd->next;hd->next=p->next;free(p);}}voidcreate(structxs*hd){intxh,gs,yy,wl,i;charxm[20];structxs*p;fr(hd);printf("\n请输入学生个数:");scanf("%d",&num);for(i=0;i<num;i++){printf("请输入%d个学生of%d\n",i+1,num);printf("学号:");scanf("%d",&xh);printf("姓名:");scanf("%s",xm);printf("高数:");scanf("%d",&gs);printf("英语:");scanf("%d",&yy);printf("物理:");scanf("%d",&wl);p=(structxs*)malloc(sizeof(structxs));p->xh=xh;strcpy(p->xm,xm);p->gs=gs;p->yy=yy;p->wl=wl;p->next=hd->next;hd->next=p;}printf("录入数据完毕,请按任意键继续!\n");getch();}voidsave(structxs*hd){if(hd->next!=NULL){structxs*p=hd->next;inti;FILE*fp;fp=fopen("yh.txt","w");fprintf(fp,"%3d\n",num);for(i=0;i<num;i++){fprintf(fp,"%3d%12s%3d%3d%3d\n",p->xh,p->xm,p->gs,p->yy,p->wl);p=p->next;}fclose(fp);printf("\n保存文件完毕,请按任意键继续!\n");getch();}else{printf("\n当前链表为空,不需要保存,请按任意键继续!\n");getch();}}voidread(structxs*hd){inti;structxs*p;FILE*fp;fr(hd);fp=fopen("yh.txt","r");fscanf(fp,"%3d\n",&num);for(i=0;i<num;i++){p=(structxs*)malloc(sizeof(structxs));fscanf(fp,"%3d%12s%3d%3d%3d\n",p->xh,p->xm,p->gs,p->yy,p->wl);p->next=hd->next;hd->next=p;}fclose(fp);printf("\n读取文件完毕,请按任意键继续!\n");getch();}voidprint(structxs*hd){structxs*p;p=hd->next;if(p!=NULL){printf("\n数据显示\n");printf("**********************************************\n");printf("学号姓名高数英语物理平均分\n");printf("**********************************************\n");while(p!=NULL){printf("%4d",p->xh);printf("%10s",p->xm);printf("%8d",p->gs);printf("%7d",p->yy);printf("%6d",p->wl);printf("%8.2f\n",(p->wl+p->wl+p->wl)/3.0);p=p->next;}printf("**********************************************\n");printf("链表显示完毕,请按任意键继续!\n");getch();}elseprintf("\n当前链表为空,请先读取文件或创建链表!\n按任意键继续!\n");}voidmenu(){system("cls");printf("****************************************\n");printf("*学生成绩管理系统(1.0)*\n");printf("****************************************\n");printf("*jb11-131宋洁2012-7-3*\n");printf("****************************************\n");printf("*1-创建链表*\n");printf("*2-数据显示*\n");printf("*3-保存文件*\n");printf("*4-读取文件*\n");printf("*5-系统退出*\n");printf("****************************************\n");printf("请选择操作(1-5:");}voidmain(){intxz=0;structxs*head;head=init();while(xz!=5){menu();scanf("%d",&xz);switch(xz){case1:create(head);break;case2:print(head);break;case3:save(head);break;case4:read(head);break;case5:printf("\n系统退出,拜拜!\n");break;default:printf("\n选择错误,请按任意键选择!\n");getch();break;}}fr(head); free(head); }。
「C语言-学生成绩管理系统-链表实现-源码」

#include<stdio.h>//标准输入输出#include <malloc.h>//内存分配#include <stdlib.h>#include<string.h>/*####说明####2014.12.28修改内容:修改了大量bug,加入了姓名项v1.6简单学生管理系统蔚蓝之链编写本人是C语言初学者,初学C语言没几个月,程序写的"很笨",不喜勿喷^_^vc++6.0编译无error,无warning已实现功能:添加学生,列出学生信息列表,删除学生,退出,学号重复检查,排序功能,多科成绩录入(求平均成绩,及总平均成绩),保存记录,读取记录,修改功能;待实现功能:查询......2014.12.1创建文件,开始编写,增加添加学生函数,增加列出学生函数,增加删除学生函数,退出版本1.02014.12.2修改内容:增加学号重复检查函数,修复显示内容时程序终止,输出列表函数优化,添加学生函数优化 1.12014.12.3~2014.12.4修改内容:增加排序函数,删除函数内部优化,main函数内部改动,添加学生函数优化1.22014.12.5~2014.12.7修改内容:增加多科目录入,添加函数优化,新增总成绩与平均成绩显示,排序函数优化,输出函数改动1.3,更新到此告一段落,继续学习去(^_^)2014.12.9~2014.12.13修改内容:新增保存函数,读取函数,主程序修改,新增链表清除函数1.42014.12.14修改内容:新增修改函数,新增宏定义MAX_SCORE and MAX_SNO,方便程序的修改,修改程序中所有warning,一些bug修正1.5*///常量定义区+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#define bool int //由于C语言中不存在bool型,所以这里把它定义成int型#definetrue 1 //同上#define false 0 //↑#define LEN sizeof(struct ryb) //动态内存分配空间大小#define DATAFILE "DATA"//数据保存文件名#defineMAX_SCORE150//最高分数上限值#define MAX_SNO200 //最多录入学生上限值,即能输入的最大学号数//END常量定义============================================================================================================//声明函数=================================================================================================================struct ryb* del_item_ryb (struct ryb *head,intsno,int * del_message);//删除指定学号节点(链表头,欲删除学号,处理结果(1为删除成功,0为删除失败)),返回删除后的链表头structryb * create_item_ryb (struct ryb *head);//向指定的链表添加学生,并返回链表头voidput_ryb (struct ryb * head);//输出学号及成绩(欲输出链表头)bool is_sno(struct ryb*head, int sno );//判断指定学号是否存在,如存在返回tru e,不存在返回false(链表头,欲判断学号)struct ryb * order(struct ryb *head, enumordertypetype,intfs);//排序函数;(链表头,排序方式(asc或desc),排序类型(1为按学号,2为按总成绩))bool save_data(struct ryb * head);//保存链表数据函数(欲保存链表头)struct ryb *read_data(void);//读取数据到链表,并返回链表头void clear(struct ryb* head);//清除函数,清除指定链表所有数据,释放内存空间void amend_ryb(struct ryb * head,int sno);//修改函数,修改指定学号学生成绩信息(链表头,要修改成绩的学生学号)structryb {//定义链表数据结构intsno; //学号ﻩchar name[9]; //姓名int chinese; //语文ﻩint math; //数学ﻩint english; //英语int clanguage; //C语言ﻩinttiyu; //体育int score; //总成绩ﻩstruct ryb *next;};enum ordertype{//定义排序枚举类型asc,desc};//性感的分割线$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$主程序$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$int main ( void ){struct ryb * head,* temp_h;//链表头,临时链表boolexit=false;short intvalue;//接受输入信息1,2,3,41表示添加信息,2显示信息,3删除信息,4排序,5退出int sno, del_message=0;//学号,删除函数处理结果(1为删除成功,0为删除失败)intpxfs,pxlx;//排序方式,排序类型(方式asc\desc);(类型1学号,2成绩)char is_quit;//表示是否退出,y或Y表示退出,否则不退出ﻩchar is_save;//表示是否保存数据,y或Y表示保存,否则不保存char is_read;//表示是否读取数据,y或Y表示读取,否则不读取ﻩbool ssave;//表示是否保存成功,true表示成功,false表示保存失败ﻩint amend_sno;//表示要修改的学号head= (struct ryb*)malloc(LEN);//创建初始链表head->sno=0;//链表赋初值ﻩhead->next = NULL;ﻩdoﻩ{printf("蔚蓝学生管理系统v1.6(C语言版) \n\n");printf("①添加学生\n②显示成绩列表\n③删除学生\n④排序\n⑤保存数据\n⑥读取数据\n⑦修改\n⑧退出系统\n\n");ﻩprintf("等待命令输入:");fflush(stdin);//清空键盘缓冲区scanf("%d",&value);if(value== 1)//添加ﻩ{head=create_item_ryb(head);//添加信息ﻩprintf("录入信息结束!\n");system("pause");}else if (value == 2)//显示ﻩ{put_ryb(head); //显示信息ﻩﻩsystem("pause");ﻩ}else if(value== 3)//删除ﻩ{printf("请输入要删除的学生学号:");ﻩfflush(stdin);//清空键盘缓冲区ﻩﻩscanf("%d",&sno);ﻩhead = del_item_ryb(head,sno,&del_message);ﻩ//删除ﻩif(del_message== 1){ﻩﻩprintf("删除成功!!!\n");ﻩ}ﻩﻩelse{ﻩﻩprintf("删除失败!!!\n");ﻩ}ﻩsystem ("pause");ﻩ}else if(value== 4)//排序ﻩ{r:ﻩﻩprintf ("请请输入排序方式(1升序,2降序):");ﻩfflush(stdin);ﻩscanf("%d",&pxfs);ﻩﻩprintf("请输入排序类型(1按学号,2按成绩):");ﻩfflush(stdin);ﻩscanf("%d",&pxlx);if(pxfs >2 || pxfs<0 || pxlx>2|| pxlx<0)ﻩﻩ{ﻩﻩprintf("排序方式或排序类型输入不符合规定!!!请重新输入!!!\n");system ("pause");ﻩﻩgoto r;}ﻩif(pxfs==1)ﻩ{ﻩhead=order(head, asc,pxlx);}ﻩelse {ﻩﻩhead=order(head, desc,pxlx);ﻩﻩ}ﻩprintf ("排序完成!!!\n");ﻩ system("pause");ﻩ}elseif(value== 5)//保存数据{ﻩﻩis_save= 'N';ﻩprintf("您是否要保存当前修改过的学生数据,以前的数据将被覆盖!\n(Y\\N):");ﻩﻩfflush(stdin);ﻩﻩscanf("%c",&is_save);ﻩif(is_save =='Y' || is_save == 'y')ﻩ{ﻩﻩssave = save_data(head);ﻩﻩif(ssave == true)ﻩﻩ{ﻩﻩﻩprintf ("当前数据已成功保存到磁盘!\n");system("pause");ﻩﻩ}else{ﻩﻩprintf("保存失败或没有数据!\n");ﻩﻩsystem("pause");ﻩﻩ}}ﻩﻩelseﻩ{ﻩprintf ("您取消了保存数据操作!\n");ﻩﻩsystem("pause");}ﻩ}elseif(value==6)//读取数据ﻩ{is_read ='N';printf("您是否要读取磁盘数据,执行此操作将覆盖当前数据,是否继续?\n (Y\\N):");fflush(stdin);ﻩscanf("%c", &is_read);if(is_read =='Y'||is_read =='y')ﻩ{ﻩtemp_h =read_data();ﻩﻩﻩif(temp_h== NULL)ﻩﻩ{ﻩprintf ("数据读取失败!\n");ﻩsystem("pause");ﻩ}else{ﻩﻩﻩclear(head);//清空当前链表,释放空间ﻩﻩﻩhead =temp_h;//读取新链表ﻩﻩprintf("数据读取成功!\n");ﻩsystem("pause");ﻩ}ﻩ}ﻩﻩelseﻩ{ﻩprintf("您取消了数据读取操作!\n");ﻩsystem ("pause");ﻩ}ﻩ}else if(value ==7)ﻩ{ﻩﻩamend_sno=0;ﻩprintf("请输入要修改的学生学号:");fflush(stdin);ﻩﻩscanf("%d",&amend_sno);ﻩif(amend_sno>0&& amend_sno <= MAX_SNO){ﻩamend_ryb(head,amend_sno);}ﻩﻩelse{ﻩﻩprintf ("学号输入不合法,学号为1-%d之间的数包括(1,%d)!!!\n",MAX_SNO,MAX_SNO);ﻩﻩsystem("pause");ﻩﻩcontinue;ﻩ}}elseif(value== 8)//退出ﻩ{printf("您确定要退出蔚蓝学生成绩管理系统吗?(Y\\N):");ﻩfflush(stdin);ﻩﻩscanf("%c",&is_quit);ﻩif(is_quit== 'Y'|| is_quit =='y')ﻩ{exit = true;ﻩprintf("感谢使用蔚蓝学生成绩管理系统,再见!\n");ﻩﻩsystem("pause");ﻩﻩ}ﻩﻩ}ﻩelse{printf("请输入1-7之间的数!!!\n");ﻩsystem("pause");}system("cls");}while(exit==false);return 0;}//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$主程序END$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$//函数定义#if(1)struct ryb *del_item_ryb (struct ryb*head, int sno,int*messag e)//删除指定学号节点(链表头,欲删除学号,处理结果(1为删除成功,0为删除失败)),返回删除后的链表头{structryb * p,* p1;p =head;ﻩdo{ﻩﻩﻩif(p->sno==sno){ﻩﻩif(p == head)//如果第一个为要删除的值ﻩ{ﻩﻩﻩhead = head->next;//修改链表头ﻩﻩﻩﻩ//printf("已成功修改头指针sno=%d\n",head->sno);ﻩ}ﻩﻩelseﻩ{ﻩﻩﻩﻩp1->next= p->next;//将链表节点指向要删除的链表节点的下一节点ﻩﻩfree(p);//释放已删除的链表节点内存ﻩﻩﻩ}ﻩﻩﻩ*message = 1;ﻩbreak;ﻩﻩ}p1 = p;//保存当前链表节点ﻩp = p->next;ﻩif(p->next==NULL && p->math >=0 && p->math<=MAX_SNO)ﻩﻩ{ﻩﻩ*message =0;ﻩﻩ}ﻩ}while(p->next&& p->math>=0&& p->math <= MAX_SNO);return head;ﻩ}#endifstructryb* create_item_ryb(struct ryb*head) //向指定的链表添加学生,并返回链表头{ﻩstruct ryb *p1;inti=1;//i表示学生数ﻩint tempsno;//临时学号ﻩint scorearr[5],n;//分数数组,循环值char tempname[9];//临时姓名printf("提示:当学号为0时则终止添加,并返回主界面,姓名长度不能超过4个字\n\n");//输出提示信息p1=head;while (p1->next != NULL)//寻找链表尾,找到后将p1指向链表尾以接受学生信息的添加ﻩ{ﻩp1 =p1->next;ﻩi++;ﻩ}do {ﻩﻩp1->sno =0;sno:ﻩprintf("请输入学生%d学号与姓名[格式:学号,姓名]:",i);ﻩﻩfflush(stdin);//清空键盘缓冲区ﻩﻩif(scanf("%d,%s",&tempsno,&tempname) == 2)ﻩﻩ{ﻩ;}ﻩﻩelseﻩﻩ{ﻩﻩprintf("输入格式错误!请重新输入T_T\n");ﻩsystem("pause");ﻩgoto sno;ﻩ}ﻩif(tempsno!= 0){ﻩﻩif(is_sno(head,tempsno) == false)//判断学号是否存在ﻩﻩﻩ{ﻩp1->sno= tempsno;ﻩﻩ}ﻩﻩelse {ﻩprintf ("学号[%d]已存在!!!\n",tempsno);ﻩﻩgoto sno;ﻩ}}ﻩelse{ﻩcontinue;ﻩﻩ}printf("---------------------------------------------\n");ﻩprintf("请输入学生%d成绩(语文,数学,英语,C语言,体育,以逗号分隔):",i);ﻩﻩfor(n=0;n<=4;n++)//成绩数组赋初值ﻩ{ﻩﻩscorearr[n]=0;ﻩ}fflush(stdin);//清空键盘缓冲区ﻩﻩscanf("%d,%d,%d,%d,%d",&scorearr[0],&scorearr[1],&scorearr[2],&scorearr[3],&scorearr[4]);ﻩprintf("*********************************************\n");//检测输入合法性ﻩif(p1->sno== 0)ﻩﻩ{ﻩ;}ﻩelseif(p1->sno < 1 ||p1->sno>MAX_SNO)//判断学号是否合法,(1~200){ﻩprintf("学号输入不合法,学号为1-%d之间的数包括(1,%d)!!!\n",MAX_SNO,MAX_SNO);ﻩﻩﻩsystem("pause");ﻩcontinue;ﻩ}else//判断成绩合法性ﻩ{ﻩfor(n=0;n<=4;n++)//检测成绩录入合法性ﻩﻩﻩ{ﻩﻩif (scorearr[n]<0 ||scorearr[n]>MAX_SCORE)ﻩﻩ{ﻩﻩprintf("成绩输入不合法或成绩数值输入错误,各科成绩应为0-%d之间的数包括(0,%d)!!!\n",MAX_SCORE,MAX_SCORE);ﻩﻩﻩsystem("pause");ﻩﻩﻩcontinue;ﻩﻩﻩ}ﻩ}ﻩﻩﻩp1->sno= tempsno;p1->chinese= scorearr[0];p1->math = scorearr[1];ﻩﻩﻩp1->english= scorearr[2];ﻩﻩp1->clanguage = scorearr[3];ﻩﻩp1->tiyu =scorearr[4];ﻩstrcpy(p1->name ,tempname);ﻩ//求总成绩ﻩﻩp1->score=scorearr[0]+scorearr[1]+scorearr[2]+scorearr[3]+scorearr[4];ﻩﻩﻩﻩ}ﻩif(p1->sno!= 0){p1->next =(struct ryb*)malloc(LEN);//create一个新节点给p1->nextp1 = p1->next;//将新节点地址给p1p1->next = NULL;//↑ﻩﻩ}else{ﻩﻩp1->sno =0;ﻩ}i++;ﻩ}while(p1->sno!= 0);//判断学号是否为0;为0退出添加ﻩreturnhead;}#if(1)void put_ryb(struct ryb* head)//输出学号及成绩(欲输出链表头){struct ryb *pryb = head;struct ryb zcj;//总成绩int student_num =0;//学生人数ﻩ//初始化总成绩结构体zcj.chinese = 0;zcj.clanguage= 0;ﻩzcj.english= 0;ﻩzcj.math=0;ﻩzcj.tiyu = 0;//初始化ENDﻩsystem("cls");printf (" --------------\n");printf("|某班学生成绩表|\n");printf("--------------\n");printf ("-------- ---- ---- ------------- --------------\n");printf("|学号||姓名||语文| |数学| |英语| |C语言||体育||总成绩| |平均成绩|\n");ﻩprintf("-------- ---- ------------- ---- ------ --------\n");//8,8,8,8,9,8,10,12do{ﻩif(pryb->sno != 0&&pryb->math>= 0 && pryb->math <=MAX_SNO)//输出成绩ﻩ{ﻩprintf("%-8d%-8s%-8d%-8d%-8d%-9d%-8d%-10d%-12d\n",pryb->sno,pryb->name,pryb->chinese,pryb->math,ﻩ pryb->english,pryb->clanguage,pryb->tiyu,pryb->score,pryb->score / 5);zcj.chinese = zcj.chinese +pryb->chinese;//计算各科总成绩ﻩﻩzcj.clanguage = zcj.clanguage+pryb->clanguage ;ﻩﻩzcj.english=zcj.english + pryb->english;ﻩﻩzcj.math= zcj.math + pryb->math;ﻩﻩzcj.tiyu =zcj.tiyu+ pryb->tiyu ;ﻩstudent_num++;//记录总学生人数,表示链表不为空:ﻩpryb=pryb->next;}ﻩ}while(pryb->next &&pryb->math >= 0 &&pryb->math<= MAX_SNO);if (student_num >=1)//判断链表是否为空ﻩ{ﻩprintf ("\n\n[总平均成绩]:(语文:%d,数学:%d,英语:%d,C语言:%d,体育:%d)\n",zc j.chinese/student_num, zcj.math / student_num,ﻩﻩzcj.english / student_num,zcj.clanguage /student_num , zcj.tiyu/ student_num);//输出总平均成绩}else{ﻩprintf ("没有可以输出列表!\n\n");}ﻩ}#endifbool is_sno(struct ryb* head,int sno)//判断学号是否存在(头指针,学号),如学号存在返回true,不存在返回false{structryb *p;ﻩp=head;ﻩdo {ﻩif(p->sno ==sno)ﻩ{ﻩﻩreturn true;ﻩ}ﻩﻩif (p->next != NULL){ﻩﻩp = p->next;ﻩ}}while(p->next!=NULL);ﻩreturnfalse;}//排序函数排序使用冒泡算法struct ryb* order(struct ryb *head,enumordertype type, intfs)//排序函数;(链表头,排序方式(asc或desc),排序类型(1为按学号,2为按总成绩)){structryb*p,*rp,*ptemp,*rph;//要排序的链表,要返回的链表,临时排序链表,要返回的链表头int max,min;ﻩint pro_mess;//删除函数处理结果1,0if(head->sno==0)ﻩ{ﻩreturn head;}p = head;ﻩmax =0,min= 0;ﻩrp=(structryb *) malloc(LEN);//create一个新节点给rp ﻩrph = rp;do{ptemp = p;if(fs == 1)//按学号ﻩ{ﻩﻩﻩmax=ptemp->sno;//赋初值ﻩmin= ptemp->sno;ﻩ}ﻩelse { //按成绩ﻩmax=ptemp->sno;ﻩﻩmin= ptemp->score;ﻩmax = ptemp->score;ﻩﻩ}ﻩrp->sno= ptemp->sno;ﻩrp->score=ptemp->score;ﻩrp->tiyu =ptemp->tiyu;ﻩrp->english =ptemp->english;ﻩrp->chinese= ptemp->chinese ;rp->math =ptemp->math ;ﻩrp->clanguage=ptemp->clanguage ;ﻩﻩstrcpy(rp->name , ptemp->name) ;do{if(type == desc)//降序ﻩ{if(fs==1)//按学号ﻩ{ﻩﻩﻩif(ptemp->sno >max)ﻩﻩﻩﻩ{ﻩﻩﻩmax = ptemp->sno;ﻩﻩrp->sno= ptemp->sno ;ﻩﻩﻩﻩﻩrp->score =ptemp->score ;ﻩﻩﻩrp->tiyu =ptemp->tiyu ;ﻩﻩﻩrp->english = ptemp->english;ﻩﻩrp->chinese=ptemp->chinese ;ﻩﻩrp->math= ptemp->math;ﻩﻩﻩﻩrp->clanguage = ptemp->clanguage ;strcpy(rp->name, ptemp->name);}ﻩﻩﻩ}ﻩelse if (fs ==2)//按成绩ﻩﻩ{ﻩif(ptemp->score > max)ﻩ{ﻩﻩmax = ptemp->score;ﻩﻩrp->sno= ptemp->sno;ﻩﻩrp->score =ptemp->score;ﻩﻩﻩrp->tiyu= ptemp->tiyu ;ﻩﻩﻩﻩrp->english =ptemp->english;ﻩﻩﻩrp->chinese =ptemp->chinese;ﻩﻩﻩrp->math=ptemp->math ;ﻩﻩrp->clanguage = ptemp->clanguage;ﻩﻩﻩstrcpy(rp->name ,ptemp->name);}ﻩﻩ}ﻩﻩ}ﻩﻩif(type== asc)//升序{ﻩﻩﻩif(fs ==1)//按学号ﻩﻩ{ﻩﻩif(ptemp->sno <min)ﻩﻩﻩ{ﻩﻩmin =ptemp->sno;ﻩrp->sno = ptemp->sno;ﻩﻩﻩﻩrp->score=ptemp->score ;ﻩﻩrp->tiyu= ptemp->tiyu ;ﻩﻩﻩrp->english=ptemp->english;ﻩﻩﻩrp->chinese = ptemp->chinese;ﻩﻩrp->math = ptemp->math ;ﻩrp->clanguage = ptemp->clanguage;ﻩstrcpy(rp->name , ptemp->name);ﻩﻩ}ﻩ}ﻩelse if(fs== 2)//按成绩ﻩﻩ{ﻩﻩif(ptemp->score <min)ﻩ{ﻩﻩmin =ptemp->score;ﻩrp->sno= ptemp->sno ;ﻩﻩrp->score =ptemp->score ;ﻩﻩﻩrp->tiyu = ptemp->tiyu ;ﻩﻩﻩﻩrp->english =ptemp->english ;ﻩﻩﻩrp->chinese =ptemp->chinese ;ﻩﻩﻩrp->math= ptemp->math ;ﻩﻩrp->clanguage = ptemp->clanguage;ﻩﻩstrcpy(rp->name, ptemp->name) ;ﻩﻩﻩ}ﻩﻩ}ﻩ}ptemp=ptemp->next ;}while(ptemp->next !=NULL);p=del_item_ryb(p,rp->sno,&pro_mess);ﻩrp->next=(struct ryb*) malloc(LEN);//create一个新节点给rp->next rp = rp->next ;ﻩif(p->next==NULL){//添加链表尾信息链表尾为一个指向NULL的空结构,以表示链表结束ﻩrp->score = 0;ﻩrp->sno=0;rp->next=NULL;ﻩ}}while(p->next!= NULL);return rph;//返回排序后链表头}//排序函数END;------------------------------------------------------------------------------boolsave_data(struct ryb * head)//保存链表数据函数(欲保存链表头),成功返回true,失败返回false{ﻩFILE *fp;struct ryb * p;p= head;ﻩif (head->sno== 0)//如果链表为空ﻩ{ﻩreturn false;//返回false}ﻩfp = fopen(DATAFILE, "wb+");//打开可读写文件,若文件存在则文件长度清为零,即该文件内容会消失。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
华北科技学院计算机系综合性实验实验报告课程名称 C语言程序设计实验学期 2011 至 2012 学年第二学期学生所在系部计算机系年级 2011 专业班级计算机科学与技术B-111学生姓名学号任课教师实验成绩计算机系制实验报告须知1、学生上交实验报告时,必须为打印稿(A4纸)。
页面空间不够,可以顺延。
2、学生应该填写的内容包括:封面相关栏目、实验地点、时间、目的、设备环境、内容、结果及分析等。
3、教师应该填写的内容包括:实验成绩、教师评价等。
4、教师根据本课程的《综合性实验指导单》中实验内容的要求,评定学生的综合性实验成绩;要求在该课程期末考试前将实验报告交给任课教师。
综合性实验中,所涉及的程序,文档等在交实验报告前,拷贝给任课教师。
任课教师统一刻录成光盘,与该课程的期末考试成绩一同上交到系里存档。
5、未尽事宜,请参考该课程的实验大纲和教学大纲。
《C语言程序设计》课程综合性实验报告实验题目基于链表的学生成绩管理系统一、实验目的1、掌握链表的创建、遍历显示和清除;2、掌握链表数据的文件保存、读取;二、设备与环境微型计算机、VC++三、实验内容1、定义结构体,创建链表struct xsnode{int xh;char xm[15];int gs;int yy;int wl;struct xsnode *next;};2、根据以上链表结点结构,实现以下功能a、学生学号、姓名、各门成绩的录入;b、链表数据显示及清除;c、链表数据的文件保存与读取;四、实验结果及分析1、运行结果主菜单数据显示2、源程序主函数void main(){int xz=0;struct xs *head;head=init();while(xz!=5){menu();scanf("%d",&xz);switch(xz){case 1:create(head);break;case 2:print(head);break;case 3:save(head);break;case 4:read(head);break;case 5:printf("\n 系统退出,拜拜!\n ");break;default:printf("\n 选择错误,请按任意键选择!\n ");getch();break;代码:#include""#include""#include<>#include""struct xs{int xh;char xm[20];int gs,yy,wl;struct xs *next;};int num=0;struct xs *init(){struct xs* hd;hd=(struct xs *)malloc(sizeof(struct xs));hd->next=NULL;return hd;}void fr(struct xs *hd){struct xs *p;p=hd->next;while(hd->next!=NULL){p=hd->next;hd->next=p->next;free(p);}}void create(struct xs *hd){int xh,gs,yy,wl,i;char xm[20];struct xs *p;fr(hd);printf("\n 请输入学生个数:");scanf("%d",&num);for(i=0;i<num;i++){printf("请输入%d个学生of %d\n",i+1,num);printf(" 学号:");scanf("%d",&xh);printf(" 姓名:");scanf("%s",xm);printf(" 高数:");scanf("%d",&gs);printf(" 英语:");scanf("%d",&yy);printf(" 物理:");scanf("%d",&wl);p=(struct xs *)malloc(sizeof(struct xs));p->xh=xh;strcpy(p->xm,xm);p->gs=gs;p->yy=yy;p->wl=wl;p->next=hd->next;hd->next=p;}printf(" 录入数据完毕,请按任意键继续!\n ");getch();}void save(struct xs *hd){if(hd->next!=NULL){struct xs *p=hd->next;int i;FILE *fp;fp=fopen("","w");fprintf(fp,"%3d\n",num);for(i=0;i<num;i++){fprintf(fp,"%3d %12s %3d %3d %3d\n",p->xh,p->xm,p->gs,p->yy,p->wl);p=p->next;}fclose(fp);printf("\n 保存文件完毕,请按任意键继续!\n ");getch();}else{printf("\n 当前链表为空,不需要保存,请按任意键继续!\n ");getch();}}void read(struct xs *hd){int i;struct xs *p;FILE *fp;fr(hd);fp=fopen("","r");fscanf(fp,"%3d\n",&num);for(i=0;i<num;i++){p=(struct xs *)malloc(sizeof(struct xs));fscanf(fp,"%3d %12s %3d %3d %3d\n",p->xh,p->xm,p->gs,p->yy,p->wl);p->next=hd->next;hd->next=p;}fclose(fp);printf("\n 读取文件完毕,请按任意键继续!\n ");getch();}void print(struct xs *hd){struct xs*p;p=hd->next;if(p!=NULL){printf("\n 数据显示\n");printf("**********************************************\n");printf(" 学号姓名高数英语物理平均分\n");printf("**********************************************\n");while(p!=NULL){printf("%4d ",p->xh);printf("%10s",p->xm);printf("%8d",p->gs);printf("%7d",p->yy);printf("%6d",p->wl);printf("%\n",(p->wl+p->wl+p->wl)/;p=p->next;}printf("**********************************************\n");printf(" 链表显示完毕,请按任意键继续!\n");getch();}elseprintf("\n 当前链表为空,请先读取文件或创建链表!\n 按任意键继续!\n ");}void menu(){system("cls");printf(" ****************************************\n");printf(" * 学生成绩管理系统*\n");printf(" ****************************************\n");printf(" * jb11-1 31 宋洁2012-7-3 *\n");printf(" ****************************************\n");printf(" * 1-创建链表*\n");printf(" * 2-数据显示*\n");printf(" * 3-保存文件*\n");printf(" * 4-读取文件*\n");printf(" * 5-系统退出*\n");printf(" ****************************************\n");printf(" 请选择操作(1-5:");}void main(){int xz=0;struct xs *head;head=init();while(xz!=5){menu();scanf("%d",&xz);switch(xz){case 1:create(head);break;case 2:print(head);break;case 3:save(head);break;case 4:read(head);break;case 5:printf("\n 系统退出,拜拜!\n ");break;default:printf("\n 选择错误,请按任意键选择!\n ");getch();break;}}fr(head);free(head);}。