Answer to Question #230349 in C++ for Arup

Question #230349

Create a class complex which store real and imaginary part of a complex number. input

 5 complex number & display it.


1
Expert's answer
2021-08-30T03:50:11-0400


#include<iostream>
using namespace std;
class Complex{
public:
    int realNumber;
    int imagNumber;
    
     void input()
    {
        cout<<"Enter the real part of the complex number: \n";
		cin>>realNumber;
	        cout<<"Enter the imaginary part of the complex number: \n";
	
        cin>>imagNumber;
    }


    void display()
    {
        cout<<realNumber<<"+"<<imagNumber<<"i"<<endl;
    }


    
    };
int main()
    {
        Complex arr[5];
        cout<<"Enter 5 complex numbers\n";
		for(int i=0; i<5; i++){
			cout<<"Complex number:  "<<(i+1)<<endl;
			arr[i].input();
        
		}
		cout<<"The 5 entered complex numbers are\n";
		for(int i=0; i<5; i++){
			arr[i].display();
		}
    return 0;
    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS