#includ using namespace std; class Complex { public: // The reals (rel) and imaginary (img) parts of the complex number float rel; float img; // Default constructor, It should initialize rel and img...

Need help with c++


#includ using namespace std; class Complex { public: // The reals (rel) and imaginary (img) parts of the complex number float rel; float img; // Default constructor, It should initialize rel and img to 0 Complex(); // Constructor with parameters, It should initialize rel to r and img to i Complex (float r, float i) ; // Copy constructor, It should initialize rel and img to the corresponding values in the input c. Complex (const Complex& c); // The unary - operator, It should multiply both rel and img by -1 Complex operator-(); // The pre increment operator, It should add 1 to the rel part and return a copy of the calling object . Complex operator++(); // The post increment operator, It should take a copy of the calling object then add 1 to the rel part and return the copy took before the increment. Complex operator++(int d); // The unary + operator, it should return the result of the addition between the calling object and the input b. Complex operator+ (Complex b); // The unary - operator, it should return the result of the subtraction between the calling object and the input b. Complex operator-(Complex b); // The unary * operator, it should return the result of the multiplication between the calling object and the input b. Complex operator* (Complex c); // The assignment (=) operator, it should update the rel and img with values from the input object c Complex operator=(Complex c); // The == operator, it should return true if the rel and img of the calling object are equal to the input object c. bool operator== (Complex c) ; // With the Right-Hand Side (RHS) and Left-Hand Side (LHS) [] operator we will be able to access the rel and img parts of the complex object using array notation, rel will be at index 0 and img will be at index 1. So, you can deal with the complex number as an array of two values (rel and img), see the main for the usage notation // The RHS [] operator, if the index is 0 it should return a reference to the rel part, if the index is 1 it should return a reference to img part, it should print an error message and exit the program otherwise. float& operator[](int index); // The LHS [] operator, if the index is 0 it should return a reference to the rel part, if the index is 1 it should return a reference to img part, it should print an error message and exit the program otherwise. it is differentiated from the RHS [] by adding const after the function name and const before the return type. const float& operator[](int index) const; }; ostream& operator<(ostream& out,const="" complex&="" c)="" to="" do="" 1:="" implement="" the="">< operator,="" it="" should="" print="" in="" the="" format="" [rel]="" +/-[img]i="" where="" rel="" and="" img="" are="" the="" values="" of="" the="" object="" members,="" for="" the="" positive="" number="" you="" need="" to="" explicitly="" print="" the="" +="" notation="" as="" c++="" will="" not="" print="" the="" +="" before="" the="" positive="" numbers.="" istream&="" operator="">>(istream& in,Complex& c) // TO DO 2: implement the >> operator, it should read the rel and img from the input stream in. // TO DO 3: implement all functions and operators in the Complex class. int main() { cout<"testing the="" default="" constructor="" :\n";="" complex*="" c1="new" complex;=""><"complex* c1="new" complex;="" the="" value="" of="" c1="" is="" :=""><><"\ntesting the="" non-default="" constructor="" :\n";="" complex*="" c2="new" complex(1.1,-3.4);=""><"\ncomplex c2(1.1,-3.4);="" the="" value="" of="" c2="" is="" :=""><><"\ntesting the="" copy="" constructor="" :\n";="" complex*="" c3="new" complex(*c2);=""><"complex c3(c2);="" the="" value="" of="" c3="" is="" :=""><><"\ntesting>> and < operators="" :\n";=""><"please enter="" real="" and="" imaginary="" parts="" for="" c1="" (cin="">>*c1;): "; cin>>*c1; cout<"the following="" is="" the="" result="" of=""><><><"\ntesing of="" the="" -="" (unary="" operator)="" :="" \n";=""><><-(*c3); will="" print=""><><" and="" c3="" is="" :=""><><"\ntesting the="" pre++="" :\n";=""><><++(*c3); will="" print=""><++(*c3);><"c3 after="" the="" ++="" is="" :=""><><"\ntesting the="" post++="" :\n";=""><><(*c3)++; will="" print=""><(*c3)++;><"c3 after="" the="" ++="" is="" :=""><><"\ntesting the="operator" :\n";="" complex="" *c4="new" complex;="" *c4="*c3;"><"complex *c4="new" complex;="" *c4="*c3;" the="" value="" of="" *c4="" is="" :=""><><"\ntesting the="=" operator="" :\n";=""><"(*c4 =="*c3)" ==""><><"(*c1 =="*c3)" ==""><><"\ntesting +,="" -="" and="" *="" binary="" operators="" :\n";=""><"c1 ==""><><" and="" c3="<<*c3<<"*c1[0] =="" 3.3;="" *c1[1]="6.6," then="" c1="" is=""><><"*c1[0] is=""><><" and="" *c1[1]="" is=""><>> and < operators="" :="" please="" enter="" real="" and="" imaginary="" parts="" for="" c1="" (cin="">>*c1;): 1.1 2.3 The following is the result of cout<><-(*c3); will="" print="" -1.1="" +3.4i="" and="" c3="" is="" :="" 1.1="" -3.4i="" testing="" the="" pre++="" :=""><++(*c3); will="" print="" 2.1="" -3.4i="" c3="" after="" the="" ++="" is="" :="" 2.1="" -3.4i="" testing="" the="" post++="" :=""><(*c3)++; will="" print="" 2.1="" -3.4i="" c3="" after="" the="" ++="" is="" :="" 3.1="" -3.4i="" testing="" the="operator" :="" complex="" *c4="new" complex;="" *c4="*c3;" the="" value="" of="" *c4="" is="" :="" 3.1="" -3.4i="" testing="" the="=" operator="" :="" (*c4="=" *c3)="1" (*c1="=" *c3)="0" testing="" +,="" -="" and="" *="" binary="" operators="" :="" c1="1.1" +2.3i="" and="" c3="3.1" -3.4i="" *c1="" +="" *c3="4.2" -1.1i="" *c1="" -="" *c3="-2" +5.7i="" *c1="" *="" *c3="11.23" +3.39i="" testing="" the="" lhs="" and="" rhs="" []="" operators="" :="" *c1[0]="3.3;" *c1[1]="6.6," then="" c1="" is="" 3.3="" +6.6i="" *c1[0]="" is="" 3.3="" and="" *c1[1]="" is="" 6.6="" question="" 2:="" update="" the="" code="" of="" q1="" by="" printing="" the="" message="" “copy="" constructor="" is="" called”="" in="" the="" copy="" constructor="" and="" replace="" the="" main="" with="" the="" following="" code:="" void="" print(complex="" *c)="" {=""><"the real="" part="" is="">rel<" and="" the="" imaginary="" part="" is="">img<"*c1 is=""><><" and="" *c2="" is=""><><"*c3 =="" *c1="" +="" *c2\n";="" *c3="*c1+*c2;"><"*c3 is="" ";="" print(c3);="" }="" after="" running="" your="" code="" you="" should="" get="" the="" following="" output:="" *c1="" is="" 1.2="" +1.43i="" and="" *c2="" is="" 5.7="" +69i="" *c3="*c1" +="" *c2="" copy="" constructor="" is="" called="" copy="" constructor="" is="" called="" *c3="" is="" the="" real="" part="" is="" 6.9="" and="" the="" imaginary="" part="" is="" 70.43="" answer="" the="" following="" questions:="" 1.="" will="" using="" the="">< operator call the copy constructor? if not, why? 2. how many times the statement *c3 =*c1+*c2; will call the copy constructor? in which places. 3. will the statement print(c3) will call the copy constructor, if not, why? 4. draw the activation record stack for the program. 1 operator="" call="" the="" copy="" constructor?="" if="" not,="" why?="" 2.="" how="" many="" times="" the="" statement="" *c3="*c1+*c2;" will="" call="" the="" copy="" constructor?="" in="" which="" places.="" 3.="" will="" the="" statement="" print(c3)="" will="" call="" the="" copy="" constructor,="" if="" not,="" why?="" 4.="" draw="" the="" activation="" record="" stack="" for="" the="" program.="">
Jun 27, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here