Answer to Question #265973 in C++ for Kimchi

Question #265973
Construct a class named Complex to represent a complex number with the requirements:

The real and imaginary components are both floats
Function to input real components, virtual components from the keyboard
Function to display information to the screen
Function to take real components, function to assign real components
Function to get virtual components, function to assign virtual components
The function also takes real and imaginary components
The function simultaneously assigns real and imaginary components
Write a main program that illustrates how to use it




1
Expert's answer
2021-11-15T00:23:08-0500
#include<iostream>
using namespace std;
class Complex {
	private:
		float imag, real;
	public:
		void input(){
			float r;
			cout<<"Enter the real part of the complex number\n";
			cin>>r;
			float i;
			cout<<"Enter the imaginary part of the complex number\n";
			cin>>i;
			imag  =i;
			real = r;
		}
		
		void output(){
			cout<<real<<"+ "<<imag<<"i"<<endl;
		}
};
int main(){
	Complex comp ;
	comp.input();
	comp.output();
}

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