课程设计实验报告-统计数字.docx

上传人:scccc 文档编号:12681277 上传时间:2021-12-05 格式:DOCX 页数:17 大小:188.39KB
返回 下载 相关 举报
课程设计实验报告-统计数字.docx_第1页
第1页 / 共17页
课程设计实验报告-统计数字.docx_第2页
第2页 / 共17页
课程设计实验报告-统计数字.docx_第3页
第3页 / 共17页
课程设计实验报告-统计数字.docx_第4页
第4页 / 共17页
课程设计实验报告-统计数字.docx_第5页
第5页 / 共17页
点击查看更多>>
资源描述

《课程设计实验报告-统计数字.docx》由会员分享,可在线阅读,更多相关《课程设计实验报告-统计数字.docx(17页珍藏版)》请在三一文库上搜索。

1、.程序设计课程设计姓 名:朱瑞春学 号:2013005493班 级:软件工程1308班指导教师:马建芬成 绩:课程设计报告统计数字专业:_软件工程_ 班级:_1308班_ 姓名:朱瑞春_ 学号:_ 2013005493 _ 完成日期:_6.24_【问题描述】某次科研调查时得到了n个自然数,每个数均不超过1500000000(1.5*109)。已知不相同的数不超过10000个,现在需要统计这些自然数各自出现的次数,并按照自然数从小到大的顺序输出统计结果。【设计需求及分析】(1) 用一维数组存储调查得到的n个自然数,原始数据保存在文件count.in,第一行输入自然数个数,2-n+1输入自然数。结

2、果保存在count.out中。(2) 用冒泡法对n个自然数进行排序,分别统计不同的自然数个数。【设计功能的实现】#include<stdio.h>#include<stdlib.h>void main()float a100,t;int i,n,j,sum;freopen("count.in.txt","r",stdin);/原始数据保存在count.in中freopen("count.out.txt","w",stdout);/输出结果保存在count.out中scanf("%d

3、",&n);for(i=0;i<n;i+)scanf("%f",&ai);/输入n个自然数for(i=0;i<n;i+)for(j=i;j<n;j+)if(ai>aj)t=ai;ai=aj;aj=t;/对n个自然数进行排序sum=1;for(i=0,j=1;j<n;i+,j+)if(ai!=aj)break;if(j>=n)printf("%f:%dn",a0,n);elsefor(i=0,j=1;j<n;i+,j+)if(ai=aj)sum+;else printf("%f:

4、%dn",ai,sum);sum=1;sum=1;for(i=n-1;i>=1;i-)if(ai=ai-1)sum+;else printf("%f:%dn",ai,sum);break;/ /统计不同自然数的出现次数【实例测设及运行结果】【心得体会】 文本的存储和读取原本是用指针来完成实现的,在实现的过程中遇到了不小的麻烦且用指针实现过于繁琐,故改用freopen("count.in.txt","r",stdin);freopen("count.out.txt","w",std

5、out);语句实现,使程序变的简单易懂。课程设计报告谁拿了最多奖学金专业:_软件工程_ 班级:_1308班_ 姓名:_朱瑞春_ 学号:_ 2013005493 _ 完成日期:_6.25_【问题描述】某校的惯例是在每学期的期末考试之后发放奖学金。发放的奖学金共有五种,获取的条件各自不同:1) 院士奖学金,每人8000元,期末平均成绩高于80分(>80),并且在本学期内发表1篇或1篇以上论文的学生均可获得;2) 五四奖学金,每人4000元,期末平均成绩高于85分(>85),并且班级评议成绩高于80分(>80)的学生均可获得;3) 成绩优秀奖,每人2000元,期末平均成绩高于90分

6、(>90)的学生均可获得;4) 西部奖学金,每人1000元,期末平均成绩高于85分(>85)的西部省份学生均可获得;5) 班级贡献奖,每人850元,班级评议成绩高于80分(>80)的学生干部均可获得;只要符合条件就可以得奖,每项奖学金的获奖人数没有限制,每名学生也可以同时获得多项奖学金。例如姚林的期末平均成绩是87分,班级评议成绩82分,同时他还是一位学生干部,那么他可以同时获得五四奖学金和班级贡献奖,奖金总数是4850元。【设计需求及分析】(1) 定义结构体类型,用结构体申明一个结构体数组用于存储学生信息。(2) 在循环输入数据的同时,分别计算每个同学应得奖学金数和总的奖学

7、金数分别存在sum数组中和add变量中。(3) 申明变量max,依次与每个同学应得奖学金比较,存储获得奖学金最多学生姓名和奖学金数。【设计功能的实现】#include <stdio.h> void main()    struct Student         char name20;      int grade1;  &

8、#160;   int grade2;      char ganbu;  char xibu;  int title;    a100;/定义结构体,同时申明一个结构体数组用于存储学生信息。   int N;   scanf("%d",&N);   int i;   int su

9、m100=0;   int add=0;   for(i=0;i<N;i+)         scanf("%s %d %d %s %s %d",&ai.name,&ai.grade1,&ai.grade2,&ai.ganbu,&ai.xibu,&ai.title);      if(

10、ai.grade1>80 && ai.title>0) sumi+=8000;      if(ai.grade1>85 && ai.grade2>80) sumi+=4000;      if(ai.grade1>90) sumi+=2000;      if(ai.grade1>85 &&

11、amp; ai.xibu='Y') sumi+=1000;  if(ai.grade2>80 && ai.ganbu='Y') sumi+=850;         add+=sumi;      /分别输入学生信息,同时根据学生情况计算学生应得的奖学金数和总的奖学金数。   int j; &#

12、160; int t=0;   int max=sum0;   for(j=0;j<N;j+)          if(sumj>max)                max=sumj;      

13、0;  t=j;                printf("%sn%dn%dn",at.name,sumt,add);/输出最高讲学金。【实例测设及运行结果】【心得体会】 在实现过程中原本是通过定义each方法类来实现对每个学生应得奖学金的计算和result方法类对学生的奖学金进行比较得出获奖学金最多的学生和最高奖学金的,但是经过比较觉得在主函数中实现比较有条理,更加容易理解。如果定义类方法实现,类方法

14、实现简单,但是类方法需要申明、定义、调用。所以选择了在主函数中实现。课程设计报告单词的计数专业:_软件工程_ 班级:_1308班_ 姓名:_朱瑞春_ 学号:_ 2013005493 _ 完成日期:_6.26_【问题描述】假设有如下的英文文本文档:(此处为太原理工大学学校简介英文版)TAIYUAN UNIVERSITY OF TECHNOLOGYTaiyuan University of Technology (TUT) has its history traced all the way back to the Western Learning School of Shanxi Grand A

15、cademy (1902), which was one of the three earliest national universities in China. With the tradition and development of over 100 years, TUT is now a general university with engineering as the major, sciences and technology integrated and coordinate development of multiple disciplines. It is a unive

16、rsity that is included in the “Project 211” - the national higher education promotion program for 100 top universities in China.Recollecting the centennial history, generations of TUT have created its mission and glory of a century with responsibility and confidence; expecting the promising tomorrow

17、, over 30,000 TUT students and faculty are producing splendor and perspectives by their wisdom and diligence. In the new era, Taiyuan University of Technology, following the Conception of Scientific Development, is determined to further the reformation on education, to reinforce the teaching managem

18、ent so as to upgrade its teaching and researching levels. Taiyuan University of Technology will be turning itself into a research-based university.设计C或C+程序,统计在这样的英文文本文件中,出现了多少个单词,每个单词出现了几次。连续的英文字符都认为单词(不包括数字),单词之间用空格或标点符号分隔。【设计需求及分析】(1) 定义结构体用于存储一个单词,freopen语句生成文本文档并用来保存结果。(2) 通过FILE指针判断文本打开是否成功,成功则

19、输入单词。【设计功能的实现】#include<stdio.h> #include<string.h>#include<ctype.h> #include <stdlib.h> #define N 1000struct a  char ch20; int m;int flag; void main()  freopen("count.out.txt","

20、;w",stdout);/把生成的结果保存在生成的count.out文档中。 struct a wordN=NULL;char tem20;int k=0,j=0,i=0,count=1; FILE *fp; char c20; if(fp=fopen("tyut.txt","r")!=NULL)  while(!(feof(fp)  fscanf(fp,"%s",wordk.ch); 

21、    k+; /如果tyut的文本打开成功,则向文本中输入单词。for(i=0;i<k;i+)  if(wordi.flag!=1) wordi.flag=1;    wordi.m+;for(j=i+1;j<k;j+)  if(strcmp(wordi.ch,wordj.ch)=0)&&(wordj.flag!=1)       wordi.m+; 

22、60; wordj.flag=1;   /统计单词数。       printf("文本共有单词数:%dn",k);     system("pause");     printf("文本统计结果如下: n");for(i=0;(wordi.ch!=NULL)&&(i<N);i+)if(wordi

23、.m!=0)printf("%3d. %s,出现了次数:%d次.n",count,wordi.ch,wordi.m);count+;    for(i=0;i<k;i+)/字典序排序      for(j=i+1;j<k;j+)       if(strcmp(wordi.ch,wordj.ch)>0)      

24、60;              strcpy(tem,wordi.ch);            strcpy(wordi.ch,wordj.ch);            strcpy(wordj.ch,tem);&

25、#160;               printf("这%d个单词按照字典排序输出为:n",k);     for(i=0;i<k;i+)/ 输出               printf("%sn&q

26、uot;,wordi.ch);     【实例测设及运行结果】 【心得体会】 字典序排序实际上就是比较字符串的ASCII码值。如果比较结果大于0,则交换顺序。课程设计报告最小生成树专业:_软件工程_ 班级:_1308班_ 姓名:_朱瑞春_ 学号:_ 2013005493 _ 完成日期:_6.27_【问题描述】给定一个地区的n个城市间的距离网,用Prim算法或Kruskal算法建立最小生成树,并计算得到的最小生成树的代价。【设计需求及分析】1、城市间的距离网采用邻接矩阵表示,邻接矩阵的存储结构定义采用课本中给出的定义,若两个城市之间不存在道路,则

27、将相应边的权值设为自己定义的无穷大值。2、要求在屏幕上显示得到的最小生成树中包括了哪些城市间的道路,并显示得到的最小生成树的代价。3、表示城市间距离网的邻接矩阵(要求至少6个城市,10条边)。【设计功能的实现】#include<stdio.h>#include<stdlib.h>#define TURE 999typedef struct ArcNode char vexs10; int edgs1010; int n,e;mgraph;struct edg int v1; int v2; int cost; a10,b10;/定义结构体void greatemgrap

28、h(mgraph *G) int i,j,k,weight,m,n; int ch1,ch2; char a,b; printf("请输入顶点数和边数:"); scanf("%d %d",&(G->n),&(G->e); for(i=0;i<G->n;i+) getchar(); printf("请输入第%d个顶点:",i+1); scanf("%c",&(G->vexsi); for(i=0;i<G->n;i+) for(j=0;j<G-&g

29、t;n;j+) G->edgsij=0; for(k=0;k<G->e;k+) printf("请输入第%d条边的顶点权值:",k+1); getchar(); scanf("%c %c %d",&a,&b,&weight); m=0,n=0; for(m=0;G->vexsm!=a;m+);for(n=0;G->vexsn!=b;n+);ch1=m;ch2=n;G->edgsch1ch2=weight;G->edgsch2ch1=weight; void prime(mgraph *G,

30、int v) int i,j,k,min; struct int adjvex; int lowcost; closedge10; for(i=0;i<G->n;i+) closedgei.lowcost=G->edgsvi; closedgei.adjvex=v; closedgev.lowcost=TURE; for(i=1;i<G->n;i+) min=100; for(j=0;j<G->n;j+) if(closedgej.lowcost!=TURE && closedgej.lowcost!=0) if(closedgej.l

31、owcost<min) min =closedgej.lowcost; k=j; printf("%C %c %dn",G->vexsclosedgek.adjvex,G->vexsk, min); closedgek.lowcost=TURE; for(j=0;j<G->n;j+) if(closedgej.lowcost!=TURE) if(G->edgskj<closedgej.lowcost|closedgej.lowcost=0) closedgej.lowcost=G->edgskj; closedgej.adjvex=k; void main() mgraph *G,a;char ch1; G=&a; printf("建立图的领结举证n"); greatemgraph(G); getchar(); ch1=1; printf("n"); printf("最小生成树 "); printf("prime输出为:n"); prime(G,0); system("pause"); 【实例测设及运行结果】【心得体会】在实验中我们我们学到了如何建设最小生成树,并计算得到的最小生成树的代价。;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1