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

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

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

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

EG1hao
网课代修代上,cs代写代考
物理代写案例
您的位置: 主页 > 理科代写案例 > 物理代写案例 >
物理代写:实验项目题目 十个项目题目整合 - 物理作业代写/物理代考
发布时间:2021-07-25 17:48:30浏览次数:
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为美国、加拿大、英国、澳洲的留学生提供物理代写、物理作业代写、物理代考等留学生物理作业代写、exam代考服务。