38c++学生信息管理系统

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

//1、已知若干名学生的信息,每名学生的信息包括:学号、姓名、英语成绩、数学成绩、计算机成绩。//编写一个录入学生信息函数input()、排序函数sort()要求对输入的无序学号进行排序,查找函数search()采用折半查找方法查找输入学生学号,//输出函数output()输出该学生各科成绩和平均成绩。#includeiostreamusingnamespacestd;classCStudent{public:voidinput();voidoutput();friendvoidsort(CStudent&);friendintseach();intno;private:charname[10];intecj;intmcj;intccj;};voidCStudent::input(){cinnonameecjmcjccj;}voidCStudent::output(){coutno:noendl;coutname:;puts(name);coutenglish:ecjendl;coutmath:mcjendl;coutcomputer:ccjendl;coutaverage:(ecj+mcj+ccj)/3endl;}CStudents[10];inti,k,j;voidcd(){coutHowmanypeople?endl;cink;coutk;}voidsort(){coutk;CStudentt;inti,j;for(intu=0;uk;u++)for(j=0;jk-1;j++)if(s[j].nos[j+1].no){t=s[j];s[j]=s[j+1];s[j+1]=t;}}intseach(){intr,i;intmid;coutplaseseachnoendl;cinr;for(i=0;ik;i++)if(s[i].no==r){cout已找到!;break;}elsecoutnofind!endl;returni;}main(){cd();inti;coutplaseinputstudent:nonameenglishmathcomputerendl;for(i=0;ik;i++)s[i].input();cout按1排序,按2搜索,按3全部显示0退出endl;intn;cinn;do{switch(n){case1:sort();break;case2:{i=seach();s[i].output();}break;case3:{for(i=0;ik;i++)s[i].output();}break;default:cout输入错误endl;}cout按1排序,按2搜索,按3全部显示0退出endl;cinn;}while(1);return0;}//2、设计一个学生类(CStudent),它具有私有数据成员是:学号、姓名、数学、外语和计算机课程的成绩。要求能实现求三门课总成绩和平均成绩,并能设置和显示学生信息(类声明和成员函数定义分离)。设计一个友元函数,按照成绩从高到低的顺序输出姓名、学号和成绩信息。#includeiostreamusingnamespacestd;classCStudent{public:voidinput();voidoutput();friendvoidsort();friendintseach();private:intno;charname[10];intecj;intmcj;intccj;};voidCStudent::input(){cinnonameecjmcjccj;}voidCStudent::output(){coutno:noendl;coutname:;puts(name);coutenglish:ecjendl;coutmath:mcjendl;coutcomputer:ccjendl;coutaverage:(ecj+mcj+ccj)/3endl;coutsum:(ecj+mcj+ccj)/3endl;}CStudents[10];inti,k,j;voidcd(){coutHowmanypeople?endl;cink;coutk;}voidsort(){coutk;CStudentt;inti,j;for(intu=0;uk;u++)for(j=0;jk-1;j++)if(s[j].ecj+s[j].mcj+s[j].ccjs[j+1].ecj+s[j+1].mcj+s[j+1].ccj){t=s[j];s[j]=s[j+1];s[j+1]=t;}}intseach(){intr,i;coutplaseseachnoendl;cinr;intlow=0,high=k;intmid;while(low=high){mid=(low+high)/2;if(r==s[mid].no)returnmid;elseif((int)r(int)s[mid].no)returnhigh=mid-1;elselow=mid+1;}returnmid;}main(){cd();inti;coutplaseinputstudent:nonameenglishmathcomputerendl;for(i=0;ik;i++)s[i].input();cout按1排序,按2搜索,按3全部显示0退出endl;intn;cinn;do{switch(n){case1:sort();break;case2:{i=seach();s[i].output();}break;case3:{for(i=0;ik;i++)s[i].output();}break;default:cout输入错误endl;}cout按1排序,按2搜索,按3全部显示0退出endl;cinn;}while(1);return0;}//3、求二叉树上结点的路径//要求在采用链式存储结构存储的二叉树上,以bt指向根结点,p指向任一给定的结点,编程实现求出从根节点到给定结点之间的路径。#includestdio.h#includestdlib.h#includeiostreamusingnamespacestd;#definenum100typedefcharDataType;typedefstructnode{DataTypedata;structnode*lchild,*rchild;}BinTNode;typedefBinTNode*BinTree;intfound;BinTNode*p;BinTreeCreateBinTree(BinTreebt){//Q[1...n]是BinTNode类型的指针数组,rear和front是指向队尾和队头的指针BinTNode*Q[num];BinTNode*s;intfront,rear;charch;ch=getchar();bt=NULL;//置空二叉树front=1;rear=0;while(ch!='%'){s=NULL;if(ch!='*'){s=(BinTNode*)malloc(sizeof(BinTNode));//申请新结点s-data=ch;s-lchild=NULL;s-rchild=NULL;}rear++;Q[rear]=s;if(rear==1)bt=s;else//不是根节点{if(s!=NULL&&Q[front]!=NULL)//当前结点及其双亲结点都不是虚结点if(rear%2==0)Q[front]-lchild=s;//rear为偶数,新结点为左孩子elseQ[front]-rchild=s;//rear为奇数,新结点为右孩子if(rear%2!=0)//rear为奇数,说明两个孩子已经处理完成,front指向下一个双亲front++;}ch=getchar();//读入下一个结点}returnbt;}voidNodePath(BinTreebt,BinTNode*ch){//求二叉树根结点到给定结点*p的路径typedefenum{FALSE,TRUE}boolean;BinTNode*stack[num];//定义栈inttag[num];inti,top;booleanfind;BinTNode*s;find=FALSE;top=0;s=bt;do{while(s!=NULL){//扫描左子树top++;stack[top]=s;tag[top]=0;s=s-lchild;}if(top0){s=stack[top];if(tag[top]==1){if(s==ch){//找到ch,则显示从根结点到ch的路径for(i=1;i=top;i++)printf(-%c,stack[i]-data);find=TRUE;}elsetop--;s=stack[top];}if(top0&&!find){if(tag[top]!=1){s=s-rchild;//扫描右子树tag[top]=1;}elses=NULL;}}}while(!find&&top!=0);}voidFindBT(BinTreebt,DataTypex){if((bt!=NULL)&&!found){if(bt-data==x){p=bt;found=1;}else{FindBT(bt-lchild,x);//遍历查找左子树FindBT(bt-rchild,x);//遍历查找右子树}}}BinTNode*Findx(BinTreebt,DataTypex){//按给定值查找结点intfound=0;//用found来作为是否查找到的标志BinTreep=NULL;//置空指针FindBT(bt,x);return(p);}intmain(){BinTreebt;intxz=1;charch1;while(xz){printf(二叉树求结点路径\n);printf(1建立二叉树存储结构\n);printf(2求指定结点的路径\n);printf(0退出\n);cinxz;switch(xz){case1:printf(请输入按完全二叉树%结束,*为空结点:\n);bt=CreateBinTree(bt);printf(二叉树的链式存储结构建立完成!\n);break;case2:printf(该输入要求路径的结点值:\n);ch1=getchar();ch1=getchar();Findx(bt,ch1);if(p!=NULL)NodePath(bt,p);elseprintf(没有结点!\n);break;}}}//内部排序算法的性能分析//要求:(1)对冒泡排序、直接排序、简单选择排序、快速排序、希尔排序、堆排序算法进行比较;//(2)待排序表的表长不小于100,表中数据随机产生,至少用5组不同数据作比较,比较指标有:关键字参加比较次数和关键字的移动次数(关键字交换记为3次移动);//(3)输出各种算法的排序结果和比较结果。#includestdio.h#includestdlib.h#includestring.h#includetime.h#includewindows.h#includewinbase.h#includeiostreamusingnamespacestd;#defineMAXSIZE100//1024*5#defineTRUE1#defineFALSE0typedefintBOOL;typedefstructStudentData{intnum;/*thisisakeyword*/}Data;typ

1 / 23
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功