0 like 0 dislike
2.6k views

Perform addition operation on complex data using class and object. The program should ask for real and imaginary part of two complex numbers, and display the real and imaginary parts of their sum.

Example input:

5 2
2 3

Example output:

7+5i

 

[Exercise] Coding (C) - asked in C++
ID: 24392 - Available when: Unlimited - Due to: Unlimited
| 2.6k views
0 0
Called for Help
0 0
Called for Help

42 Answers

0 like 0 dislike
Hidden content!
#include<iostream>

using namespace std;

class  num{
* *** ** *** * * * ** *
* * *** * *** ** *** *** * real;
* * * * ** *** * *** ** * ** *** *** * imagine;

};



int main()

{
* ** * ** * * * data1,data2,sum;

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

    {
** *** * * * * * * * * *** * * ** * *** * * * ****
*** * * *** * ****** *
* ** ***** ** ** *** * ** *** if(sum.real==0)
****** ****** ** *
* * ***** ***** * * * * * * ** ** * ** ** **** *** * * *** *** * * ** *

    }
****** *** * **
* ** * * * *** *** * *
************* **** * **** ** * ****** * *** * ** * * *** * * * * ****** *** * * *** * * ** * **
* **** * * * * ** ***
** ** ** ** *** *** * * 0;

    

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

using namespace std;

class  num{
** ** * * * * * * *
* ** ** **** ** * *** *** *** * *** ** * real;
** ** * * **** * * * ** ** ** * * * * ** * imagine;

};



int main()

{
* ** * * *** ** data1,data2;
* * * * ** * *** **
**** ** * *** * * * ** * ** * *** * ***** *
* * ** * *** * * **** * ** **** ** * *** * ** ** * ** **

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

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



class  num{
* *** * ** * ** *
* * *** * * ** ** * ** * * *** * **** real;
** ** * * *** ** * * * ** *** ** * * ** imagine;

};



int main()

{
* * * * * * ** ** ** * data1,data2;

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

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

using namespace std;

 

class Complex

{
*** * * *** * *** *** *****
* * * * ** * *** * * **** ** * *** * **** real;
* * ** * **** *** ** * ** ** * * * * *** ** ** imag; * * * * ****

 
** ** *** ** * ** * * ** **
*** ***** ** * **** * * * * *** * * **** ** * * * ** r = 0, int i = 0): real(r), imag(i) {};

 
* ** ** * *** * * * * * ** * **** ** ** * ***** setComplex(void)
** * * * *** * * ** ** ** * ** ** * *
* * **** ** * ***** **** * * * ** * ** *** * * * * **** **** * >> this->real;
*** * * * ** ** * ****** ** **** * * ** * * * *** >> this->imag;
**** * ** * * * * *** * ** ******* * *  
** * * *** * * ** * * ** *** * *** *** *** * * * add(const Complex& c)
** ********* * * * ** ** * ** **** * * **
* ** * * **** ** ** * ***** *** * * ***** ** *** ** * * * comp;
* * ** ** ** * ***** * * * * * * **** * ** ***** * ***** = this->real + c.real;
* ** ****** * ** * * *** * * * ** *** ***** * **** ** * * * *** ** = this->imag + c.imag;
** *** * * * **** ** * * *** * *** *** * * ** * ** * **** comp;
* ** **** * * * ** * **** ***** ** *
*** ** ** ** **** *** ** ** * * * ** *** * * *** printComplex(void)
* * * *** * * *** *** * * * * **** * * **
* * ** * * ** * ** * *** ** *** *** *** * * ****** * ** ***** **** << this->real << * *** ** * << this->imag << ** * * * * << endl;
* ** * * * * * * *** ** * * *** * * * *

};

 

int main()

{
* * * *** ** ***** * a, b, c, d;

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


* ** ** * *** *** = a.add(b);
*** ** * * ** * * **

}
answered by (5.9k points)
0 like 0 dislike
Hidden content!
*** ** * * * * *
* *** * *******

using namespace std;



int main(){
* *** * * * * int real , *****
**** **** * int realsec , * *** ** ** **

* * * * * **

* ***** *** * cin * * * ** real ** * * * * * * *** ** realsec * * * * * *** * *** * ***

* * * *** * + **** ** > 0){
* ** * * * *** * * * * cout ** ** * ** * ** ** *** * * * ** * * * * * * ** ***** *** ** *** ** ;
* ** * ** ** ** }
*** * ** else{
** * ** * * * ** ** cout ** ****** ** ** * ** ** * * ***** * * * ** ** ** * ** * * ** ** * * ** *** ** ;
* *** **** ** }
**** * * ** * return 0;

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



using * std;


**** * * *

{
* * **
** ***** * *** * void * *
* * * * *** ** * * * * * real;
* * * *** * ***** * *** imag;
**** **** ** * * *** ** * *
*** * * * **** ** **** ** * *



};



int *


** * **** one, two;

cin ****** * ** *

cin **** **** * *

cin * *** * *

cin * * *** * *** * **


*** * * = * + *
** = *** + * * *





cout ** ** * **** *
* * *** ***

cout ** * * ** ** * **



cout * * ** **

cout * * * ** ** ** * * * *





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


*** * * * std;


* * * *

{
*****
* ****** * * * * ** void ** ***
*** *** * ** * * * ** * real;
* * * * ****** *** *** * * imag;
* ** ** * *** **
**** ** ******* * * *



};



int ***


*** * ** one, two;

cin ** ** ** *

cin * ** * * ****

cin **** * * * **

cin *** **** * **


***** = * * + ** * *
* * = ** + ****





cout ** * ** ** * *

cout * * ** ** ****** * **

cout **** * * *** ***

cout ** *** * * * ***





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

#include * * * ** *** *



using namespace std;



class com

{

public:
** ** **** * * * ** re, im;

};



int main()

{
* ** * * * ** * *** * * c;
* ***** * * ***** *** * r=0, i=0, n=2;
* ** ** *** *** * * *
**** * ** * * ** ** >> c.re ** ** c.im;
** *** ** ** * ** * **** += c.re;
* ** ***** ****** * *** += c.im;}
** ***** *** ** * ** ** ** *
** **** ** ** ** * ** *** * * * ** * * * ***** r, i);
* ** **** *** * * * * * ** * if(i<0)
* * ** ****** ** ** ** ******* * * * * ** * ** ** ***** * ** ** r, i);
* ** * **** * *** ** ***
** * *** **** * * *** *** *** ** * * * ** ***** * r;
*** * ** **** * ***** 0;

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

#include<cstdlib>

using namespace std;

class calculate

{
* ****** * ** ** ** **
* ** * *** *** ** * *** *** r1, r2;
** ** * * * ***** i1, i2;

};

int main ()

{
** * * ** ** * * number;
**** * ** * * * * * ****** * * ***** * ** * * ***** **** ** * ** *** * ***
* ** * **** ** ** ** **** *
* *** * **** *** *****
** * * ** * *** * * ** ** *** *** * ** * * *** * **** * ** ** * * * * **** * ** ** * ** * ** *** ** **** * **** * * ** * *
*** ***** * * * *
* * ** *** * * * * if(number.i1+number.i2<0)
* **** **** * ** * * **
* * ** ** * * * ** * *** * * *** ** *** * ** * * * * ** * * * *** *** *** ** * ** ** * * ** * *** ****
* ** *** * *** * ****
**** * * * * **** ** *

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

    }
** *** **** **** **** 0;

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

#include ******** ****



using namespace std;



class com

{

public:
* * ****** **** ** ** re, im;

};



int main()

{
** * * * *** ** c;
* **** **** * * * *** ** r=0, i=0, n=2;
* ** * *** ** *** * ** * * **
*** * ****** * * **** * **** * c.re * * * c.im;
**** * ** **** * ** * += c.re;
* **** ******* * * * ** *** += c.im;}
** * * ** ** * * ** * * *****
* * * ** *** ** * * *** ** * ** *** *** * ** ******** * r, i);
* *** * ******** * *** * * ** *
** ****** * * * ** * * * ** * * * * * **** *** r;
** ***** **** ***** **** **** *** 0;

}
answered by (-364 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.71.255.88
©2016-2024

Related questions

0 like 0 dislike
30 answers
[Exercise] Coding (C) - asked May 18, 2017 in C++
ID: 24769 - Available when: Unlimited - Due to: Unlimited
| 1.7k views
0 like 0 dislike
20 answers
[Exercise] Coding (C) - asked Apr 27, 2017 in C++
ID: 24393 - Available when: Unlimited - Due to: Unlimited
| 1.4k views
0 like 0 dislike
17 answers
[Exercise] Coding (C) - asked Jun 1, 2017 in C++
ID: 24855 - Available when: Unlimited - Due to: Unlimited
| 1.2k views
0 like 0 dislike
27 answers
[Exercise] Coding (C) - asked Apr 27, 2017 in C++
ID: 24389 - Available when: Unlimited - Due to: Unlimited
| 1.7k views
12,783 questions
183,443 answers
172,219 comments
4,824 users