预览加载中,请您耐心等待几秒...
1/7
2/7
3/7
4/7
5/7
6/7
7/7

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

C语言的基础练习C语言的基础练习一、实验目的对C语言的复习,增强学生对结构体数组和指针的学习,尤以结构体的应用和指针的操作作为重点。二、问题描述1、构造一个学生结构体,成员包括学号,姓名,四门成绩,以及平均成绩;2、从键盘上输入学生的学号,姓名和四门成绩;3、找出学生中考试没有通过的.学生姓名并输出;找出考试在90分以上的学生并输出。三、实验要求1、要求分别用数组和链表存储学生的记录,并设计出输入和查找的基本操作算法。2、在实验过程中,分析算法的时间复杂度和空间复杂度进行分析。四、实验环境PC微机DOS操作系统或Windows操作系统TurboC程序集成环境或VisualC++程序集成环境五、实验步骤1、用所选择的语言实现算法;3、测试程序,并对算法进行时间和空间复杂度分析。结构体数组方法及测试结果:#includeusingnamespacestd;structstudent{intnum;charname[20];floatscore[4];floatave;};//构造结构体studentinti,j,k,m,n,a[100],b[100];structstudentstu[100];intmain()cout<<"Pleaseinputthenumber:(0isend)";cin>>stu[0].num;i=0;while(stu[i].num){cout<<"Pleaseinputthename:";cin>>stu[;cout<<"Pleaseinputthescores:";stu[i].ave-0;for(j=0;j<=3;j++){cin>>stu[i].score[j];stu[i].ave+=stu[i].score[j];}stu[i].ave=stu[i].ave/4.0;i++;cout<<"Pleaseinputthenumber:(0isend)";cin>>stu[i].num;}n=i-1;k=m=0;for(i=0;i<=n;i++){if(stu[i].ave>90)a[k++]=i;else{for(j=0;j<=3;j++)if(stu[i].score[j]<60){b[m++]=i;gotoloop;}}//以上为输入操作//使用a[]存放90分以上的学生位置//使用a[]存放未通过的学生位置{loop:;}//以上为查找操作if(k>0){for(i=0;i<=k-1;i++)cout<<stu[a[i]].name<<"";cout<<"is(are)90above."<<endl;}      //输出90以上的学生if(m>0){for(i=0;i<=m-1;i++)}cout<<stu[b[i]].name<<"";cout<<"didnotpasstheexam."<<endl;}      //输出未通过学生return0;链表方法及测试结果:#includeusingnamespacestd;structstudent{longnum;charname[20];floatscore[4];floatave;structstudent*next;};intmain(){structstudent*head,*p,*q;intnumber,k,j,m,i;char*a[100],*b[100];head=0;k=0;cout<<"inputthenumberofstudent:";cin>>number;while(number!=0){k++;p=newstudent;p->num=number;cout<<"Pleaseinputthename:"; cin>>p->name;cout<<"Pleaseinputthescores:"; p->ave=0;for(j=0;j<=3;j++){cin>>p->score[j];p->ave+=p->sco