Answer to Question #176343 in C++ for Muhammad Ahmed

Question #176343

Write base class that ask the user to enter a complex number and derived class adds the complex number of its own with the base. Finally make third class that is friend of derived and calculate the difference of base complex number and its own complex number.


1
Expert's answer
2021-03-28T14:37:20-0400
#include<iostream.h>
#include<conio.h>
class complex
{
   private:
	float x;
	float y;
   public:
	void set(float real, float img)
	{
		x=real; y=img;
	}
	complex sum(complex);
	void disp();
};
complex complex::sum(complex C)
{
	complex t;
	t.x = x + C.x;
	t.y = y + C.y;
	return t;
}
void complex::disp()
{
	cout<<x<<" + j"<<y<<endl;
}
int main()
{
	complex C1,C2,C3;
	C1.set(2.5,7.1);
	C2.set(4.2,5.5);
	C3=C1.sum(C2);
	cout<<"\n complex Number 1 = ";C1.disp();
	cout<<"\n complex Number 2 = ";C2.disp();
	cout<<"\n complex Number 3 = ";C3.disp();
	getch();
	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