Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

classes with private class complex{ public: complex( double = 0.0, double = 0.0)

ID: 3534922 • Letter: C

Question

classes with private class complex{ public: complex( double = 0.0, double = 0.0); //constructor // complex(); complex add(complex); //member functions void print() const; private: double a, b; //not known on outside }; int main() { complex c(1.0,1.0 ), d(2.0,0.0 ), e; e=c.complex::add( d); e.print(); system(" pause"); return 0; } // Member function definitions for class complex <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> complex::complex( double y1, double y2 ) { a = y1; //constructor b = y2; } complex complex::add( complex d) { return complex(a+ d.a,b + d.b) ; } void complex::print() const { cout << "(" <<a << "," <<b <<")"<<endl ; }

need hlp. have to do with subtraction and multiplication now. this is just an example for addition i have to use this for multiplication and subtraction. same thing as the one above

Explanation / Answer

#include<iostream.h>
#include<conio.h>
class Cmplx1
{
int real,imagin;
public :
void get()
{
cout<<" ENTER THE REAL PART : ";
cin>>real;
cout<<" ENTER THE IMAGINARY PART : ";
cin>>imagin;
}
friend void sum(Cmplx1,Cmplx1);
};
void sum(Cmplx1 c1,Cmplx1 c2)
{
cout<<" RESULT : ";
cout<<" ["<<c1.real<<" + i "<<c1.imagin;
cout<<" ] + [ "<<c2.real<<" + i "<<c2.imagin;
cout<<" ] = "<<c1.real+c2.real<<" + i "<<c1.imagin+c2.imagin;
}
void main()
{
Cmplx1 op1,op2;
clrscr();
cout<<" ADDITION OF TWO COMPLEX NUMBERS USING FRIEND FUNCTIONS ";
cout<<" INPUT OPERAND 1";
op1.get();
cout<<" OPERAND 2";
op2.get();
sum(op1,op2);
getch();
}