7 like 0 dislike

Finish a class called Complex for complex numbers. Write the full runable program with this class. Following requirements should be satisfied:

(a) Use double variables for the private data.
(b) Provide a constructor with default values.
(c) Provide functions support arithmetic calculation of adding and subtracting with Complex number objects.
(d) Provide function printing Complex numbers in the form “a + bi”.

class Complex
{
    private:
        double r;
        double i;
    public:
    Complex(double, double);       // Constructor with two arguments
    Complex(double );              // Constructor with one argument
    Complex();                     // default constructor

    Complex operator+ (Complex&);  //Operator overloading
    Complex operator- (Complex&);

    void    print();               // prints the complex number
};

main() function:

int main()
{
    double ar,ai,br,bi,cr;
    cin>>ar>>ai>>br>>bi>>cr;
    Complex a(ar,ai);
    cout << "Constructor with two values: a = ";
    a.print();

    Complex b(br,bi);
    cout << "b = ";
    b.print();

    Complex c(cr);
    cout << "Constructor with one value: c = ";
    c.print();

    c = a + b;
    cout << "a + b = ";
    c.print();

    Complex d;
    cout << "Default constructor: d = ";
    d.print();

    d = a - b;
    cout << "a - b = ";
    d.print();

    return 0;
}

Example input:

1 2 3 4 5

Example output:

Constructor with two values: a = 1 + 2i
b = 3 + 4i
Constructor with one value: c = 5 + 0i
a + b = 4 + 6i
Default constructor: d = 0 + 0i
a - b = -2 - 2i

 

[Exercise] Coding (C) - asked in Final Exam
Available when: 2016-06-22 14:30:00 - Due to: 2016-06-22 17:00:00

edited by | 33 views
1 0
Please see my code
0 0
Called for Help
0 0
TA can you please check my answer... I run it first it was correct but when I upload it was wrong... I accidentally add up all those stuffs like:  (a) Use double variables for the private data.
(b) Provide a constructor with default values.
(c) Provide functions support arithmetic calculation of adding and subtracting with Complex number objects.
(d) Provide function printing Complex numbers in the form “a + bi”. yea you can see that these appears on my coding... So please can You just check my coding itself .
0 0
#include<iostream>

using namespace std;

class Complex
{
    private:
        double r=0;
        double i=0;
    public:
    Complex(double real, double image):r(real), i(image){

    }       // Constructor with two arguments
    Complex(double c):r(c){}              // Constructor with one argument
    Complex()=default;// default constructor

    Complex operator+ (Complex &operand2){
        return Complex(r + operand2.r, i + operand2. i);
    }  //Operator overloading
    Complex operator- (Complex &operand2){
        return (r - operand2.r, i - operand2.i);
    }

    void    print(){

        cout<<r<<'+'<<i<<"i"<<endl;}

                // prints the complex number
};
int main()
{
    double ar,ai,br,bi,cr;
    cin >>ar>>ai>>br>>bi>>cr;
    Complex a(ar,ai);
    cout << "Constructor with two values: a = ";
    a.print();

    Complex b(br,bi);
    cout << "b = ";
    b.print();

    Complex c(cr);
    cout << "Constructor with one value: c = ";
    c.print();

    c = a + b;
    cout << "a + b = ";
    c.print();

    Complex d;
    cout << "Default constructor: d = ";
    d.print();

    d = a - b;
    cout << "a - b = ";
    d.print();

    return 0;
}
0 0
******WRONG PLACE FOR THIS CODE!!!!!!!********
0 0
#include <iostream>
using namespace std;

class Complex
{
private:
    double r;
    double i;
public:
    Complex(double num1, double num2)
    {
        r = num1;
        i = num2;
    }// Constructor with two arguments
    Complex(double num1)
    {
        r = num1;
        i = 0;
    }// Constructor with one argument
    Complex()
    {
        r = 0;
        i = 0;
    }// default constructor
    Complex operator+ (Complex& ptr)
    {
        double new_r, new_i;
        new_r = this->r + ptr.r;
        new_i = this->i + ptr.i;
        if(new_i>=0)cout << new_r << " + " << new_i << "i" << endl;
        else cout << new_r << " - " << (-new_i) << "i" << endl;
    }//Operator overloading
    Complex operator- (Complex& ptr)
    {
        double new_r, new_i;
        new_r = this->r - ptr.r;
        new_i = this->i - ptr.i;
        if(new_i>=0)cout << new_r << " + " << new_i << "i" << endl;
        else cout << new_r << " - " << (-new_i) << "i" << endl;
    }//Operator overloading
    void print()
    {
        if(i>=0)cout << r << " + " << i << "i" << endl;
        else cout << r << " - " << (-i) << "i" << endl;
    }// prints the complex number
};


int main()
{
    double ar,ai,br,bi,cr;
    cin>>ar>>ai>>br>>bi>>cr;
    Complex a(ar,ai);
    cout << "Constructor with two values: a = ";
    a.print();

    Complex b(br,bi);
    cout << "b = ";
    b.print();

    Complex c(cr);
    cout << "Constructor with one value: c = ";
    c.print();

    cout << "a + b = ";
    c = a + b;

    Complex d;
    cout << "Default constructor: d = ";
    d.print();

    cout << "a - b = ";
    d = a - b;

    return 0;
}
0 0
diyiel

#include <iostream>

using namespace std;

class Complex
{
    private:
        double num1;
        double num2;
    public:

    double getr()
    {
        return num1;
    }
    double geti()
    {
        return num2;
    }

    Complex(double numb1=3, double numb2=4)
    {
       num1 = numb1;
       num2 = numb2;
    }

    Complex(double num3=5)
    {
       num1 = num3;

    }
    Complex(){}

    Complex operator+ (Complex& com)
    {
        double a;
        double b;

        a = num1 + com.num1;
        b = num2 + com.num2;


    }

    Complex operator- (Complex& com )
    {
        double a;
        double b;

        a = num1 - com.num1;
        b = num2 - com.num2;
    }

    void    print();

};

void Complex::print()
{
    cout<<num1<<" "<<"+"<<" " <<num2<<"i"<<endl;
    cout<<com.num1<<" + "<<com.num2<<"i"<<endl;

    cout<<num1<<" + "<<"0"<<"i"
    <<a<<" + "<<b<<"i";

}

int main()
{
    double ar,ai,br,bi,cr;
    cin>>ar>>ai>>br>>bi>>cr;
    Complex a(ar,ai);
    cout << "Constructor with two values: a = ";
    a.print();

    Complex b(br,bi);
    cout << "b = ";
    b.print();

    Complex c(cr);
    cout << "Constructor with one value: c = ";
    c.print();

    c = a + b;
    cout << "a + b = ";
    c.print();

    Complex d;
    cout << "Default constructor: d = ";
    d.print();

    d = a - b;
    cout << "a - b = ";
    d.print();

    return 0;
}

25 Answers

0 like 0 dislike
Hidden content!
#include ** * ** ****
*** * * * ***

using ** std;

class Complex

{
**** * ** * * * * * * *
**** ** * * * * *** * * * * ** **** ** r;
**** * ** * ** * **** ****** * ** ** ** i;
* * ** ** * * * *** **** ** **
* *** * ** * ** ** * ** ** * double);
** *** ** **** * * * *** * );
* **** * * ** * * **** **




* * * ** *** * * * ** ** * *** * **
* * **** * * *** **** *** * *** * * *
** ** * *** ** *
* * ** * * * * ****** * * * * * ***



};



// ** * * with two ** * *
** * * ** * * _r, double _i)

{
* * ** ** * * ** * * = _r;
* * *** ** ***** * * ** * = _i;

}



// * * with one argument
*** *** * * _r)

{
* **** * *** *** * * * **** * = _r;
** *** * * *** *** ** * * = 0.0;

}



// default *******
** ** * ****

{
* * ** ** **** **** * * = 0.0;
** ** ** * * * * *** = 0.0;

}



/* Operator * * **

*/

Complex ** ** * (Complex * ** *

{
** *** ** * **** * * (a + bi) + (c + di) = (a+c) + (b+d)i
***** ** * **** * double a = r **** * ** * * * * double b = i;
** * ** *** * * ** double c = rhs.r ; double d = rhs.i;
** ** ** *** * * * * * double nr = a + c;
* *** **** * *********** double ni = b + d;
** ***** ************* * Complex tmp(nr, ni);
* ** ** *** * * * * ** return tmp;
******* * * * * * ** * Complex(r + rhs.r, i + rhs.i);

}



// * * *** '-' operator

Complex * * * * (Complex * **

{
* ** *** ** * * ***** * (a + bi) - (c + di) = (a-c) + (b-d)i
*** * **** ** *** * double a = r *** ** * * ** ** * double b = i;
* ** **** ** *** * * * double c = rhs.r ; double d = rhs.i;
*** * * * ** * ** * ** ******** nr = a - c;
* * * ** *** * ** * ni = b - d;
* * * **** ** * tmp(nr, ni);
* ** **** * ** * * * **** tmp;
* ** * **** ** **** * * * * ** ** * - rhs.r, i - rhs.i);

}



// prints the complex number

void ** * **

{
*** * *** ** * < 0)
*** ** ** * ** * * * ****** * *** * ** * * * *** r ** ** * - * * * ** * ** (-i) * * ***** * * * * * * *** endl;
** *** * * * * ** ** * *
* **** ** * * * * ******** ** * * ** * r * * ** *** * + ** * * *** i *** *** * * * * * * * * ** endl;

}



int main()

{
* * ** ** * * * * ** *
** * * **** * ** **** ******** *** ** * * * * * * ** * * **** * *
** ** * * ** ** * * * ** **** * *
* *** * * ** * *** * ** * ** ** ** ** * * with two values: a = ****
* *** ** * ****** **


*** * * ***** * ** * * * *
* *** * * * * ** *** ** **** * * * = * *
* ** ** **** ** * * *


** * ** ** *** * * * *** c(cr);
** * * * ** * *** * *** *** * * ** * ** * with one value: c = ** ** *
* ** **** * * * * * * *


** * * *** *** * ** = a + b;
* ** * * *** * * *** **** * + b = ** **
* * *** ** * *** ** * * * *


** * * * * ** * * * * *** **** d;
* ** **** ** ******* ** ** *** ** ***** * *** * * d = * ** **
** ** ********* *** **


**** ** ** * *** ** = a - b;
* *** **** ** * * ** * ** * ** *** ***** - b = ** *
** ** * ** * * * * *** * * **


** * * * * **** **** *** 0;

}
answered by (11.8k points)
0 like 0 dislike
Hidden content!
#include <iostream>

#include <fstream> ** * * * ** ** ** * * * *** * * **** ** * ** **** ***** * * *** ** *** * * *** * ** ** * * ** ***** * * * *** * ** ** * * ** * *** * * **** * * * ** *** *** * ********** * * * * ** ** Line 1

using namespace std;



class Point {
* * *** ** ** * *





Point(double xpos, double ypos);

string to_string();



bool equal_to(Point other);



void reflect();

double getx()

{
* ** * * ** * ** *** ** x;

}



double gety()

{

return y;

}



private:
*** * ***** * * *** * *** x;
* * ** * **** ** * * * ** * ** y;

};



Point::Point(double xpos, double ypos)
** * ********** ***** *** * * * *
** ***** *** * * * ** ** * **** * = xpos;
** ***** * * * ***** *** *** * *** * * *** * = ypos;
** * * *** *** * * ** * * ** ****





 void to_string()
* *** * * * ** * * * * ** * **
**** *** * * *** *** ******* *** * ** * string a,b;
* ** ***** * ** ** ** * ** * ** ** ****** ** *** * * *** ***** * * * * * ** * ** ** ** ** * ** ** * * ** * *** * * * * * * ** *** **


* *** ** * ** * ***** *****


** * * ** * *** *** * * *** ** *** *** * equal_to(Point other)
* * * **** * * * * * ****
***** ****** * * ***** **** * ** *** * * *** * ***
* ** * ** * * * * ** * * ** ** * **** (x==y)
* * ** * * * ******** *** ** * * * * *** * ********** * ***** * * * 1;
** ** * ** * * * ***** * * * * ** **
**** ** **** *** * ** ** ******* *** **** * *** * * * * * 0;
** ** ** * * *** ** **** ** ***



 void reflect()
* * * ***** * * * **** * ** *
* ** **** **** *** **** ** * * ***** *** ** f, p;
*** * * * ***** **** * * ** * ** temper;
* ** ******** * ** ** ** ** * * ** *** **** temper;
** **** ** *** ** *** *** * ***** * * = f;
*** ** *** ** * * * * * ** ** ** *** *** *** * *** * =p;


** ** ** * * ** * **** * * *



int main(){
* * * ** ** * * ** *** ** * ax,ay,bx,by;
* * *** ** * * ** ***** * ** * * **** * * *** ** ** *****
* ** * ** * ** *** * A(ax,ay);
* ***** ** * * ** * * B(bx,by);
* *** * ********* * * * *** * * ** ** **** **** * **
* * * * * ** * * *** (A.equal_to(B)) cout<<"A equal B"<<endl;
* **** ******* *** * * ** * cout<<"A not equal B"<<endl;
* *** * *** *** * * **
* * * * * ** * * * *** ******** * * * * ***
*** * * ** * * ***** * ** * 0;

}
answered by (323 points)
0 0
Why class Point, Richard??
0 like 0 dislike
Hidden content!
*** ** * * * *



using namespace std;



class Complex

{
* ** ***** * * ***
*** ***** ** ** * ** **** * * * * * **** r;
**** * **** ** * * * * * * *** * *** * *** **** i;
* *** * ** *
* **** ***** * ******* **** ** *** a, double b)
* * **** ***** * * **
** **** ** ** * * *** * * * * ** * ** = a;
** *** * * * *** **** * * ** ** ** **** * = b;
* **** * * * * * * *** **** **** *** *** * *** * ** * ** *** * **** **** * * *** ** ** **** *** ** ****** **** * * * ** ** ** * *** * ****** * ***** ** *** * *** * * * * * * * * *** * ** * * *** *** * * * * ** Constructor with two arguments
** * ***** ** ***** ** * * * a)
** * * ** * *
***** * * * * *** ******* ***** * * ** * ** * = a;
* *** ****** ** **** * ** ** ** ** * ** * * ** ** = 0;
* * **** * * ** * ***
** ** * * * * * **** * *** ()
** ** * ** ** * ** ***
** * * * **** ** * ****** ** ** **** = 0;
* * * *** * * **** * ** ** * ** * * ** = 0;
*** * *** *** ** * *** ** * * *** *** * * * * ***** ** **** ** ** * * * * ** * * ** ** ** * * * ** * * ** ** * * *** ** * * *** **** ** ** ** * ***** ** * * ** *** ** * * ** ** * ** * ** * * Constructor with one argument
* * ** * ** ** ** * * *** *** ** * ** ** **** * **** ** * ** ** **** * * * ****** * **** * * ** **** **** ** ** * * * * *** ** ** * * *** **** *** **** * ** *** *** *** ***** ** * * * ** ** ** *** * * default constructor
* **** ********** * * * operator+ ****** * a)
* *** **** * * *** **
* ** * ** * ** * ******* * * * *** * ** * ** * temp;
* * * ********* * * **** **** * * * * * * (a) Use double variables for the private data.

(b) Provide a constructor with default values.

(c) Provide functions support arithmetic calculation of adding and subtracting with Complex number objects.

(d) Provide function printing Complex numbers in the form “a + bi”.= r + a.r;
* ** *** *** *** ** * * * * **** ** * **** **** = i + a.i;
**** * * * ** *** *** * ** * ** * * *** temp;
** * * *** ** *** **
*** * ** *** * ** ** ** operator- ****** * a)
* * * * * **** ** *
** * * ** * * ** * * *** * ** * *** temp;
** * * **** ******* * * *** * ** * ****** * * = r - a.r;
*** * * ** **** * ** ** * * *** * ** **** **** ** = i - a.i;
** *** * ********* *** **** *** *** ****** * * ** temp;
* * ** * * ** ****** * * *


** ** *** * * * ** *
** ******** * * *** **
* **** * *** * **
******* *** *** * * ** * * ** ** * * * **** * >= 0)
* ** * **** ** * ** *** * ****** * ** * * * * * * << r << " + " << i << * * * * *** *** **
**** * * * * * ** * ** * **** ** * **** * ****
* * ***** ***** * *** ** ** ** ** **** * *** * * * << r << " - " * ** *** << ** **** << endl;
* * ** **** * ** * * ***

};

int main()

{
** ** * ******* ** *** ar, ai, br, bi, cr;
** * *** ** *** ** >> ar >> ai >> br >> bi >> cr;
** *** * * * ** ** a(ar, ai);
** * **** ***** * ******* * << *** * *** with two values: a = ";
* * * * ** * * *


* * * *** ** * * * * ** ** b (br, bi);
***** *** ** * ** *** * ** * << *** *** ** * with one value: b = ";
**** * ***** ** * * *** ***


* ** * ** * * **** * * ** 0;

}
answered by (-233 points)
0 like 0 dislike
Hidden content!
#include <iostream>



using namespace std;



class Complex

{
** *** * *** * * * ******** **
* ***** ** *** ** * ** * ** ** ** * ** *** ** num1;
* * ****** *** * * * ********** *** * ** * ** *** * num2;
* *** ** * ** ****** * ** *


* * * ** ** * *** **** * **** getr()
*** **** ** * * *
*** * *** *** * *** * ** ** * ****** * * num1;
* **** ** * * ** * * * *
* ** * * ***** geti()
** ** *** * **** ** **** *
** ** ** ** * ** ** ** ***** ** *** ** ** * * num2;
** ** ** ** *


**** *** *** * * *** ** numb1=3, double numb2=4)
*** **** * * * ** *** *****
*** * ** *** * * * * ** * = numb1;
* ** * ** * *** * * * ** * * *** * * * *** = numb2;
** * *** * * * * * **


* * ** * * * * * ** * num3=5)
* * * * * ** * **
* * ***** ** * ** * * * * *** = num3;


** ** **** * * ****
** ** ** ** ***** *


* *** ** * * * ** operator+ (Complex& com)
** * *** *** *** *
* *** ** ***** * **** ** ** * * * ***** ** a;
*** ** * ** * **** * **** ***** ** * * * *** * * * b;


***** ** * * * * ** * * *** * * *** = num1 + com.num1;
* * *** * *** ** * * *** * *** *** *** **** = num2 + com.num2;




* * * **** * * * *


* ** ** *** * * * * ** * * * * operator- (Complex& com )
** ** ** * * ** *
*** ** * * ** * * * * * *** * ***** a;
**** * * ** **** ** ** ** * * * ** * ** ** ** b;


* * ** **** * ** *** ** ** *** ** *** *** ****** = num1 - com.num1;
* * * * * * *** *** * **** *** * * ** * * * * = num2 - com.num2;

    }


* *** * ** ** * * * * *    print();



};



void Complex::print()

{
** * *** **** * * ***** ****** * ***** * * *** *** *** * ** ** *** ** * * *** ** * " * * * ** * * * * * *** * * ** * *
* *** ********* * ******* ** ** ***** * * * *** * **** + * * **** *** *** * * * * * * **** * * ***


* **** ** * * ****** ****** * ** ** ** * *** + * ** * * ** ** * ** * *** ** * * ***** * **
*** ***** * * **** **** * ** * **** * + * ** ** ** ** *** ** * ** * * *



}



int main()

{
*** ***** * ** ***** ** * * ar,ai,br,bi,cr;
****** * * **** * * * *** * * *** * ** * * * ** ** * ** ** ** * ** ** *
** **** * *** ** *** ** * a(ar,ai);
* ** * *** * ***** * << "Constructor with two values: a = ";
* *** * *** * * * ** *** ***


**** ** * ** * *** * * * b(br,bi);
***** ** ** *** * ** * ** ** << "b = ";
* * ** ** ****** ** * **** ***


* * **** ** * * ** *** c(cr);
* ** * ** * *** << "Constructor with one value: c = ";
** ** * **** * ** * **** **


** * * ********** ** = a + b;
* ****** **** *** * * ** << "a + b = ";
* * **** * **** *** * ** ** *


**** *** * ** ** ** d;
* * * ** **** ** ** * << "Default constructor: d = ";
* * ** *** * ***** **** *


* * * *** ** * ** ** = a - b;
* ** ** * ** * * * << "a - b = ";
** * ** **** * ** *


* **** * * ******** ** * * 0;

}
answered by (-359 points)
0 like 0 dislike
Hidden content!
#include <iostream>

using namespace std;



class Complex

{
* * *** * * * * * * *
* * ******** * ** * * ** ** ** * * *** ******** ** r;

* * *** * ** ** * ** * * *** * * ** * ** * ***** ** i;

*** * **** **** ***** **** *** *** **
** ** * * * * * * **** *** * *
** * ** ** * * ** * ***** * * a, double b) {
*** * * ** ** ** ****** * ** *** ** *** * ** * = a;
** ** * * *** * * * * *** ** *** * ** = b;
*** * ***** ** * *** * * * * * * * * **
* * **** * ** ****** *
** * * * *** *** * (double a ) {
***** ** ** ***** ** ** * * * * * = a;
** ** ** *** * ** * * ** *** * * *** ****** **** = 0;
*** * * ** * *** *** * * * *** ****** *** *** *

    }
* *** * * ** ***** ** * () {
*** * ** **** ** **** ** ****** * * * * = 0;
*** * ** * *** * * * ** * * *** *** *** = 0;

    }

    
* ** * ***** ** **** * * operator+ (Complex& a) {
* *** * * * * ** * * *** * * *** * * ****** temp;
* * * * *** ** * * * * * * * ** = r + a.r;
* **** * ** * ** ** ** ** * ***** = i + a.i;
* * * ** * * ** * * ** * * * *** ** temp;

    }
** * **** ** ** ** *** * * operator- (Complex& a) {
** * * * **** * ** * *** * * * *** * ** *** ** ***** temp;
* * * * * * ** *** **** * * * * ** * * * * = r - a.r;
* ** * *** * * *** * ** ** * * ** ** *** * **** * * = i - a.i;
* *** * * **** **** * * * **** ** * * temp;
* ** * * * * * * * *** ** **** **** *
* ***** * ** * * * * ***

    
* * ** * * ** *** * print () {
* * * ************ **** *** * ** ** * * ***
* ** ** *** * ****** ** * ** **** *** *** * * * * ***** ** ** *** * ** ** **** * + * * * ****** * * ** ****** * * * * ** *
* *** * **** * ** *** ** * * * * * * ***
* * * ****** * * ** * * ** * * * *** ** **** * * ** *** * ********** ** ** *** - * *** * * * * * * ** ***** ** * **** ** **
** ** ** * * * **** * * * ** **** * * ** * * ** ***
* ***** * ******

    

    

};

int main()

{
* *** **** ******* ** * ** * ** ar, ai, br, bi, cr;
* * * *** ** * * * * *** ****** * * ** **** * * ** * **** * * ***
** * * ** * ** ** * * * * ** a(ar,ai);
** * ********* * * ** << "Constructor with two values: a = ";
******* * * * ***** ** ***

    
* ** ** * *** * * * * * b(br,bi);

}
answered by (6 points)
0 like 0 dislike
Hidden content!
#include * * * ****

#include ** * * ** ***

using namespace std;



class Complex

{
* *** * ***** * ** ** * *
* * ** * *** * ** * * * ** * ** *** r;
* * ***** * * **** * * ** *** * * * * * *** **** i;
** *** * * * ** ** * ** ***
* * ** ** * *** * * ** * (double realnum, double imagnum)
*** * *** **** *
**** * * **** *** ** *** *** ****** ** * = realnum;
**** *** ** **** ********* ****** ** **** ** * = imagnum;
**** * ** ** ****** * ** **** *** ** * * * ** * ** Constructor with two arguments
* * ** **** * * ** ** * (double realnum)
*** **** *** * ** * *
**** * * ** ******* * * ***** ** * *** ** = realnum;
* * ** **** * ** *** ****** * ** ******* ** * ** * *** *** * * ** * ***** ***** * * ** Constructor with one argument
* ** ** * ** *** * * * * ****** r=0; int i=0;}; ** ***** **** * * * * * * * * ** * *** ** * *** * ** **** **** * **** * * * ****** * * ** ***** * * * ** * ** * *** ** default constructor


* ** *** ** * * **** ** * ** operator+ *** *****
** * *** *** *******
* *** **** *** * * * *** *** ** * ar,ai,br,bi;
* *** * *** *** * * ** * * **** ****** *** ** ar+br;
* ******* ** * * ** * * ** ** ** * * * * * ** *** ai+bi;
* * ** * *** * ** * ** ** overloading
** ** * * ** * ** operator- (const Complex&)
* * *** * * *** ** * * *
* * ** * ** ** * * **** * ** * ** ar,ai,br,bi;
** * * * * * * ****** * ** ***** * * ** *** * ar-br;
* *** * ** ** *** ** * *** ** ** *** * * ** * ai-bi;
** **** ** * ** **** *
** * ** * * *** * * print()
** * *** * * ** * **
* * * * * **** * * * * * ** * ** * * **** * * *
** *** * * * *** *** ** * *
** ***** * * * **** * **** ** ** *** ***** **** ** *** **
**** *** **** * * * ** ** * *
*** * *** *** *** ** * **** ** * ** * *** * ** << r << " + " << (int)i << * ** *** ** << endl;
** * * * * * **** * * * ** ******* *** ** ** ** ***** * * * * ** * * * ******* * * ** *** prints the complex number

};



int main()

{
***** **** ** * * *** ar,ai,br,bi,cr;
* * **** *** * * ****** *** * ****** ** * ** * * * * * * * ***
** *** * **** ** * * * a(ar,ai);
* * ** ** * ******* * ** * ** << ** * * ** *** with two values: a = ";
****** * * * * * ***


****** * * ** * * **** * b(br,bi);
* ** **** * ** *** ** * << "b = ";
* ******* * * * *** ** * *


* * ** * * ** ** ** ** * c(cr);
** ** * * ***** * * * << ***** ****** with one value: c = ";
** *** * *** ** ** * *


* * * **** ** *** * ** * = a + b;
* * ***** * ** * << "a + b = ";
** ** ** * * ** *** * *** * *


** * ** ***** * ** *** **** d;
* ******* * * *** * * * * << ** *** ** ** constructor: d = ";
**** ** * * *** ** ** * * *


** *** ****** ** * * * * = a - b;
* ** * ** ****** **** << "a - b = ";
** ** * * * * * ** * ** * * *


** * * ** ** * ** 0;

}
answered by (-211 points)
0 like 0 dislike
Hidden content!
**** *** * * ** * *



using namespace std;



class Complex

{
***** *** * * ** * *** * **
* * ** **** * * **** * * ** ** * * ** *** ** r;
* *** * * * * ** ***** *** ** *** ** **** i;
* * *** * * * * * * ***** * * ** **
* * * * * * * *** * ** ** a, double b)
** * ** ** *** *** *
***** * * *** * * * * * ** *** * *** ** ** * **
** **** * * * * * ** * * ** * * * * * * **
* * *** **** *** * * ** ****** ** * ** Constructor with two arguments
* * * ******* * ** * * *** a)
*** ** ***** ****
** ** * * * * ** * * * ** * * * ** ** ** * * *
* * * ***** * * * * ** ** ** * * * ** ** * * * * * * * * * ** **** ***** *** Constructor with one argument
**** ** *** ** * * * * **** * ** ** ** * *** ***** * *** ** **** * *** * * * * * * ** ** * * ***** * * ** * * * * *** * ** default constructor


* * * * ** *** * * * ** operator+ (Complex &com)
* * * * **** ** **** *
*** * ** * **** ** * *** *** * ** * ** * * *** *** **
** *** * * * * **** //Operator overloading
* ** *** ***** * operator- (Complex &com);


* ** ** ***** ** * * * * *** *** * ** ** **
*** * **** ** ** * **
****** * *** * * * ****** ** * * ** *** ** *** * ** **** ** * + ** *** * **** **** * * * * **** **
* *** * * * * ** *** ** * * *** * ** ** ***** ** ** ***** * ** ** * ** ** * * * *** *** * prints the complex number

};





int main()

{
* **** **** ** ** * * ar,ai,br,bi,cr;
* * ** * *** * **** * ** * * * *** *** * ** ******* * * * ** * * ***********
* * * * *** **** * * a(ar,ai);
** * * * * ***** * << "Constructor with two values: a = ";
*** ** **** * ** ****


** * * *** **** ** b(br,bi);
**** ** * ***** * * << "b = ";
** ** * * * ** ** * **** *


** ** *** ** * *** **** *** c(cr);
** * **** *** ** * ** << "Constructor with one value: c = ";
** * * * * * * *** ** **


* *** * * ******* * *** = a + b;
* * *** ******* * ***** << "a + b = ";
** ******* ******* ** *


* *** * *** * * * ** **** d;
**** ** ** *** * **** ** << "Default constructor: d = ";
** ** * **** * * ******* **


*** **** * *** ***** * * = a - b;
*** * * * * **** * * << "a - b = ";
* ** *** * * * ** ** *** ***


* ****** ** ** * *** 0;

}
answered by (38 points)
0 like 0 dislike
Hidden content!
#include <iostream>



using namespace std;



class Complex

{
*** * * ** * *** *
* *** * *** ** * **** **** * ** r;
*** * ** * ** * * * ** *** *** *** * ** * * * i;
* * ****** * **** ** * *****
*** * * * * **** * ** * * x, double y)


** * *** * ** * * *** * * * ***** *
* ** * * ** * * * * **** ** * * * *** *
* **** *** * ***** ** * *** * * ** ** * * *
* * ** * * *** *** *** * **** * **** * **


* ** **** ** * * ** ** ***** *** * ** * * * ** Constructor with two arguments
** **** *** ** * * * * * * ** x)
*** * * ** * * * *** *
** ** *** * **** * ** * ** ** ****** *
** * * * ******** * *** ** * * *** ** ***** * **
**** * ** * ** **** * * *** *** * * *** *** * ** **** ** * ** ** * *** ** ** * * ** * Constructor with one argument
** * ***** *** **** * * *
* ** * **** * **
* * *** *** ** *** * * * ** * * * * * *** * ****
* ** ** ******* ** * * ***** * ** **



    } **** * * ****** *** * *** * * ** * *** ***** * * * * * * * *** **** default constructor


* * * ** * *** * operator+(Complex &win)

    {
** ** * * *** * * ****** * * *** ** *** ***** * sum;


***** ** * * * ******** * *** * *** * * * * *** * *** + win.r;
** **** * ** * *** ** ***** ** *** *** * *** * * * * ** ** + win.i;


* * * * * * * ** * * *** *** ** ** *** **** * * ** * sum;
** ** * * ** **  //Operator overloading
******* * * * * * ** ** operator-(Complex &win2)
***** **** * * *** * *
* *** **** **** ** ** * * * * * * * * * ** sum;


* * ** ** **** * * * * ** ****** ** * * * * * - win2.r;
** * * * * * * ** *** * * * ** * * ** * * * * * - win2.i;


** * ** **** * *** * * * * *** *** ** * ** * * sum;
**** ** ** ** *** ** ** ***


* * * * * *** * *    print()
* *** * * ** * * *** * *
** * * * *** * * (i>=0)
***** * *** ** * ** *
** * * * ** ** * * ** * **** * **** * *** ** * * * * ** * ** ** ** * + ** * *** * * ** * **** * *** ** **** * ***


***** * *** * ** * * * *
* **** * * * * * * ***** *
*** ** ** *** ** * ** ** * *
* ** ** ** * ** ** * * * ***** * * * * * ** ** *** ** * ** **** ***** * * * - * ** * * * * * * ***** * "i"<<endl;
* * * ** * * ** * ** * ***
** * ** * *** * *** * * * * * * * ** * * ** ***** * ** *** * * * ***** ** * * * ** * prints the complex number

};

int main()

{
* * *** ********** *** ** ar,ai,br,bi,cr;
* * ** * **** * * * * * * * * ** * ** *** ** * * * *** ** * *
* ** ****** * *** * * * *** a(ar,ai);
* * ** ****** ** ** ** * * << "Constructor with two values: a = ";
* *** ** *** * ** ***


* ***** ** * ** ** *** * b(br,bi);
** ** ** ***** ** ** *** << "b = ";
* ** * * ** * * * * ** * * ** *


** **** ** * * c(cr);
** ** * ***** ** * *** * << "Constructor with one value: c = ";
** * * ** ** * *** ** ****


* * ** ***** * * ** * ** = a + b;
* *** ** *** * *** ** << "a + b = ";
** * * * * **** * *****


* *** ******* ****** * *** d;
* * ** **** * * * * *** * << "Default constructor: d = ";
** * * *** * * * ** * * ** * *



    d = a - b;
** * **** * *** * **** << "a - b = ";
***** * ** ** * * ****


** ** ** * * ** * ** * ** 0;

}
answered by (-11 points)
0 like 0 dislike
Hidden content!
#include <iostream>



using namespace std;



class Complex

{
** ** ***** ** * ** *
* ** ** * ** * * ** ** ***** * * *** * *
*** *** * * * ****** ** ** * r,double i){real=r;imag=i;}
* * ** ** ** ** ** * * ** * complex_add(Complex &c2);


* **** * ** ** * * ** ** diaplay();
* * * * **** ** * **
* * ***** **** * **** * real;
* ** ** ***** * ** * imag;

};



Complex * * *** * * * &c2)

{
***** * * * * * * * c;
* * ** * *** *** * ** *** **** **
* * **** * ** ** * ****
**** * * ** ** ** *** * c;

}



void Complex::display()

{
**** * ** ****** ****** * **** * * * * ** *** ** *** **** *** *** ******* **** * * *** ***** * * ** * * ** ** * * * * **

}



int main()

{
**** ***** * ** * *** * c1(3,4),c2(5,-10),c3;
*** ** ** * * * *** *** ****** **
** * ** * *** **** * * *** ** * * ** * * ** * * *
* ******** *** ** * * * * ** *** *** ** *** * ** * ** *** *
* * * *** **** ** ** * * * ** * * * * * ** * ** *
*** **** ** ** * *** * ** 0;

}
answered by (-605 points)
0 like 0 dislike
Hidden content!
#include <iostream>



using namespace std;



class Complex

{
* * * * **** * * * **
****** * ****** * * * * * * * * ** r;
* ** * * ** ** * * ** ** * * * ** **** i;
*** ** * *** * ** * ** *****
** *** ** **** * ****** x, double y)


* * ***** *** * ** * * * ***** * * *
* ** * ** * * ** **** * * * * ** * *
* * *** *** * * * **** * *** ** *** * * *
* *** ** * * * *** ** * * * * ** ** * ** *


* * * ***** * * ** * **** * ***** * * * * **** * * * Constructor with two arguments
*** * * ** * ** * * * * * ***** x)
* * * * ** * * ** ***
* **** * * ** ** * * * **** ***** **** *****
* ** ** * ** **** * * * * * ** * * * *** * * *
*** ** **** *** ** * *** * * * * *** ** ** * ** ** ** ** * * ** * ** ***** * * ** *** Constructor with one argument
** * * ** * *** *** ** **
** ** ** * ***
** * *** ******** ***** * ** * * * * ** ****
* * *** * *** * **** ** ** * * * **** ** *



    } ** ** ** * ** * * * ** ** * * ** * * ** ***** ** ****** *** * * * ** * * ** default constructor


** * * *** * * * * *** ** operator+(Complex &win)
* ** ** ****
** *** ******* * * *** * * *** ** ** *********** * ** * ** *** sum;


* ***** * * * ** * **** * *** * * ** ***** ** *** *** * + win.r;
* * *** ******* * * * ** * *** ** ** * * ** + win.i;


* ** ****** * * * ***** * *** ******** ** * * * sum;
* * * ***** * *** **  //Operator overloading
**** * ** * ** * * operator-(Complex &win2)
* * * ** *** *** *
***** * * * ** *** * ** ** * ******* * * sum;


***** * ** * * ** ** *** *** ****** ** * ******* * - win2.r;
* ** * * * * * * ** * * ** * ** **** * * ** * - win2.i;


*** ** * * * * * * * * *** * ****** * * ** * * sum;
* ****** ** ** * *


* *** * * * ***** * * ** ***    print()
*** ** ** * ***** *** *
* ** ** *** * * * * * (i>=0)
** *** *** * * * * *
* * * * * * * ** ** ** ****** * * *** * ** * *** + *** * * * * * * ** ** "<<endl;


* * ** * **** * ** ** *** ***
** *** * * ** * * **** * * *
** * * * *** * * * * * **
*** * * ***** * **** *** * * ** ** * * * ** * * * * ** ** * ** *** ****** * *** * - * * * ** ***** * ** ** "i"<<endl;
* ******* ** * ** * **
*** * * * * *** *** **** * * * * ********** ** ** * ** * * * ** ** *** ** * * **** ** ** * ** *** * prints the complex number

};

int main()

{
** *** * * * * *** *** ** ar,ai,br,bi,cr;
*** ** * *** ** **** * * *** **** *** * * ** ***** * * * * ** ** * ***** * *
**** *** ** * **** ***** ** a(ar,ai);
* ** * **** * * << "Constructor with two values: a = ";
* * ** ** ** **** **** *


* * *** ** *** * * ** b(br,bi);
* **** ***** ** * ** * * << "b = ";
*** ** * *** ** * * * **


* **** **** * **** ** * c(cr);
**** ** ** ****** ******* << "Constructor with one value: c = ";
** *** * * * * **** * *



    c = a + b;
* *** ** * * * * << "a + b = ";
** * *** ** * * * *****


* * * ** * ** ** ** ** * * d;
*** ** *** ** * ** *** ** ** << "Default constructor: d = ";
** * * **** *** * **


*** ** * ** *** * * * = a - b;
*** *** *** * ** * *** << "a - b = ";
** * * ****** ** * ***


** ** ** * * ** * ** 0;

}
answered by (-11 points)
Get it on Google Play Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.68.65.168
©2016-2018

Related questions

3 like 1 dislike
8 answers
[Exercise] Essay (Open question) - asked Jun 22, 2016 in Final Exam
Available when: 2016-06-22 14:30:00 - Due to: 2016-06-22 17:00:00
| 31 views
5 like 1 dislike
24 answers
[Exercise] Coding (C) - asked Jun 21, 2016 in Final Exam
Available when: 2016-06-22 14:30:00 - Due to: 2016-06-22 17:00:00
| 34 views
7 like 0 dislike
44 answers
[Exercise] Multichoice - asked Jun 21, 2016 in Final Exam
Available when: 2016-06-22 14:30:00 - Due to: 2016-06-22 17:00:00
| 17 views
6 like 0 dislike
32 answers
[Exercise] True/False - asked Jun 21, 2016 in Final Exam
Available when: 2016-06-22 14:30:00 - Due to: 2016-06-22 17:00:00
| 29 views
7 like 0 dislike
20 answers
[Exercise] Coding (C) - asked Jun 16, 2016 in Final Exam Preparation
Available when: Unlimited - Due to: Unlimited
| 81 views
2,974 questions
57,434 answers
29,089 comments
938 users