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!
* * * * *** *

#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)
0 like 0 dislike
Hidden content!
* * * * * *



using * std;





class **
* *
** *** ** *** ** * ** * Re;
* * * ** * **** ***** * Im;

};



int ***

{
* * *** * **** *** ***** * n1, n2;
*** * * *** ****** **** * ** ** * n1.Re ** ** * * n1.Im;
** *** * **** * * ** * ******** n2.Re *** * ** *
* * *** *** ***** *** * n1.Re + n2.Re * **** * **** ******* * ** **** n1.Im + n2.Im * ** * * *** * ** ** endl;


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

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



using ** ** std;





class *
****
*** ****** * ** * **** Re;
* * ****** * * ** *** * Im;

};



int * *

{
** * *** ***** ** *** * * * n1, n2;
** * * * * *** * **** * *** n1.Re *** * ** n1.Im;
** ** * * * * ******* ** *** * ** ** n2.Re * *** * * **
* * * * ***** * * * * ** ***** n1.Re + n2.Re * ** ** *** * * * * n1.Im + n2.Im *** *** *** * **** * * **** ** endl;


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

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



using * * ** std;



class complex

{
**** ***** * * :
* * *** * *** * * ** ** * * * *** * real, img;

};



int main()

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


* * * ***** ** * * * * *** ** * * a and b where a + ib is the first complex **** * *
** * *** * * * * ** ** * * **** = ** * *
* * ** *** ** * *** * ** a.real;
****** ***** **** * * * *** ** = * **
* ** * *** * ** * * *** * * a.img;
* *** **** * *** * * ***** ***** *** c and d where c + id is the second complex * *******
***** * * **** * *** * ** * *** ** = **** **
**** * ** ** * ********* *** ** * b.real;
**** ** ****** * ** * * ** * * * * * = *
* *** ** ** * ** ** * ** ** b.img;


** ** ** * * *** = a.real + b.real;
** ** * * * * **** = a.img + b.img;


** * *** ** * ( c.img * ** ** * 0 )
* *** ** ** ** * * * **** ** * ** **** c.real * * * * * ***** * ** ** ** ** c.img * * * * ** *
* ** *** * * * ** * *
* **** * ** *** * * * * * ** * * * * * ** * * ***** ** **** * * ** * c.img ** * *** ** ** *** * *


* * ** *** * 0;

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



using * ** std;



class complex

{
** * **** *** * :
**** ** * ** * ****** * * * * *** real, img;

};



int main()

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


*** * * * * ** * * * *** * a and b where a + ib is the first * * * ***** **
* * *** **** * * * ** * * ** = ** *
**** *** ** ** ** * * *
** * * ** *** * * ***** ** * * = * ** * *
*** ** ** * ** * * * * ** a.img;
** * * * * * * ***** ** * * ** * c and d where c + id is the second complex * ** ***
* *** ** *** * * * * * * * ** = ** * **
* ** * * * * * * ** * b.real;
* * *** * * ** * ** * * * ** * = * ** **
********* * **** * ** b.img;


*** **** * = a.real + b.real;
* ***** *** ** * *** = a.img + b.img;


**** * *** **** * ( c.img * * 0 )
* **** ***** * * * * ** * * ** * **** * * ** c.real ******** * * *** * * ** ** c.img **** ** * ** * * * *
* * *** * ** ***
*** ** ** ** ** *** * * ** * * *** * ** *** ** of two complex numbers = * * ** ** ** * c.real * * * * ** *** ****** ** c.img * ** * ** * ** * * * *


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

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



using * std;



class complex

{
** *** * * * * *** *** :
** * ** **** **** * * * * ** * real, img;

};



int main()

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


* * ** * ** ** ** ** * ** * a and b where a + ib is the first complex * ***
* **** * ** * *** * * ** = *** * *
** *** * * **** * * *** * a.real;
* * ** * * ** ** * **** = **** ***
* * * * * ** ** **** * a.img;
* * ** ** ** ** * * ***** *** * * ** * ** c and d where c + id is the second complex **** *
** * **** ** ** * ** * ** ***** = ****
**** * *** * * ** ** b.real;
** *** * * ********* * **** * * = * * ***
* **** ** *** * * *** b.img;


* * *** *** *** ** = a.real + b.real;
* * **** **** ** *** = a.img + b.img;


*** * ** ***** ( c.img 0 )
* * * * ** * * *** * *** * *** ** ** ** * c.real ** * ** * ** ** ** * ** c.img * **** * * * * * * * ***
** * * **** **
* * * **** * ***** ** *** * ** ** *** * * ** * *** * * * * * ** * * * c.img * * **** * * * * * ***


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

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



using ** * std;



class * *

{
*** * * * * ***** :
* * * ** *** * * * * * ** * ** **** real, img;

};



int main()

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


* ** ** * * ** * * ** * * * * * * ** a and b where a + ib is the first complex * ****
** * *** * * *** **** * * * * * = ** * *
* *** ** * * **** * * * ** *** a.real;
* ** *** *** * * * * * *** * * *** *** = *** ***
** * ** * * * * **** a.img;
* * ** * ** ** * ** **** * ** * * c and d where c + id is the second complex ** ****** **
***** ** ** **** ** * * * ***** * * = ***
* * * ******** * * * * * b.real;
* * ** **** * * * * * * * **** * =
** ** * ** *** **** * b.img;


********* * **** * * = a.real + *
* ***** * * * ** * **** = a.img + b.img;


** ** * ***** * ( c.img ** * * 0 )
*** * * ** ** ** ** * * ** * * ** *** **** ** c.real *** ** ** ***** ** *** ** *** c.img * *** * **** ***
* * * * * * ** *
*** * ** * ** * ***** * ** ** * * * * ** ** of two complex numbers = * * ** * * c.real ** *** * * ** ** * ** ** c.img * *** *** *** * * **


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

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



using namespace std;



class Demo {

public:
* ** ** * * *** * * *** a;
*** * * ****** * b;
**** * ** * * ** * * c;
*** *** ** * * *** ** * d;
**** * * * * * * * do_something1();
***** ** * ** ** *** do_something2();

};



int * *** * * ** {
** ** **** * ** * **** a + c;

}

int ** * ** {
* ** ** **** * ** * *** * * b + d;

}



int main(void) {
****** * **** *** * t;
**** ** * ** * *** * ** * * ;
*** * * *** **** * * **** ** ;
* ***** ***** * ** ** ** ***** * * ** ;
*** * * * * * * * * *** ******* ;
* * ** * * ** * ** * << *** ****
* ** ** * ** * * * * * ***** **
* * * ** * *** * ** * * * *** * * * * * ** * ** ** t.do_something2() ** * * * * * ** * *** * * * endl;
** ** * ** * ** *** * * * * * ***** *
** ** *** * * * ** * << * ** ** * * * * * * * *** ** endl;
* * * *** ** * * * * ** << endl;


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

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



using namespace std;



class Demo {

public:
** **** * *** * a;
*** ** ** *** ** *** ** b;
***** ** * ** ****** c;
* * * ** ** * * *** d;
** ** ** ** **** * * * do_something1();
* * * * * * **** * do_something2();

};



int * ** *** ** ** {
**** ** **** * * * ** a + c;

}

int *** * * **** {
*** * ** *** * * * * b + d;

}



int main(void) {
* *** *** *** **** *** t;
*** ** * ** *** ** * **** * *** ;
**** * ** * * * * ** * ** ******* ;
* * * ** *** *** ** ** ****** ** * ;
** * **** ** * * * ** * * * ;
** * *** * * * * * *** **** << ** ** *
*** *** * * * * * **** ** * ** ** **** * * * * *** *** * *** ** ** ** ** * * ** ** endl;
** * * * *** * * ** << endl;


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

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

using namespace std;

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

};



int main()

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

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

    }
*** ** ** * * ** ** if(sum.real==0)
* * *** ** ******* *
*** * ** * * * **** *** * *** * * * ** ** ** * * ***** * ** * * * **
* * * * ** ** * *
* * ** * * **** * *** if(sum.imagine<0)
* * * ** *** * **
* ** * * * * * * ** ** * * * ** ** * *** * ** * ** ** ** ******* **** * * ** * ** **** *** **
* * ** * * ******** **
* *** * ***** **** ** * ** **

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

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

    

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