EssayGhost Assignment代写,Essay代写,网课代修,Quiz代考

EssayGhost-Essay代写,作业代写,网课代修代上,cs代写代考

一站式网课代修,论文代写

高质量的Assignment代写、Paper代写、Report代写服务

EG1hao
网课代修代上,cs代写代考
C/C++代写
您的位置: 主页 > 编程案例 > C/C++代写 >
代写C++/C:实验项目题目:十个项目题目整合 - C++代写
发布时间:2021-07-25 15:51:43浏览次数:
1.进一步了解运算符重载的概念和使用方法。2.掌握几种常用的运算符重载的方法。3.了解转换构造函数的使用方法。二、实验主要内容1.理解下面的程序并运行查看结果,回答程序后面的问题。#include iostream usingnamespacestd;classCComplex{public:CComplex(){real=0;imag=0;}CComplex(intx,inty){ real=x;imag=y;}intreal;intimag;CComplexoperator+(CComplexobj1) -(1) {CComplexobj2(real+obj1.real,imag+obj1.imag);returnobj2;}};intmain(){CComplexobj1(100,30);CComplexobj2(20,30);CComplexobj; obj=obj1+obj2; (2)cout obj.real endl;cout obj.imag endl;return 0;}问题一:(1)处的运算符重载,为什么该函数的返回值要设计成CComplex类型? 问题二:(2)处的运算符重载函数调用就相当于“obj=operator+(obj1,obj2);”,但是为什么CComplex类中的运算符重载函数只设计了一个参数?2.理解下面的程序并运行查看结果,回答程序后面的问题。#include iostream usingnamespacestd;classCComplex{public:CComplex(){real=0.0;imag=0.0;}CComplex(floatx,floaty){real=x;imag=y;}CComplexoperator+(CComplex obj1,CComplex obj2){CComplexobj3(obj1.real+obj2.real,obj1.imag+obj2.imag);returnobj3;}CComplex operator++(CComplex obj){obj.real+=1;obj.imag+=1;returnobj;}void print() { cout real + imag i endl; } private: float real; float imag; }; CComplex operator (CComplex x) { x.real -= 1; x.imag -= 1; return x; } int main() { CComplex obj1(2.1,3.2); CComplex obj2(3.6,2.5); cout obj1= obj1.print(); cout obj2= obj2.print(); CComplex obj3 = obj1 + obj2; cout befor++, obj3= obj3.print(); ++obj3; cout after++, obj3= obj3.print(); obj3; cout after , obj3= obj3.print(); CComplex obj4 = ++obj3; cout obj4= obj4.print(); } 问题:以上程序中的三个运算符重载都有错误,试改正过来,并分析该程序的输出结果。三、实验步骤

所有的编程代写范围:essayghost为美国、加拿大、英国、澳洲的留学生提供C语言代写、代写C语言、C语言代做、代做C语言、数据库代写、代写数据库、数据库代做、代做数据库、Web作业代写、代写Web作业、Web作业代做、代做Web作业、Java代写、代写Java、Java代做、代做Java、Python代写、代写Python、Python代做、代做Python、C/C++代写、代写C/C++、C/C++代做、代做C/C++、数据结构代写、代写数据结构、数据结构代做、代做数据结构等留学生编程作业代写服务。