French, asked by Azinkiya, 1 year ago

Write a syntax to define a derived class.​

Answers

Answered by Anonymous
4

A class can be used as the base class for a derived new class. The derived class inherits all of the properties of the base class. The derived class can add new members or change base class members.  C++ Support for OOP (cont.)

class Complex

 {

 private:

     double re;

     double im;

 

 public:

     Complex(float r,float i) {re = r; im = i;}

     Complex(float r) {re = r;im = 0.0;}

     ~Complex() {};

 

     double Magnitude();        // calculate magnitude

       

     double Real() {return re;} // return real part

     inline double Imag();      // return imaginary part

 

     Complex operator+(Complex b)

     {return Complex(re + b.re,im + b.im);}

 

     Complex operator=(Complex b)

         {re = b.re;im = b.im; return *this;}

 };

 

 inline double Complex::Imag()

 {

     return im;

 }

 

 double Complex::Magnitude()

 {

     return sqrt(re*re + Imag()*Imag());

 }

Answered by Anonymous
4

heya mate

A class that was created based on a previously existing class (i.e., base class). A derived class inherits all of the member variables and methods of the base class from which it is derivclass can be used as the base class for a derived new class. The derived class inherits all of the properties of the base class. The derived class can add new members or change base class members.  C++ Support for OOP (cont.)

class Complex

 {

 private:

     double re;

     double im;

 

 public:

     Complex(float r,float i) {re = r; im = i;}

     Complex(float r) {re = r;im = 0.0;}

     ~Complex() {};

 

     double Magnitude();        // calculate magnitude

       

     double Real() {return re;} // return real part

     inline double Imag();      // return imaginary part

 

     Complex operator+(Complex b)

     {return Complex(re + b.re,im + b.im);}

 

     Complex operator=(Complex b)

         {re = b.re;im = b.im; return *this;}

 };

 

 inline double Complex::Imag()

 {

     return im;

 }

 

 double Complex::Magnitude()

 {

     return sqrt(re*re + Imag()*Imag());

 hope it helps u mate

Similar questions