[专业课]综合实验报告格式

上传人:tian****1990 文档编号:73221097 上传时间:2019-01-25 格式:DOC 页数:7 大小:119.18KB
返回 下载 相关 举报
[专业课]综合实验报告格式_第1页
第1页 / 共7页
[专业课]综合实验报告格式_第2页
第2页 / 共7页
[专业课]综合实验报告格式_第3页
第3页 / 共7页
[专业课]综合实验报告格式_第4页
第4页 / 共7页
[专业课]综合实验报告格式_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《[专业课]综合实验报告格式》由会员分享,可在线阅读,更多相关《[专业课]综合实验报告格式(7页珍藏版)》请在金锄头文库上搜索。

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

2、); 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& rhs)

3、; 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、实验结果及分析3、复数类功能及主要代码分析建立一个运算符重载的类:class mycomplexpublic:mycomplex()real=0;imag=0;mycomplex(double r,double i)real=r;imag=i;mycomplex& operator+=(const mycomplex &rhs);mycomple

5、x& 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,mycomplex&c2);friend mycompl

6、ex operator/(mycomplex&c1,mycomplex&c2);friend ostream& operator(istream& ,mycomplex&); void display();private:double real;double imag;建立一个类是对类中的函数进行定义和变量进行赋初值。运算符+的重载:mycomplex operator+(mycomplex&c1,mycomplex&c2)/定义运算符+重载函数return mycomplex(c1.real+c2.real,c1.imag+c2.imag);/定义重载函数的函数体运算符-的重载:mycomp

7、lex 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)return mycomplex(c1.real/c2.real,c1.imag/c2.imag);运算

8、符的重载:ostream& operator(ostream& output,mycomplex &c)output(c.real +c.imag 的重载:istream& operator(istream& input,mycomplex&c)coutc.realc.imag;return input;运算符+=的重载:mycomplex& mycomplex:operator +=(const mycomplex &rhs) real+= rhs.real; imag+=rhs.imag; return *this; 运算符-=的重载:mycomplex& mycomplex:operat

9、or -=(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; 主函数

10、:int main()mycomplex c1,c2,c3,c4,c5,c6,b,b1,b2,b3,b4;/定义变量cinc1c2b;/输入变量的值coutc1=c1endl;coutc2=c2endl;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

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

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

当前位置:首页 > 办公文档 > 其它办公文档

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