南昌航空大学实验报告7动态链接库的制作与调用(多项式矩阵定义).doc_第1页
南昌航空大学实验报告7动态链接库的制作与调用(多项式矩阵定义).doc_第2页
南昌航空大学实验报告7动态链接库的制作与调用(多项式矩阵定义).doc_第3页
南昌航空大学实验报告7动态链接库的制作与调用(多项式矩阵定义).doc_第4页
南昌航空大学实验报告7动态链接库的制作与调用(多项式矩阵定义).doc_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

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

文档简介

南昌航空大学实验报告2011年12月11日课程名称: 面向对象程序设计B 实验名称:动态链接库的制作与调用(多项式矩阵定义)班级:102022 姓名:林书晨 指导老师评定: 签名:1. 实验目的综合运用所学面向对象编程知识完成动态链接库文件的创建,调用,理解动态链接库的工作原理,议会声明和定义封开方法在程序设计中的优势,掌握利用动态链接库实现不同开发平台间混合变成的方法,掌握利用动态链接库实现代码可复用技术,进一步掌握混合开发的方法。2 实验内容 综合运用所学面向对象编程知识定义一个多项式矩阵类并应用该类实现多项式矩阵类的运算。具体实现该矩阵的加法(采用运算符“+”重载).转置(采用运算符“”重载)及输出(采用运算符“重载)操作。将该类制作作为动态链接库。然后在其他工程中对该动态链接库进行调用。以上内容为恋歌学时的内容,同学们重点注意构件顺序与方法以及动态链接库的调用方法,接下来的连年改革学士需要同学们自行设计多项类的设计以及该类动态链接库的设计,并在工程内实现该dll的调用。 Class matrixPublic: Matrix(int a,int b);matrix();Void set();Matrix operator +(matrix &);Matrix operator -(int);_declspec(dllexport) friend ostream &operator (ostream &out,matrix &s);Private: int i,int j;int *m;3 概要设计 Class matrixPublic:Matric(it a,int b);/声明构造函数matrix();/声明析构函数Viod set();/声明自定义的构造函数Matrix oprator +(matrix &);/声明重载”+“运算符的函数Matrix oprator -(int );/声明”-“运算符的函数 _declspec(dllexport) friend ostream &operator (ostream &out,matrix &s);声明友员”“运算符函数Private: Int i,j;/声明数组的大小的变量Int *m;4 详细设计/头文件matrix.h#ifndef Matrix_H#define Matrix_H#ifdef DLL_FILEClass_declspec(dllexport) matrix#elseClass_declspec(dllexport) matrix#end if Public: Matrix(it a,int b);/声明构造函数matrix();/声明析构函数Viod set();/声明自定义的构造函数Matrix operator +(matrix &);/声明重载”+“运算符的函数Matrix operator -(int );/声明”-“运算符的函数 _declspec(dllexport) friend ostream &operator (ostream &out,matrix &s);声明友员”“运算符函数Private: Int i,j;/声明数组的大小的变量Int *m;#end if /matrix.cpp#ifdef DLL_FILE#define DLL_FILE#end if #include#includeMatrix:matrix(it a,int b)/定义构造函数i=a;J=b;M =new inti*j;For (int k=0;ki;k+) For(int l=0;ij;l+) Mk*j+l;Matrix:matrix(VIOD)/定义析构函数 DELETEM;Void matrix:set()/定义自定义的构造函数ContPlease input the data of Matrixendl;For (int k+0;ki;k+)For(int l=0;lmk*j+l;Matrix matrix:operator -(matrix &s)/定义重载“+”运算符的函数 matrix n()s.i,s.j); For(int k=0;ki;k+) For (int l=0;lj;l+) N.mk*j+l=mk*j+l+s.mk*j+l;Return 0;Matrix matrix:operator -(int a)/定义“-“运算符的函数 Matrix n(i,j); For(int k=0;ki;k+) For (int l=0;lj;l+) N.mk*j+l=ml*j+k;Return n; _declspec(dllexport) friend ostream &operator (ostream &out,matrix &s);定义友员”“运算符函数For (int k=0;ks.i;k+) For (int l=0;lj;l+) outs.mk*(s.j)+l;Outendl;Return out;/MatrixCall.Cpp:Defines the entry point for the console application./MatrixCall.Cpp:Defines the entry point for the application./MatrixCall:Defines the entry point for the application.#include#include#include.matrix.h#pragma comment(lib,matrixDL.lib);Int main(int argc, char* argv)Int a,b;Cout请输入矩阵的大小: M1a,bab;/ 定义确定叔祖大小的变量 Matirx Mat1(a,b); /声明一个 matrix 对象CoutMAt1a,b;Ma1.set();/ 调用自定义函数Matrix Mat2(a,b); Cout:Mat2a,b;Mat2.set();Martix Mat3(a,b);Mat3=Mat1+Mat2;/调用重载运算符 +CoutMat3=Mat1+Mat2endl;Mat3=;CoutMat3endl;Return 0;5 程序调试6 实验总结 编写程序的时候不要将程序的多个执行功能防在同一个函数里面,要将程序细分,不同的函数执行不同的给功能7 附录#ifndef Matrix_H#define Matrix_H#ifdef DLL_FILEClass_declspec(dllexport) matrix#elseClass_declspec(dllexport) matrix#end if Public: Matrix(it a,int b);matrix();Viod set();Matrix operator +(matrix &);Matrix operator -(int ); _declspec(dllexport) friend ostream &operator (ostream &out,matrix &s);Private: Int i,j;Int *m;#end if /matrix.cpp#ifdef DLL_FILE#define DLL_FILE#end if #include#includeMatrix:matrix(it a,int b)i=a;J=b;M =new inti*j;For (int k=0;ki;k+) For(int l=0;ij;l+) Mk*j+l;Matrix:matrix(VIOD) DELETEM;Void matrix:set()ContPlease input the data of Matrixendl;For (int k+0;ki;k+)For(int l=0;lmk*j+l;Matrix matrix:operator -(matrix &s) matrix n()s.i,s.j); For(int k=0;ki;k+) For (int l=0;lj;l+) N.mk*j+l=mk*j+l+s.mk*j+l;Return 0;Matrix matrix:operator -(int a) Matrix n(i,j); For(int k=0;ki;k+) For (int l=0;lj;l+) N.mk*j+l=ml*j+k;Return n; _declspec(dllexport) friend ostream &operator (ostream &out,matrix &s);For (int k=0;ks.i;k+) For (int l=0;lj;l+) outs.mk*(s.j)+l;Outendl;Return out;/MatrixCall.Cpp:Defines the entry point for the console application./MatrixCall.Cpp:Defines the entry point for the application./MatrixCall:Defines the entry point for the application.#include#include#include.matrix.h#pragma comment(lib,matrixDL.lib);Int main(int argc, c

温馨提示

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

评论

0/150

提交评论