




已阅读5页,还剩25页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
C语言程序设计综 合 实 习 报 告学 号119074122姓 名石险峰班 级计114指导教师陈学进安徽工业大学计算机学院2012年6 月课题一:根据条件进行学生成绩排名一、目的1.熟悉变量、数组定义、使用、输入、输出等基本操作2.进行选择、循环结构程序设计练习3.掌握冒泡法排序的算法4.掌握函数的定义、调用、声明,以及参数的两种传递方式4.掌握函数的定义、调用、声明,以及参数的两种传递方式二、实习环境个人计算机,Windows操作系统,Turbo C 2.0或 WinTC或Visual C+等编译开发环境三、实习内容、步骤与要求1.在函数中进行10个学生成绩从高到低排名 sort(int a10)2.改进第一步的函数为sort(int a,int n),进行n个学生成绩从高到低排名,3.改进第二步的函数为sort(int a,int n, char style), 将n个学生成绩从高到低排名,排名方式根据sort()函数的style参数进行,如style为a按升序排,style为d按降序排。(a:ascending 升,d:descending 降)四程序流程图、算法及运行结果Inputfor(i=0;in;i+) scanf(%d,&ai)Sortfor(i=0;in-1;i+) for(j=0;jn-i-1;j+)char c if(c=d)yesnoif(c=a)if(ajaj+1)交换两者否则,不交换 否则,不交换 开始 定义input函数,建输入模块 定义sort函数,利用冒泡法排序 在冒泡排序的前面加上if句判断 如果是d,递减排列反之递加排列 建output函数输出排列后的分数 在main函数中调用上述的函数 结束#include stdio.h#include conio.hvoid input(int score,int n) int i; for(i=0;in;i+) scanf(%d,&scorei); printf(n);sort(int score,int n,char style) int i,j,t; for(i=0;in;i+) for(j=0;jn;j+) if(style=a) if(scoreiscorej) t=scorei; scorei=scorej; scorej=t; main() int score81,i,n;char style;scanf(%d,&n);printf(please input data:n); input(score,n); getchar(); printf(please input a or d:);scanf(%c,&style); sort(score,n,style); for(i=0;inum!=NULL建insert模块,输入要插入的对象m,定义p=h,p=p-nextP!=NULL (m-numq-num)&(m-numnum)Yq-next=m; m-next=p; break;q=q-next; p=p-next;m-numq-numq-next=m; m-next=NULL;构建delete模块,while(p-next!=q) p=p-next; p-next=q-next;Main函数中调用上述模块,再添加文件即可结束主函数流程图: 定义结构体Main():int n,i,x; DAT h,p;scanf(%d,&n);h=creat(n); print(h);scanf(%d,&x); p=search(h,x); 是 if(p) 否 输出printf(No num); scanf(%d,&x); dele(h,x); print(h); insert(h); print(h); getch(); CreatDAT h,p,q; int i; h=(DAT)malloc(sizeof(NODE);scanf(%d%s%d,&h-num,h-name,&h-score);p=q=h;for(i=2;inum,p-name,&p-score); q-next=p; q=p; p-next=NULL; Print DAT p;p=h; while(p!=NULL)printf(%6d%6s%6dn,p-num,p-name,p-score)p=p-next;Search DAT p; p=h;p=p-next; while(p-num!=x&p!=NULL) 是 if(p) 否 return(p); return(NULL); DeleDAT p,q; q=search(h,x) p=h; p=p-next;p-next=q-next;free(q); p-next!=q Insert DAT p,q,j; p=q=h; j=(DAT)malloc(sizeof(NODE); scanf(%d%s%d,&j-num,j-name,&j-score); p=p-next; if(j-numq-num)&(j-numnum) 是 否 q-next=j;j-next=p;break; q=q-next;p=p-next; 是 p=NULL 否 j-numq-num 是 q-next=j; j-next=NULL;编译预处理#include stdio.h;定义结构体,typedef struct stu,结构体成员为:int num; char name20; int score; struct stu *next; 结构体外:NODE,*DAT;在主函数中,先定义int n,i,x; DAT h,p; 然后执行语句printf(请输入学生人数:) ,scanf(%d,&n);调用函数 h=creat(n);print(h);再执行printf(请输入要查的学号:n); scanf(%d,&x); 再调用函数p=search(h,x); 执行判断语句if(p),如果成立则printf(%6d%6s%6dn,p-num,p-name,p-score) ,如果不成立则printf(No num); 接着执行printf(请输入要删除的学号:n); scanf(%d,&x);依次调用函数 dele(h,x); print(h);insert(h); print(h); getch();程序结束。代码:#include stdio.h#include conio.htypedef struct dt int num; char name10; int score; struct dt *next; NODE,*DAT;DAT create(int n) DAT h,p,q; int i; h=(DAT)malloc(sizeof(NODE); scanf(%d%s%d,&h-num,&h-name,&h-score); h-next=NULL; p=q=h; for(i=2;inum,&p-name,&p-score); q-next=p; q=p; p-next=NULL; return(h);void print(DAT h) DAT p; p=h; while(p!=NULL) printf(%8d%8s%8dn,p-num,p-name,p-score); p=p-next; printf(n);DAT search(int x,DAT h) DAT p; p=h; while(p-num!=x&p!=NULL) p=p-next; if(p) return(p); else return(NULL);void del(int y,DAT h) DAT p,q; p=h; q=search(y,h); while(p-next!=q) p=p-next; p-next=q-next; free(q);DAT insert(DAT z,DAT h) DAT p0,p1,p2; p1=h; p0=z; if(h=NULL) h=p0;p0-next=NULL; else while(p0-nump1-num) & (p1-next!=NULL) p2=p1; p1=p1-next; if(p0-numnum) if(h=p1) h=p0; else p2-next=p0; p0-next=p1; else p1-next=p0;p0-next=NULL; return h;void save(DAT h) FILE *fp; DAT p; int i; p=h; if(fp=fopen(G:stu_dat,wb)=NULL) printf(cannot open filen); return; while(p!=NULL) fwrite(p,sizeof(NODE),1,fp); p=p-next; fclose(fp); main() int n,x,y; DAT h,p,z; z=(DAT)malloc(sizeof(NODE); scanf(%d,&n); h=create(n); print(h); printf(intput search data:); scanf(%d,&x); p=search(x,h); if(p) printf(%8d%8s%8dn,p-num,p-name,p-score); else printf(NO search datan); printf(intput delete data:); scanf(%d,&y); del(y,h); print(h); printf(input insert data:); getchar(); scanf(%d%s%d,&z-num,&z-name,&z-score); h=insert(z,h); print(h); save(h);getch();五、知识点、难点及解决办法。知识点:1链表的制作,查找,插入及删除功能2 结构体的制作3 指针的应用4 函数的使用 5 链表的头指针,结点的概念。难点:1 链表的各种功能函数2 指针在链表中的应用解决方法:谨慎使用链表6、 编程小结或体会。现在的程序不仅仅满足于主函数的构建,同时还需要附加其他功能,以实现不同的作用,这就需要我们去构建函数以实现这些功能。课题三:学生成绩单制作一、目的1掌握结构体变量及数组的定义、赋值、初始化、输入、输出2结构体数组的操作。二、实习环境个人计算机,Windows操作系统,Turbo C 2.0或 WinTC或Visual C+等编译开发环境三、实习内容、步骤与要求1定义一个结构体数组,存放10个学生的学号,姓名,三门课的成绩2从键盘输入10个学生的以上内容3输出单门课成绩最高的学生的学号、姓名、以及该门课程的成绩4输出三门课程的平均分数最高的学生的学号、姓名及其平均分5将10个学生按照平均分数从高到低进行排序,输出结果,格式如下所示:number name math Chinese English average103 tom 90 90 100 95101 alice 90 80 70 80 四、程序流程图、算法及运行结果开始建结构体,定义学号、姓名、成绩建输入模块,利用循环进行输入建max函数,利用循环,结合比较法,输出单科的各个信息同样方法,输出最大平均分的学生信息建sort模块,利用冒泡排序进行排列结束代码:/* HELLO.C - Hello, world */#include stdio.h#include conio.h#define n 10struct student int number; char namen; int math; int Chinese; int English; float average;stun;void input(struct student stun) int i; printf(please input 10 data:n); for(i=0;in;i+)scanf(%8d%8s%8d%8d%8d%,&stui.number,&,&stui.math,&stui.Chinese,&stui.English);void print2(struct student stun)struct student stu1; int i,j,k; for(i=0;in;i+)for(j=i+1;jn;j+)if(stui.mathstuj.math) stu1=stui;stui=stuj;stuj=stu1;printf(math zuigao wei:) ;printf(%8d%8s%8d%8d%8dn,stu0.number,,stu0.math,stu0.Chinese,stu0.English);for(i=0;in;i+)for(j=i+1;jn;j+)if(stui.Chinesestuj.Chinese)stu1=stui;stui=stuj;stuj=stu1;printf(Chinese zuigao wei:);printf(%8d%8s%8d%8d%8dn,stu0.number,,stu0.math,stu0.Chinese,stu0.English);for(i=0;in;i+)for(j=i+1;jn;j+)if(stui.Englishstuj.English)stu1=stui;stui=stuj;stuj=stu1;printf(English zuigao wei:);printf(%8d%8s%8d%8d%8dn,stu0.number,,stu0.math,stu0.Chinese,stu0.English);void print4(struct student stun) int i,j; struct student stu1; for(i=0;in;i+) for(j=i+1;jn;j+) if(stui.averagestuj.average) stu1=stui; stui=stuj; stuj=stu1; for(i=0;in;i+)printf(%8d%8s%8d%8d%8d%15fn,stui.number,,stui.math,stui.Chinese,stui.English,stui.average);void print3(struct student stun) int i,j,d ; struct student stu1; for(i=0;in;i+) stui.average=(float)(stui.math+stui.Chinese+stui.English);stui.average=stui.average/(float)(n); for(i=0;in;i+) for(j=i+1;jn;j+) if(stui.averagestuj.average) stu1=stui; stui=stuj; stuj=stu1; printf(sanmen pingjunfen zuigao:%8d%8s%8d%8d%8d%15fn,stu0.number,,stu0.math,stu0.Chinese,stu0.English,stu0.average);void print1(struct student stun)int i;printf(xianzai de data:n); for(i=0;in;i+)printf(%8d%8s%8d%8d%8dn,stui.number,,stui.math,stui.Chinese,stui.English,&stui.average);void meu()printf( number name math Chinese English averagen);main() int i;input(stu);print1(stu);print2(stu);print3(stu);meu();print4(stu);getch();五、知识点、难点及解决办法。1、 知识点有:1冒泡排序法2、 循环3、 数组4、 函数的使用5、 结构体难点:结构体的使用,带入及输出六、编程小结或体会。6、 体会:当一个问题比较繁琐时,往往建立模块显得清楚明了。课题四:学生成绩文件管理一、目的1掌握文件指针的概念和运用2掌握文件的相关操作:打开、读、写、关闭3掌握文件的定位操作二、实习环境个人计算机,Windows操作系统,Turbo C 2.0或 WinTC或Visual C+等编译开发环境三、实习内容、步骤与要求1定义一个结构体数组,存放10个学生的学号,姓名,三门课的成绩2从键盘输入10个学生的以上内容,存入文件stud.dat,关闭文件3打开stud.dat文件,将数据读出,查看是否正确写入,关闭文件。4打开文件stud.dat文件,读出数据,将10个学生按照平均分数从高到低进行排序,分别将结果输出到屏幕上和另一文件studsort.dat中。5从studsort.dat 文件中读取第2,4,6,8,10个学生的数据。 四、程序流程图、算法及运行结果算法 定义结构体,输入学生的信息,将数据写入文件stud.dat,然后读出来,然后利用循环计算每人平均分,进行排序和转换,存在stusort.dat中,然后读取stusort.dat2,4,6,8,10的信息。开始构建结构体,定义学生的学号,姓名,分数读出数据,关闭文件Main函数中,定义变量,输入数据,写入到stud,dat求出平均值,根据平均值进行排序存入到studsort.dat中读出文件,并输出2,4,6,8,10的信息结束#includestdio.h#define n 10struct student int num; char name21; int score1; int score2; int score3; stun;void save()FILE *fp;int i;if(fp=fopen(i:stud.dat,wb)=NULL )printf(Cant open filen);return;for(i=0;in;i+) if(fwrite(&stui,sizeof(struct student),1,fp)!=1) printf(write error); fclose(fp);void display()FILE *fp;int i;if(fp=fopen(i:stud.dat,rb)=NULL)printf(cant open filen);return;printf(xianzai de data:n);for(i=0;in;i+)fread(&stui,sizeof(struct student),1,fp);printf(%4d%4s%4d%4d%4dn,stui.num,,stui.score1,stui.score2,stui.score3);fclose(fp);void sort()FILE *fp,*fp1;int i,j;struct student stu1;if(fp=fopen(i:stud.dat,rb)=NULL)printf(cant open filen);return;if(fp1=fopen(i:studsort.dat,wb)=NULL)printf(cant open filen );return;printf(xianzai de data:n);for(i=0;in;i+)fread(&stui,sizeof(struct student),1,fp);for(j=i+1;jn;j+) fread(&stuj,sizeof(struct student),1,fp);if(stui.score1+stui.score2+stui.score2stuj.score1+stuj.score2+stuj.score2) stu1=stui; stui=stuj; stuj=stu1;printf(%4d%4s%4d%4d%4dn,stui.num,,stui.score1,stui.score2,stui.score3);if(fwrite(&stui,sizeof(struct student),1,fp1)!=1)printf(write errorn);fclose(fp);fclose(fp1);void display1()FILE *fp;int i;if(fp=fopen(i:studsort.dat,rb)=NULL) printf(cant open file ); return;printf(xianzai 2 4 6 8 10de data:n);for(i=1;in;i=i+2)fseek(fp,i*sizeof(struct student),0);fread(&stui,sizeof(struct student),1,fp);printf(%4d%4s%4d%4d%4dn,stui.num,,stui.score1,stui.score2,stui.score3);fclose(fp);main() int i; printf(please input data:n) ; for(i=0;in;i+)scanf(%d%s%d%d%d,&stui.num,,&stui.score1,&stui.score2,&stui.score3);save();display();sort();display1();五、知识点、难点知识点有:1循环2数组3 文件的读写 4 结构体难点:读取特定项2,4,6,8,10的信息。体会:文件的读写,保存是重难点,也是以后编程所必须掌握的,非常重要。附加题:字符串处理:用一个字符数组保存着一个英文句子要求:(a) 删除该英文句子的前导空格 后导空格和句子中多余的空格(单词之间只留一个空格)#include stdio.h#include conio.h#include string.hvoid input(char a) gets(a);void del(char a) int i,j,d; i=-1,j=0; d=strlen(a); while(ai!=n&i=d) i+; if(i=0&ai= ) continue; if(ai= &ai+1= ) continue; if(ai= &ai+1=n) continue; if(ai= &ai+1!= ) aj=ai;j+; if(ai!= ) aj=ai;j+; aj=n; puts(a);void tongji(char a,char x) int n=0,i;i=0;while(ai!=n) if(ai=x) n+; i+; printf(%c de pinlv wei:%d,x,n);main() char a81,x; input(a); del(a); printf(please input tongji danci:); scanf(%c,&x); tongji(a,x); getch();(b) 统计该句子中 单词出现的频率(c) 查找并替换某个单词/* HELLO.C -
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 云南专业活动策划执行方案
- 气象科普活动策划方案
- 电液控液压支架培训课件
- 电池阻尼和电池驱动课件
- 甘肃酒店隔墙施工方案
- 铁路下穿段施工方案
- 2025年儿科医生个人年度工作总结
- 混凝土槽身施工方案范本
- 村居活动策划方案设计
- 电气安全器具培训内容课件
- 2025年河北省中考数学试卷(含解析)
- 组装工艺培训
- 2025年江苏省苏州市中考英语真题(原卷版)
- 儿童用药合理使用课件
- 2025-2030船用内燃机行业发展分析及投资价值研究咨询报告
- 《新编日语泛读教程学生用书1》课件-新编日语泛读教程 第三册 第1课
- 护理实习生安全协议书10篇
- 巨人的陨落介绍课件视频
- 无人机测量课件
- 党务工作论述知识课件
- 科研助理笔试题库及答案
评论
0/150
提交评论