Saturday, September 27, 2014

Write a base class that asks the user to enter a complex number and make a derived class that 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.

#include
#include
class complex{
protected:
float real;
float img;
public:
void getcomplex()
{
cout<<"\nEnter real and imaginary numbers:";
cin>>real>>img;
}
};
class add_complex:public complex
{
private:
float real1;
float img1;
public:
void getnew()
{
cout<<"\nEnter real and imaginary numbers:";
cin>>real1>>img1;
}
void add(){
float sum_real;
float sum_img;
sum_real=real+real1;
sum_img=img +img1;
cout<<"Sum:"<
}
friend class sub_complex;
};
class sub_complex{
private:
float real2;
float img2;
public:
void getnew()
{
cout<<"\nEnter real and imaginary numbers:";
cin>>real2>>img2;
}
void sub(add_complex c1){
float diff_real;
float diff_img;
diff_real=c1.real-real2;
diff_img=c1.img -img2;
cout<<"Difference: "<
}
};
void main(){
clrscr();
add_complex c1;
sub_complex c2;
cout<
c1.getcomplex();
cout<
c1.getnew();
c1.add();
cout<
c2.getnew();
c2.sub(c1);
getch();

}

No comments:

Post a Comment