Home > Back-end >  The C subject inquire
The C subject inquire

Time:09-23

Define CComplex class, realize the real part and imaginary part of initialization; Through GetReal member function and GetImag member function return to the real part and imaginary part respectively,

#include
using namespace std;
//added your code here
Int main ()
{
Double Real, Imag;
cin> Real> Imag;
Const CComplex num1 (Real, Imag);

Cout<'(' & lt; return 0;
}

CodePudding user response:

Teachers teach all finished forget, can't remember the plural used to do,

CodePudding user response:

Like this:
 
#include
using namespace std;
//added your code here
The class CComplex {
Double Real;
Double Imag;
Public:
CComplex (double R, double I) {
Real=R;
Imag=I;
}
Double GetRealNum () const {
Return Real;
}
Double GetImagNum () const {
Return Imag;
}
};
Int main ()
{
Double Real, Imag;
Cin & gt;> Real & gt;> Imag;
Const CComplex num1 (Real, Imag);

Cout & lt; <'(' & lt; return 0;
}

CodePudding user response:

There's a better way, by overloading the plural computing,
  • Related