测绘软件实习报告(共26页).doc
精选优质文档-倾情为你奉上测 绘 软 件 设 计 与 实 现2011年11月15日目录实验一 图的创建、遍历及其MST的构建一、实验目的通过上机实践,进一步了解图的创建、遍历及其MST的构建,巩固所学课本知识。二、实验过程专心-专注-专业#include<stdio.h>#include<iostream.h>#include<malloc.h>#define INF 32767#define MAXV 100typedef int InfoType;typedef structint no;InfoType info;VertexType;typedef structint edgesMAXVMAXV;int n,e;VertexType vexsMAXV;MGraph;typedef struct ANodeint adjvex;struct ANode *nextarc;InfoType info;ArcNode;typedef int Vertex;typedef struct VnodeVertex data;ArcNode *firstarc;VNode;typedef VNode AdjListMAXV;typedef struct AdjList adjlist; int n,e;ALGraph;void MatToList(MGraph g,ALGraph *&G)int i,j,n=g.n;ArcNode *p;G=(ALGraph *)malloc(sizeof(ALGraph);for(i=0;i<n;i+)G->adjlisti.firstarc=NULL;for(i=0;i<n;i+)for(j=n-1;j>=0;j-)if(g.edgesij!=0)p=(ArcNode *)malloc(sizeof(ArcNode);p->adjvex=j;p->info=g.edgesij;p->nextarc=G->adjlisti.firstarc;G->adjlisti.firstarc=p;G->n=n;G->e=g.e;void ListToMat(ALGraph *G,MGraph &g)int i,j,n=G->n;ArcNode *p;for(i=0;i<n;i+)for(j=0;j<n;j+)g.edgesij=0;for(i=0;i<n;i+)p=G->adjlisti.firstarc;while(p!=NULL)g.edgesip->adjvex=p->info;p=p->nextarc;g.n=n;g.e=G->e;void DispMat(MGraph g)int i,j;int zz=99;for(i=0;i<g.n;i+)for(j=0;j<g.n;j+)if(g.edgesij=INF)printf("%3s"," ");elseprintf("%3d",g.edgesij);printf("n");void DispAdj(ALGraph *G)int i;ArcNode *p;for(i=0;i<G->n;i+)p=G->adjlisti.firstarc;if(p!=NULL)printf("%3d",i);while(p!=NULL)printf("%3d",p->adjvex);p=p->nextarc;printf("n");int visitedMAXV;void DFS(ALGraph *G,int v)ArcNode *p;visitedv=1;printf("%3d",v);p=G->adjlistv.firstarc;while(p!=NULL)if(visitedp->adjvex=0)DFS(G,p->adjvex);p=p->nextarc;void DFS1(ALGraph *G,int v) ArcNode *p;ArcNode *StMAXV;int top=-1,w,i;for(i=0;i<G->n;i+)visitedi=0;printf("%3d",v);visitedv=1;top+;Sttop=G->adjlistv.firstarc;while(top>-1)p=Sttop;top-;while(p!=NULL)w=p->adjvex;if(visitedw=0)printf("%3d",w);visitedw=1;top+;Sttop=G->adjlistw.firstarc;break;p=p->nextarc;printf("n");void BFS(ALGraph *G,int v)ArcNode *p;int queueMAXV,front=0,rear=0;int visitedMAXV;int w,i;for(i=0;i<G->n;i+)visitedi=0;printf("%3d",v);visitedv=1;rear=(rear+1)%MAXV;queuerear=v;while(front!=rear)front=(front+1)%MAXV;w=queuefront;p=G->adjlistw.firstarc;while(p!=NULL)if(visitedp->adjvex=0)printf("%3d",p->adjvex);visitedp->adjvex=1;rear=(rear+1)%MAXV;queuerear=p->adjvex;p=p->nextarc;printf("n");void Prim(MGraph g,int v)int lowcostMAXV,min,n=g.n;int closestMAXV,i,j,k;for(i=0;i<n;i+)lowcosti=g.edgesvi;closesti=v; for(i=0;i<n-1;i+)min=INF;for(j=0;j<n;j+)if(lowcostj!=0&&lowcostj<min)min=lowcostj;k=j;printf("边(%d,%d)权为:%dn",closestk,k,min);lowcostk=0;for(j=0;j<n;j+)if(g.edgeskj!=0&&g.edgeskj<lowcostj)lowcostj=g.edgeskj;closestj=k;/typedef structint u;int v;int w;Edge;void SortEdge(MGraph g,Edge E)int i,j,k=0;Edge temp;for(i=0;i<g.n;i+)for(j=0;j<g.n;j+)if(g.edgesij<INF)Ek.u=i;Ek.v=j;Ek.w=g.edgesij;k+;for(i=0;i<k;i+)temp=Ei;j=i-1;while(j>=0&&temp.w<Ej.w)Ej+1=Ej;j-;E+1=temp;void Kruskal(Edge E,int n,int e)int i,j,m1,m2,sn1,sn2,k;int vsetMAXV;for(i=0;i<n;i+)vseti=i;k=1;j=0;while(k<n)m1=Ej.u;m2=Ej.v;sn1=vsetm1;sn2=vsetm2;if(sn1!=sn2)printf("(%d,%d):%dn",m1,m2,Ej.w);k+;for(i=0;i<n;i+)if(vseti=sn2)vseti=sn1;j+;/void main()int i,j,u=3;MGraph g,g1;ALGraph *G;Edge EMAXV; int BMAXV11;int AMAXV6=0,5,0,7,0,0,0,0,4,0,0,0,8,0,0,0,0,9,0,0,5,0,0,6,0,0,0,5,0,0,3,0,0,0,1,0;g.n=6;g.e=10;for(i=0;i<g.n;i+)for(j=0;j<g.n;j+)g.edgesij=Aij;printf("n");printf("图G的邻接表:n");MatToList(g,G);DispAdj(G);printf("图G的邻接表转换成邻接矩阵n");ListToMat(G,g1);DispMat(g1);printf("从顶点0开始的DFS(递归算法) :n");DFS(G,0);printf("n"); printf("从顶点0开始的DFS(非递归算法) :n");DFS1(G,0);printf("从顶点0开始的BFS(递归算法) :n");BFS(G,0);printf("n"); for(i=0;i<g.n;i+)for(j=0;j<g.n;j+)Bij=INF;B01=1; B02=4; B03=12; B05=2; B12=8; B23=5; B25=9; B34=3; B45=7; for(i=0;i<g.n;i+)for(j=0;j<g.n;j+)Aji=Aij;for(i=0;i<g.n;i+)for(j=0;j<g.n;j+)g.edgesij=Bij;printf("n"); printf("n"); printf("普里姆算法求解结果:n"); Prim(g,0); printf("n"); SortEdge(g,E);printf("n");printf("n");printf("克鲁斯卡尔算法求解结果:n"); Kruskal(E,g.n,g.e); printf("n");三、实验成果四、实验体会通过此次上机实践,基本上掌握了图的创建过程,对于程序设计,在设计过程中遇到很多问题,但是通过相互讨论及老师指导,已经基本掌握了基于深度优先的图的遍历算法的设计与实现、基于广度优先的图的遍历算法的设计与实现、基于Prim算法的最小生成树的构建、基于Kruskal算法的最小生成树的构建。实验二 快速排序算法的实现一、实验目的通过上机实践巩固课堂所学快速排序算法相关知识,通过讨论,同学之间相互学习,彻底了解实验内容,完成实验作业。二、实验过程#include<iostream.h>void XXXquicksort(int data,int low,int high)int i,pivot,j;if(low<high)pivot=datalow;i=low;j=high;while(i<j)while(i<j&&dataj>=pivot)j-;if(i<j)datai+=dataj;while(i<j&&datai<=pivot)i+;if(i<j)dataj-=datai;datai=pivot;XXXquicksort(data,low,i-1);XXXquicksort(data,i+1,high);void main()int a6;int i; cout<<"请输入待排序数组"<<endl;for(i=0;i<6;i+)cin>>ai; cout<<endl;cout<<"由输入得结果为:"<<endl; for( i=0;i<6;i+)cout<<ai<<" " cout<<endl;XXXquicksort(a,0,5);cout<<"快速排序后的结果为:"<<endl; for( i=0;i<6;i+)cout<<ai<<" " cout<<endl;三、实验成果四、实验体会此次上机实践主要是实现快速排序算法,这个实验相对于其他实验,比较简单,做起来问题不是很多,经过几次调试,基本上就能完成。实验三 矩阵类的设计与实现一、实验目的通过上机实践,巩固课堂老师所讲关于矩阵设计的知识,通过反复的调试,找错,设计出矩阵。二、实验过程#include<iostream.h>#include<stdlib.h>#include<math.h>#include<stdio.h>class XXXMatrixprivate:int rows,columns;double *element;public:XXXMatrix(int rows=4,int columns=4);XXXMatrix(int *mat,int rows,int columns); XXXMatrix(const XXXMatrix& m); XXXMatrix(); int rintv(int n,double a4); XXXMatrix& inverse(XXXMatrix& mat); XXXMatrix& transpose(double a4); void init(int rows,int columns);double get(int i,int j);bool set(int i,int j,int value);friend ostream& operator <<(ostream& out,XXXMatrix &mat);XXXMatrix& operator +=(XXXMatrix& mat); XXXMatrix& operator=(const XXXMatrix& mat); bool operator=(const XXXMatrix& mat); bool operator!=(const XXXMatrix& mat); XXXMatrix& operator-(XXXMatrix& mat); XXXMatrix& operator-(); XXXMatrix& operator*(XXXMatrix& mat);void XXXMatrix:init(int rows,int columns)if(rows<=0|columns<=0)throw"矩阵行或列数非正数异常"this->rows=rows;this->columns=columns;element=new double *rows;for(int i=0;i<rows;i+)elementi=new doublecolumns;for(int j=0;j<columns;j+)elementij=0;XXXMatrix:XXXMatrix(int rows,int columns)init(rows,columns);XXXMatrix:XXXMatrix(int *mat,int rows,int columns)init(rows,columns);for(int i=0;i<rows;i+)for(int j=0;j<columns;j+)elementij=*(mat+i*columns+j);XXXMatrix:XXXMatrix(const XXXMatrix& m)init(m.rows,m.columns);for(int i=0;i<m.rows;i+)for(int j;j<m.columns;j+)elementij=m.elementij;XXXMatrix:XXXMatrix()for(int i=0;i<rows;i+)delete(elementi);delete(element);double XXXMatrix:get(int i,int j)if(i>=0&&i<rows&&j>=0&&j<columns)return elementij;bool XXXMatrix:set(int i,int j,int value)if(i>=0&&i<rows&&j>=0&&j<columns)elementij=value;return true;return false;ostream& operator<<(ostream& out,XXXMatrix& mat)out<<"矩阵 XXXMatrix("<<mat.rows<<"x"<<mat.columns<<")"<<endl;for(int i=0;i<mat.rows;i+)for(int j=0;j<mat.columns;j+)out<<mat.elementij<<" "out<<"n"return out;XXXMatrix& XXXMatrix: operator=(const XXXMatrix& mat)if(this->rows=mat.rows&&this->columns=mat.columns)for(int i=0;i<mat.rows;i+)for(int j=0;j<mat.columns;j+)elementij=mat.elementij;return *this;throw"两个矩阵阶数不同,不能相加"bool XXXMatrix: operator=(const XXXMatrix& mat)if(this->rows=mat.rows&&this->columns=mat.columns)for(int i=0;i<mat.rows;i+)for(int j=0;j<mat.columns;j+)if(this->elementij!=mat.elementij)break;return false;elsereturn true;bool XXXMatrix: operator!=(const XXXMatrix& mat)if(this->rows=mat.rows&&this->columns=mat.columns)for(int i=0;i<mat.rows;i+)for(int j=0;j<mat.columns;j+)if(this->elementij=mat.elementij)break;return false;elsereturn true;XXXMatrix& XXXMatrix: operator-( XXXMatrix& mat)if(this->rows=mat.rows&&this->columns=mat.columns)for(int i=0;i<mat.rows;i+)for(int j=0;j<mat.columns;j+)elementij-=mat.elementij;return *this;throw"两个矩阵阶数不同,不能相加"XXXMatrix& XXXMatrix:operator-()for(int i=0;i<this->rows;i+)for(int j=0;j<this->columns;j+)this->elementij=-this->elementij;return *this;throw"两个矩阵阶数不同,不能相加"XXXMatrix& XXXMatrix:operator*(XXXMatrix& mat)int i,j,k;double s;for(i=0;i<mat.rows;i+)for(j=0;j<mat.columns;j+)s=0.0;for(k=0;k<mat.columns;k+)s=s+mat.elementik*this->elementkj;this->elementij=s;return *this;XXXMatrix& XXXMatrix:inverse(XXXMatrix& mat)if(this->rows=mat.columns&&this->columns=mat.rows)for(int i=0;i<mat.columns;i+)for(int j=0;j<mat.rows;j+)this->elementij=mat.elementji;return *this;int XXXMatrix:rintv(int n,double a4)int *is,*js,i,j,k,u,v;double p,d;is=(int *) malloc(n*sizeof(int);js=(int *) malloc(n*sizeof(int);for(k=0;k<=n-1;k+)d=0.0;for(i=k;i<=n-1;i+)for(j=k;j<=n-1;j+)p=fabs(aij);if(p>d)d=p;isk=i;jsk=j;if(d+1.0=1.0)free(is);free(js);printf("err*not invn");return(0);if(isk!=k)for(j=0;j<=n-1;j+)p=akj;akj=aiskj;aiskj=p;if(jsk!=k)for(i=0;i<=n-1;i+)u=i*n+k;v=i*n+jsk;p=aik; aik=aijsk; aijsk=p;akk=1.0/akk;for(j=0;j<=n-1;j+)if(j!=k)u=k*n+j;akj=akj*akk;for(i=0;i<=n-1;i+)if(i!=k)for(j=0;j<=n;j+)if(j!=k)aij=aij-aik*akj;for(i=0;i<=n-1;i+)if(i!=k)aik=-aik*akk;for(k=n-1;k>=0;k-)if(jsk!=k)for(j=0;j<=n-1;j+)p=akj;akj=ajskj;ajskj=p;if(isk!=k)for(i=0;i<n-1;i+)p=aik;aik=aiisk;aiisk=p;free(is);free(js);return (1);XXXMatrix& XXXMatrix:transpose(double a4)int q;q=rintv(4,a);for(int i=0;i<this->rows;i+)for(int j=0;j<this->columns;j+)this->elementij=aij;return *this;XXXMatrix& XXXMatrix:operator+=(XXXMatrix& mat)if(this->rows=mat.rows&&this->columns=mat.columns)for(int i=0;i<mat.rows;i+)for(int j=0;j<mat.columns;j+)elementij+=mat.elementij;return *this;throw"两个矩阵阶数不同,不能相加"int main()const int M=3,N=4; static double a44=0.5,0.0,0.0,0.0,0.0,0.5,0.0,0.0,0.0,0.0,0.5,0.0,0.0,0.0,0.0,0.5;cout<<"待求逆矩阵为:"<<endl; for(int i=0;i<=3;i+)for(int j=0;j<=3;j+)cout<<aij<<" "cout<<endl; XXXMatrix B(3,4),C(4,3),D(4,4); D.transpose(a); /求逆 cout<<"求逆后的矩阵为 "<<D;int table1M*N=1,0,0,0,0,1;XXXMatrix mat1(table1,M,N); /矩阵1mat1.set(2,2,1);B=mat1;int table2MN=1,2,3,4,5,6,7,8,9;XXXMatrix mat2(*table2,M,N); /矩阵2cout<<"矩阵P为"<<endl;cout<<mat1;cout<<"和P相等的矩阵Q为"<<endl; /赋值 cout<<B; if(mat1=B)cout<<"两矩阵相等!"<<endl; /相等 -B;cout<<"负的矩阵-Q"<<endl; /求负值cout<<B; cout<<"矩阵R为"<<endl;cout<<mat2; mat1+=mat2; /+= mat2-mat1; mat2-mat1;/相减cout<<"矩阵相加S=P+Rn"<<mat1; cout<<"矩阵相减R-S-Sn"<<mat2;if(mat1!=B)cout<<"两矩阵不再相等!"<<endl; /!=C.inverse(B);cout<<"转置"<<C; /转置return 0;三、实验成果四、实验体会由于矩阵设计的成员函数较多,操作起来不是很容易,在上机过程中遇到很多困难,但是通过老师指导,经过多次调试,终于成功了。实验四 Windows绘图一、实验目的通过上机实践,学会用程序实现Windows绘图。通过一次次探索实践,掌握程序设计的要点。二、实验过程1. 鼠标画图void CMyDrawView:OnLButtonDown(UINT nFlags, CPoint point) / TODO: Add your message handler code here and/or call default/ TODO: Add your message handler code here . . . CClientDC dc(this);OnPrepareDC(&dc); / 调整设备环境的属性dc.DPtoLP(&point); / 将设备坐标转换为逻辑坐标SetCapture(); / 捕捉鼠标/:SetCursor(m_hCross); / 设置十字光标m_ptOrigin=point;m_bDragging=TRUE; / 设置拖拽标记/ CScrollView:OnLButtonDown(nFlags, point);CView:OnLButtonDown(nFlags, point);void CMyDrawView:OnLButtonUp(UINT nFlags, CPoint point) / TODO: Add your message handler code here and/or call defaultm_bDragging = false;ReleaseCapture();