文档详情

测绘2008级《测绘程序设计基础(VC.net)》考试说明.pdf

发布:2017-07-24约2.39千字共2页下载文档
文本预览下载声明
时间 120 分钟 考试形式: 闭 卷 考试范围:除实验 6 的全部实验内容以及课堂上的主要示例 题型介绍: 一、读程序(本题 30 分,每小题 5 分) 示例: 写出下列 CMatrix 类成员函数的功能及参数说明,并添加注释。 CMatrix operator + (const CMatrix m1,const CMatrix m2) { if((m1.Col()!=m2.Col()) ||(m1.Row()!=m2.Row()) )//注释① { throw( CMatrix::operator+: The two matrix have different size!); } CMatrix matTmp(m1.Row(),m1.Col());//注释② //////////////////////////////////////////////////// /* 写出下列代码段得注释③ */ for(int i=0;im1.Row();i++) { for(int j=0;jm1.Col();j++) { matTmp(i,j)=m1(i,j)+m2(i,j); } } /////////////////////////////////////////////////// return matTmp; } 说明:CMatrix为矩阵类,其头文件定义如下: class CMatrix { public: CMatrix(int row=3,int col=3); CMatrix (const CMatrix m); // copy constructor ~CMatrix(void); private: double **dMatData;//保存矩阵元素数据的二维数组 int iRow;//矩阵的行 int iCol;//矩阵的列 public: int Row() const {return iRow;}//返回行 int Col() const {return iCol;}//返回列 1 double operator () (int row, int col);//获取矩阵元素 double operator () (int row, int col) const; CMatrix operator = (const CMatrix m) ; friend CMatrix operator + (const CMatrix m1,const CMatrix m2); friend CMatrix operator - (const CMatrix m1,const CMatrix m2); friend CMatrix operator * (const CMatrix m1,const CMatrix m2); friend CMatrix operator ~ (const CMatrix m); CMatrix Inv(); }; 参考答案: 功能:通过重载+符号函数,求两个矩阵的和 输入参数:m1,m2 为要求和的两个矩阵 注释:①判断 m1 与 m2 的大小是否相等,如果不相等则抛出异常,不求和 ②根据 m1 矩阵的大小定义一矩阵类变量,用于保存矩阵的和 ③通过二重循环把 m1 与 m2 矩阵的对应元素相加并保存在 matTmp 矩阵中 二、写程序(本题 40 分,每题 10 分)(注意代码的书写规范以及简单注释) 示例: 用 C++编写十进制度向度分秒转换的函数。 //功能:度向度分秒转换 double Dms(const double dDeg) { int iDeg,iMin; double dSec; double dTmp;
显示全部
相似文档