武汉大学遥感院复试上机练习(节选).doc_第1页
武汉大学遥感院复试上机练习(节选).doc_第2页
武汉大学遥感院复试上机练习(节选).doc_第3页
武汉大学遥感院复试上机练习(节选).doc_第4页
武汉大学遥感院复试上机练习(节选).doc_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

精品文档现有一数组,其元素值见文件test.txt,要求通过编程的方法求出这组数中值最大的元素、值最小的元素和中值元素。结果通过编程的方法写入文本文件中输出。#include#includeusing namespace std;int main()int num;ifstream filein(C:UsersywDesktop机试复习2004testtest.txt);if (!filein)cout num;int *data = new intnum;for (int i = 0; i datai; filein.close();int swap;for (int i = 0; i num-1;i+)for (int j = i + 1; j dataj)swap = datai;datai = dataj;dataj = swap;else continue;/冒泡法排序ofstream fileout(C:UsersywDesktop机试复习2004testtest2.txt);if (!fileout)cout cannot open the file!;return 0;fileout max: datanum-1 endl;fileout min: data0 endl;fileout medium: datanum/2 endl;fileout.close();deletedata,data=NULL;return 1;编写调试程序从磁盘的数据文件“SourceData.txt”中读入10000个数据,先理解为12580的矩阵,使用卷积矩阵1进行卷积,再理解为100100的矩阵,使用卷积矩阵2进行卷积。卷积矩阵1 卷积矩阵2#include#includeusing namespace std;int main()int *data = new int10000;ifstream filein(C:UsersywDesktop机试复习2005testSourceData.txt);if (!filein)cout cannot open the file!;return 0;for (int i = 0; i datai;filein.close();int Mat133 = 0, -1, 0, -1, 5, -1, 0, -1, 0 ;int Mat255 = 0, 0, -1, 0, 0, 0, -1, -2, -1, 0, -1, -2, 16, -2, -1, 0, -1, -2, -1, 0, 0, 0, -1, 0, 0 ;int Matrix112580, MatrixNew112580 = 0 ;int Matrix2100100, MatrixNew2100100 = 0 ;int k = 0;for (int i = 0; i 125; i+)for (int j = 0; j 80; j+)Matrix1ij = datak;k+;k = 0;for (int i = 0; i 100; i+)for (int j = 0; j 100; j+)Matrix2ij = datak;k+; for (int i = 1; i 124; i+)for (int j = 1; j 79; j+)for (int m = -1; m = 1; m+)for (int n = -1; n = 1; n+)MatrixNew1ij += Matrix1i + mj + n * Mat1m + 1n + 1;for (int i = 2; i 99; i+)for (int j = 2; j 99; j+)for (int m = -2; m = 2; m+)for (int n = -2; n = 2; n+)MatrixNew2ij += Matrix2i + mj + n * Mat2m + 2n + 2;ofstream fileout(C:UsersywDesktop机试复习2005testtest2.txt);if (!fileout)cout cannot open the file!;return 0;for (int i = 1; i 124; i+)for (int j = 1; j 79; j+)fileout MatrixNew1ij ;fileout endl;fileout.close();deletedata,data=NULL;return 1;(1)利用随机函数rand()生成(0,1)区间的100个均匀分布随机数;提示:首先利用“srand(unsigned)time(NULL) ”语句设置产生随机数的开始点(需要包含time.h头文件);产生随机数的函数为rand(),为了将该随机数转换为(0,1)范围内的数,利用“rand()*1.0/RAND_MAX”可实现此目的。(2)利用正态分布随机数的产生函数生成正态分布随机数。正态分布随机数生成函数如下:*0.3+1(3)计算出100个正态分布随机数y的均值和方差,计算公式如下: /n , -其中,自变量x即为100个均匀分布的随机数。#include#include#include#include#define PI 3.1415926using namespace std;int main()double*data = new double100;srand(unsigned)time(NULL);for (int i = 0; i 100; i+)datai = rand()*1.0 / RAND_MAX;double*data2 = new double100;for (int i = 0; i 100; i+)data2i = 1 + 0.3*cos(2 * PI*datai)*sqrt(-2 * log(datai);double average = 0, variance = 0;for (int i = 0; i 100; i+)average += datai;variance += datai * datai;average /= 100;variance = variance/100 - average*average;/输出略deletedata, data = NULL;deletedata2, data2 = NULL;return 1;题目:已知某多光谱遥感影像一个样区的数据。分别计算该样区数据的均值向量和协方差矩阵。计算公式如下:1)均值向量:2) 协方差矩阵:式中: 表示第i个波段样区的第k个像元值,N为样区像元总个数。multispectral.h中:#include#includeusing namespace std;/=/计算多光谱影像每个波段的均值/average:输出每个波段的均值/num:每个波段的像元总数/band:每个波段的波段数/data:多光谱影像的像素值/=void Average(double *average, int num, int band, vector *data);/=/说明略/=void Matrix(vector *matrix, double *average, vector *data, int band, int num);Multispectral.cpp中:#includemultispectral.hvoid Average(double *average, int num, int band, vector *data)for (int i = 0; i band; i+)averagei = 0;for (int i = 0; i num; i+)for (int j = 0; j band; j+)averagej += (double)dataji / num;void Matrix(vector *matrix, double *average, vector *data,int band,int num)for (int i = 0; i band; i+)for (int j = 0; j band; j+)matrixi.push_back(0);for (int i = 0; i band; i+)for (int j = 0; j band; j+)for (int k = 0; k num; k+)matrixij += (double)dataik - averagei)*(double)datajk - averagej) / num;主函数中:#include#include#include#includemultispectral.husing namespace std;int main()int band, num;ifstream filein(C:UsersywDesktop机试复习2006data.txt);/判断略filein band;filein num;vector *data=new vectorband;int count;for (int i = 0; i band; i+)for (int j = 0; j count;datai.push_back(count);filein.close();double *average = new doubleband;vector *matrix = new vectornum;Average(average, num, band, data);Matrix(matrix, average, data, band, num);deletedata, data = NULL;deletematrix, matrix = NULL;deleteaverage, average = NULL;/输出略return 1;多边形外包矩形外包矩形的概念如下图所示:(点落在内部和边缘上)用编制的程序判断哪些点落在矩形外包内部,输出落在外包内的点号。#include#include#includeusing namespace std;struct POINTdouble x;double y;POINT() memset(this, 0, sizeof(POINT); ;int main()int num;ifstream filein(C:UsersywDesktop机试复习2007test.txt);if (!filein)cout num;vector data;POINT point;for (int i = 0; i point.x;filein point.y;data.push_back(point);filein.close();double xmax = data0.x, xmin = data0.x, ymax = data0.y, ymin = data0.y;for (int i = 1; i xmax)xmax = datai.x;if (datai.xymax)ymax = datai.y;if (datai.yymin)ymin = datai.y;cout 内部点有:;for (int i = 0; i num; i+)if (datai.x != xmax&datai.x != xmin&datai.y != ymax&datai.y != ymin)cout i + 1 ;cout endl;return 1;程序改:(将判断点放在文件中,以点名(字符),x,y方式储存)struct POINTJudgedouble x;double y;char name10;POINTJudge()x = 0.0;y = 0.0;ifstream filein2(C:UsersywDesktop机试复习2007外包矩形欲判断点.dat);if (!filein2)cout cannot open the file!;return 0;vector record;while(!filein2.eof()POINTJudge jugde;filein2 jugde.xjugde.y;if (jugde.x xmin&jugde.y ymin)record.push_back(jugde);filein2.close();cout 内部点有:;for (int i = 0; i record.size(); i+)cout recordi.x recordi.y endl ;cout endl;题目:编程统计某专业的一门课程考试成绩的最高分、最低分、平均分以及考试成绩分布的均方差。说明:均方差计算公式如下:X:考试成绩;N:成绩总个数#include#include#includeusing namespace std;int main()int num = 0;double max = 0, min = 100, sum1 = 0, sum2 = 0;ifstream filein(C:UsersywDesktop新建文件夹2008年score.txt);if (!filein)cout num;double *data = new doublenum;for (int i = 0; i datai;if (dataimax)max = datai;if (datai min)min = datai;sum1 += datai;sum2 += datai * datai;filein.close();double average = 0.0, jun = 0.0;average = (double)sum1 / num;jun = sqrt(double)sum2 / num - average*average);ofstream fp2(C:UsersywDesktop机试复习2008result.txt);if (!fp2)cout cannot open the file!;return 0;fp2 最高分为 max endl 最低分为 min endl;fp2 平均分为 average endl 均方差为 jun endl;fp2.close();deletedata,data=NULL;return 1;试题:文件test.txt中存贮了一串字符串,请统计该文件中各字母出现的次数(字母的大小写不加区分,如a与A算同一字母,标点符号不统计),并按出现次数的多少由高到低进行排列输出,最后将字母及出现次数的排列写入result.txt文件中。#include#include#includeusing namespace std;struct alpint num;char d;alp() memset(this, 0, sizeof(alp); ;int main()ifstream fp(C:UsersywDesktop机试复习2009source.txt);char data3000;/char *data =new char3000;int al26 = 0 ;int w = 0;while (!fp.eof()dataw = fp.get();w+;fp.close();for (int j = 0; j = 0 & dataj - 65 = 0 & dataj - 97 = 25)aldataj - 97+;vector alph;alp me, ma;for (int o = 0; o 26; o+)me.d = A + o;me.num = alo;alph.push_back(me);for (int i = 0; i 25; i+)for (int j = i + 1; j alphj.num)ma = alphi;alphi = alphj;alphj = ma;for (int o = 0; o 26; o+)cout alpho.d alpho.num endl;/delete data,data=NULL;输出略return 1;题目:猫让10只老鼠站成一圈,它决定每数到第n只老鼠就吃掉,请输出最后剩下的老鼠的位置#include #include void main()int i, j, id;int num, l;printf(请输入老鼠的个数:n);scanf(%d, &num);printf(请输入间隔(范围:大于0且小于老鼠个数):n);scanf(%d, &l);int *p;p = (int *)malloc(sizeof(int)*num);for (i = 0; inum - 1; i+)pi = i + 1;pi = 0;for (i = 0, id

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论