【2017年整理】综合实验报告格式

上传人:爱****1 文档编号:945928 上传时间:2017-05-23 格式:DOC 页数:7 大小:84KB
返回 下载 相关 举报
【2017年整理】综合实验报告格式_第1页
第1页 / 共7页
【2017年整理】综合实验报告格式_第2页
第2页 / 共7页
【2017年整理】综合实验报告格式_第3页
第3页 / 共7页
【2017年整理】综合实验报告格式_第4页
第4页 / 共7页
【2017年整理】综合实验报告格式_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《【2017年整理】综合实验报告格式》由会员分享,可在线阅读,更多相关《【2017年整理】综合实验报告格式(7页珍藏版)》请在金锄头文库上搜索。

1、综合性实验实 验 报 告 课程名称 面向对象的程序设计 C+ 实验学期 至 学年 第 学期学生所在系部 年级 专业班级 学生姓名 学号 任课教师 实验成绩 计算机系制华北科技学院计算机系综合性实验报告第 1 页1、 面向对象程序设计 C+课程综合性实验报告开课实验室:基础五 2011 年 12 月 20 日实验题目 复数类的设计一、实验目的掌握类的概念及构造方法;掌握构造函数的定义与使用;掌握友元的定义与使用;掌握运算符的重载定义与使用。二、设备与环境微型计算机、Windows 系列操作系统 、Visual C+6.0 软件三、实验内容设计复数类,重载+,-,*,/,等运算符。编程设计实现下列

2、函数:MyComplex();MyComplex(int a);MyComplex(int a,int b) ;MyComplex(const MyComplex& v) ;Mycomplex& operator=(const Mycomplex& rhs);Mycomplex& operator+=(const Mycomplex& rhs);Mycomplex& operator-=(const Mycomplex& rhs);Mycomplex& operator*=(const Mycomplex& rhs);Mycomplex& operator/=(const Mycomplex&

3、 rhs);friend MyComplex operator+(MyComplex m,MyComplex n) ;friend MyComplex operator-(MyComplex m,MyComplex n) ;friend MyComplex operator*(MyComplex m,MyComplex n) ;friend MyComplex operator/(MyComplex m,MyComplex n) ;friend ostream& operator(istream& s,MyComplex& t); 四、实验结果及分析1、题目分析及设计思路该题目利用 c+编程实

4、现运算符重载。在设计这个程序时,首先构造一个 MyComplex 的类,在这个类里面,构造成员函数和友元函数,对重载运算符的定义,然后对各个重载函数在类体外对函数进行定义和声明,最后有一个主函数运行这些重载函数实现运算符的重载,这就是整个程序的设计思路。华北科技学院计算机系综合性实验报告第 2 页2、实验结果及分析3、复数类功能及主要代码分析建立一个运算符重载的类:class mycomplexpublic:mycomplex()real=0;imag=0;mycomplex(double r,double i)real=r;imag=i;mycomplex& operator+=(const

5、 mycomplex &rhs);mycomplex& operator-=(const mycomplex &rhs);mycomplex& operator*=(const mycomplex &rhs);mycomplex& operator/=(const mycomplex &rhs);friend mycomplex operator+(mycomplex&c1,mycomplex&c2);friend mycomplex operator-(mycomplex&c1,mycomplex&c2);friend mycomplex operator*(mycomplex&c1,myc

6、omplex&c2);friend mycomplex operator/(mycomplex&c1,mycomplex&c2);friend ostream& operator(istream& ,mycomplex&); void display();华北科技学院计算机系综合性实验报告第 3 页private:double real;double imag;建立一个类是对类中的函数进行定义和变量进行赋初值。运算符+的重载:mycomplex operator+(mycomplex&c1,mycomplex&c2)/定义运算符+重载函数return mycomplex(c1.real+c2.

7、real,c1.imag+c2.imag);/定义重载函数的函数体运算符-的重载:mycomplex operator-(mycomplex&c1,mycomplex&c2)return mycomplex(c1.real-c2.real,c1.imag-c2.imag);运算符*的重载:mycomplex operator*(mycomplex&c1,mycomplex&c2)return mycomplex(c1.real*c2.real,c1.imag*c2.imag);运算符/的重载:mycomplex operator/(mycomplex&c1,mycomplex&c2)retur

8、n mycomplex(c1.real/c2.real,c1.imag/c2.imag);运算符的重载:istream& operator(istream& input,mycomplex&c)coutc.realc.imag;return input;运算符+=的重载:华北科技学院计算机系综合性实验报告第 4 页mycomplex& mycomplex:operator +=(const mycomplex &rhs) real+= rhs.real; imag+=rhs.imag;return *this; 运算符-=的重载:mycomplex& mycomplex:operator -=

9、(const mycomplex &rhs) real-= rhs.real; imag-=rhs.imag;return *this; 运算符*=的重载:mycomplex& mycomplex:operator *=(const mycomplex &rhs) real*= rhs.real; imag*=rhs.imag;return *this; 运算符/=的重载:mycomplex& mycomplex:operator /=(const mycomplex &rhs) real/= rhs.real; imag/=rhs.imag;return *this; 主函数:int mai

10、n()mycomplex c1,c2,c3,c4,c5,c6,b,b1,b2,b3,b4;/定义变量cinc1c2b;/输入变量的值coutc1=c1endl;coutc2=c2endl;华北科技学院计算机系综合性实验报告第 5 页coutb=bendl;c3=c1+c2;/运行重载函数c4=c1-c2;c5=c1*c2;c6=c1/c2;b1=b;b1+=c1;coutb1+=c1:;b1.display ();b2=b;b2-=c1;coutb2-=c1:;b2.display ();b3=b;b3*=c1;coutb3*=c1:;b3.display ();b4=b;b4/=c1;cou

11、tb4/=c1:;b4.display ();coutc1=;c1.display ();coutc2=;c2.display ();coutc1+c2=;c3.display ();coutc1-c2=;c4.display ();华北科技学院计算机系综合性实验报告第 6 页coutc1*c2=;c5.display ();coutc1/c2=;c6.display ();return 0;4、实验心得及体会评定项目 A B C D 评定项目 A B C D算法正确 界面美观,布局合理程序结构合理 操作熟练语法、语义正确 解析完整实验结果正确 文字流畅报告规范 题解正确教 师 评 价其他:评价教师签名:2011 年 12 月 28 日

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 研究报告 > 综合/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号