0 like 0 dislike
1.3k 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
| 1.3k views
0 0
Called for Help
0 0
Called for Help

42 Answers

0 like 0 dislike
Hidden content!
* * *** ** * ***
** * * * ** **

using namespace std;



int main(){
*** *** * ** * * ** real , imaginary;
** * ** * * ** *** *** realsec , imaginarysec; * **** ** *
* * ** ** ******* * *
* ******* ** ******* ** ** >> real >> imaginary * ** ** realsec * *** * imaginarysec ; * ** *** *
*** * * * * * ** **** *** ** + imaginarysec) > 0){
* * * * **** ** ** * * **** * * * ***** ** * * * * * ** real+realsec *** * * * ** * * * * ** * * *** *** * * * * ;
******** *** ** * ***
**** *** ***** **** * * ***
******* * * * ** * * * ** * * ** * ** * * ** ***** real+realsec * ** **** ** * ** * ** * ******* * * * *** ** ********* ** ;
* * * *** * * * ** * * *
* ** * ***** * ** 0;

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

using namespace std;



int main(){
* ******** * * **** * * real , imaginary;
* * * * ** ** * * * ** realsec , imaginarysec; *** *** * **** * ** *
* * * ** * ***** **
** ** * * * * * * ** >> real >> imaginary ** * *** * realsec * * imaginarysec ; * * ** **
*** *** ** ** * * * * * + imaginarysec) > 0){
** * *** *** * **** * ** * * * ** * real+realsec ** ** * * *** * ** * * ***** ** ** ** *** * * * ** ** * * ;
***** * * * * * ** *
* * *** * * * ** * * ****
* ***** * ** * * * ** ****** *** * ** * *** * real+realsec *** *** ** ** * **** * * * * * ** ** ** * *** ** ** **** ** ** * * ;
* ***** ** ** * * ***
* * * * ** ** ** * ** * ** 0;

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

using namespace std;



int main(){
* * **** * * * ** * * * * ** real , imaginary;
** * * *** ** * * * *** realsec , imaginarysec; * ***** ** *
*** * * ** * * * * * *
* ** **** * * *** ** ** *** * * >> real >> imaginary * ** realsec * * *** imaginarysec ; * ** * *** *****
* ****** **** * * *** * + imaginarysec) > 0){
* ** ** * * * ** ** * **** ****** * ** *** *** * ** real+realsec * * * * ** * *** ***** * * * **** * * *** * * ** * ** ** * * ;
**** *** * ** * ** *
** ** * * ***** * ** * *
*** * * ** *** * ********* * ** *** ** ***** * real+realsec * * * ***** * ** * * **** ** **** * * *** *** ** * * * *** * ** * ** ;
** **** ** * * ** * ** *
** ** * ** * ** ** *** ****** * 0;

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

using namespace std;



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

    
* ** * * real ****** * * ** * ** realsec ** * * ** *** ;    
***** ** ** + *** > 0){
** ** * ***** * ** * * * ** *** *** *** *** ** ** **** * * *** ** * * * *** * ;
*** *
** * *
* **** *** ** ** * ** ** * ** * *** *** ** *** *** * * * * **** **** * * **** * ***** **** * ******* ;
* **
***** * * 0;

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

using namespace std;



int main(){
* *** * ** * * * * real , imaginary;
** * * **** * * ***** realsec , imaginarysec; ** ** ** ** ** * *
** ****** * * **** ** * *
*** * * * * ** * ** >> real >> imaginary *** *** realsec * ** imaginarysec ; * * * * **** *
*** * ** *** * ****** ** + imaginarysec) > 0){
* * **** *** * * * *** * ** **** *** ** * * * * * real+realsec ** * ** * * * ** * ** ** ** * * * * ** * ** ** * * ;
* ** **** * *
* ** *** * ** * *** **
* *** ****** * ** *** ** * * * ** ** * ** * ****** real+realsec * * *** * ** * ***** *** * * *** * * ** ;
******* ** * ** *
*** * * **** * ** ** * 0;

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

using namespace std;



int main(){
* * * * * *** * ** * ** real , imaginary;
*** * * ** * *** ** **** * realsec , imaginarysec; ******* * *
* * *** * * * ** * *
* ** ****** ** * * >> real >> imaginary ******* ** realsec *** * * imaginarysec ; * * * ****
* ** * * * ****** **** * * + imaginarysec) > 0){
** * * * *** * **** ** *** * *** * ** * * *** * * ** * real+realsec *** * *** * * * * * **** * * * ** * *** * * * ****** *** * * ;
* *** **** ** ***
** ** * * ** * * **** **
** ****** ** * ** ** * * **** * * * *** * ** * * real+realsec * * * ** * * * ** * * ***** * * * ** * * * * * * ;
* * ** * ** **** **
* * * *** *** ** ** *** * ** 0;

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

#include **** * *

using namespace std;



class NUM{

public:
* * * *** ** * * * ***
** * ** * * ** * *** ***** *** ** = 0;
* ** ** * ** ** **** * * * ** * *** * ** ** = 0;
** ***** ******* ** **
** * * * * * * *** * * * a, int b){
* ** ******** ** ***** * ******** ***** * * ***** = a;
** *** ***** ** * ** ** * ** * ** ** * ** * = b;
* ** ** ** * * * **
* * *** * * * output_num(){
*** ** ** * ** * ** ** * * *** *** * * **** ** **
* * ** ** *** ************* ** * *** * ** ***
*** ** **** **** * ** *** * * * ** ** ** ** ***** ** ** * * << real_num * * * * ** ****** ** << image_num << ****** ** * << endl;
* * * *** * * * * ** * ** ** *** * ***
* * * *** * * * * * ** * * *** *** * * * *
* ** **** * ** *** * * * ** * * ** * * * ****** * ** * *** * ** << real_num << **** ** *** << *** ** ** << endl;
* * * * **** * ** ** * ** * * ** * ******* ***** *
* ** *** * * *** * * * * *** * * *** * * ***
**** * ** * * ********* * * * * ***** * **** ** * * ** ** * * << real_num << * * ***** ** << image_num << * ** *** << endl;
** * ** * * ** * * * ** * * ** ** * * **
***** * * ** ** * *


* **** * * * * ** operator+(const NUM& m){
**** ** * *** * * ** * * * ** **** n;
* ** ** **** **** ** * * * *** * * ** * * ** * = * * * * ** * * + m.real_num;
* * ** ** *** **** ** ** **** * *** * *** * * = * * ** ** * + m.image_num;
* ** ** * ** * *** * * ** * * * * * *** n;
* * * * * ** ****

private:
***** * * * * * * * ** real_num;
** * ** ****** * image_num;

};



int main()

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


** * ** * ** * ** * >> a >> b >> c *** *** d;
* * ** * *** n1(a, b);
* * * * * * n2(c, d);
* * ** ** ** ** **** = n1 + n2;
* ** ** **** **** * *** **
* *** * **** **** * ** 0;

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

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

using namespace std;



class NUM{

public:
* *** *** * ****** * *** * * *
** * ** ** *** * * ** * * *** ** ** ** * = 0;
* * **** ** * * * * * ** * **** *** * ** * ** *** = 0;
* ** * *** ** * * * *
* *** ** * * * *** a, int b){
* ***** * * *** * * *** ** ** * * = a;
*** ****** ******* * ** *** **** * * * * = b;
* * ******** *** ** ** * *
* ** * * ** * *** * output_num(){
**** * ** * * * *** * * * *** * **** ** * * ***** * *
* * ** * * ** ** * * **** * ** * * ** **** * **
* * **** ** * * **** ** ** **** ** ** * * * * *** * * * * ** * << real_num << * * * *** * ** * << image_num << endl;
** ** * ** * * * *** ** * **** * ** *
* * ***** * **** * * * * ***** ******** *** * *** *** ***
* * * ** * *** * * ** ** * ** * ** **** ** * * * * * * * * << real_num << * ** ** << * * << endl;
* **** *** ** ** *** **** ** ****** * *** **
** ** * * * * * * * ** * ******* **** ******
** ** *** * **** * * * **** * * *** * * * * * ** ***** * ******* ** ** real_num << * ** * * * << image_num << * * * * << endl;
* * ** * *** ** * **** ******* *** *** ** ***
* ***** ** * * * * *


***** * ** ** * * * * operator+(const NUM& m){
* **** ** ** * * ******* * ** * **** * ** ** n;
*** * * * **** *** *** * ** *** ***** ** * * * = ** ** * + m.real_num;
* ** **** * *** *** * * ** * * ******* ** * *** * * = * * ** * **** * + m.image_num;
* ** * **** ** ** * *** * **** ** *** * * ** n;
* ** * * * * ** * * **

private:
* * *** **** *** *** *** ** real_num;
* * * *** * **** * image_num;

};



int main()

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


* * * ****** **** >> a >> b >> c >> d;
* * ** ** * * **** * n1(a, b);
* * ***** * ** * * n2(c, d);
* ** ** ***** ** ** * * * = n1 + n2;
*** * * ** * ***** * * *
* ** * * * *** ** * 0;

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

#include * ********

using namespace std;



class NUM{

public:
** ** * * ** ** * **** *
* ** * * ** * * *** ** * * *** * *** * *** * * ** = 0;
* * * * ***** * * ** *** * ** ** * = 0;
* * ** ***** **** * *
** * * * * *** * ** a, int b){
* ** * * ** * * ** ** * *** *** * * * * * * = a;
****** *** * *** * ** * * * ******* * * ** *** = b;
* * * ***** * * *** * ** ***
** * ** * ** *** * * * output_num(){
* *** * ** * * * ** * ** * * **** * ** *** ***
** ** * *** ** *** * ** ***** **
* * * * * * * **** ** ** * ** **** ****** * * ** * **** **** ** << real_num << ** ** ***** << image_num << endl;
** * * ** * *** * **** ** * **** ** * *** ***
****** * * *** ** *** * ****** *** ** *** ** * **
* * ** ** ***** * ** * * ** * ** ** ** * * ** ** ** **** * * * ** << real_num << ** *** ** ** << image_num << * * * * << endl;
****** ** * ** * * ** ***** ** * * ** **
* * * **** * * *** *


* * ** ** * * * * * operator+(const NUM& m){
**** * *** * ** ** **** *** * * ** **** * n;
* **** * ** **** * * * * ** ** ******* ***** ** ** = *** * ** + m.real_num;
** * **** ** ** * ** *** * *** * **** = * * * ** + m.image_num;
** * * * *** * * * *** ***** *** ** * ** ** ** * ***** ** n;
** ** *** ***** * * *

private:
** ** ** * ** * * * real_num;
* *** * * * * * * ****** *** ** image_num;

};



int main()

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


* * **** * * * ** >> a >> b >> c ***** * d;
* * *** * * ** * * n1(a, b);
* *** ** * ** * ** n2(c, d);
* * ** * *** * * ***** = n1 + n2;
* ***** ** *** * ** * * *
*** **** ** * **** * * * * 0;

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

#include * * **

using namespace std;



class NUM{

public:
* *** * * *** *** **
*** ** ** * ** *** ** *** *** ** * * * * = 0;
** *** * ** * * * **** ** ** *** = 0;
*** * ** * * * ** * *
**** ** * * * * ** * a, int b){
**** * * * * * * ** * * ** *** * * * * * ** ** = a;
*** ** ** ** * * ** * * * * ** * * ** * * = b;
* * * ** * * * * ******
* * *** * * *** * *** ** * output_num(){
** ** * * *** *** *** ** * *** *** ****** * << real_num << ** **** * << image_num * * * * * * * ** * ** endl;
** * * * * ***
* * ** **** * ** * *** * operator+(const NUM& m){
** * *** **** * * * ** *** * ** * ** * * * n;
* ** ** ** ** * ** ** **** *** * * ** * * * = ** ** + m.real_num;
* * ** * * * ** ** ** * * * ** * * ** ** *** * * = ****** * ** + m.image_num;
* * * * * * * *** * * * *** ** * **** *** n;
* * ** ********** * *

private:
** *** * ** * *** real_num;
* * * * **** * **** ** ** image_num;

};



int main()

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


**** **** **** ** ** * * >> a >> b * ** c * ** ** d;
**** * ** * * * **** * * * n1(a, b);
* ** * ** * ** * * n2(c, d);
* *** * ** ** * * * = n1 + n2;
** * * * ** * * * ** * * ** * * ****
*** ** *** * *** * *** ** 0;

}
answered by (-368 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.131.70
©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
| 758 views
0 like 0 dislike
20 answers
[Exercise] Coding (C) - asked Apr 27, 2017 in C++
ID: 24393 - Available when: Unlimited - Due to: Unlimited
| 707 views
0 like 0 dislike
17 answers
[Exercise] Coding (C) - asked Jun 1, 2017 in C++
ID: 24855 - Available when: Unlimited - Due to: Unlimited
| 577 views
0 like 0 dislike
27 answers
[Exercise] Coding (C) - asked Apr 27, 2017 in C++
ID: 24389 - Available when: Unlimited - Due to: Unlimited
| 851 views
12,783 questions
183,443 answers
172,219 comments
4,824 users