Question: Need help creating the functions for this complex numbers program class complexType { public : complexType (); complexType ( double ); complexType ( double ,
Need help creating the functions for this complex numbers program
class complexType
{
public :
complexType ();
complexType ( double );
complexType ( double , double );
complexType operator *( const complexType &) const ;
complexType operator *( double ) const ;
complexType operator /( const complexType &) const ;
complexType operator /( double ) const ;
complexType operator +( const complexType &) const ;
complexType operator +( double ) const ;
complexType operator -( const complexType ) const ;
complexType operator -( double ) const ;
bool operator ==( const complexType &) const ;
bool operator ==( double ) const ;
bool operator !=( const complexType &) const ;
bool operator !=( double ) const ;
friend complexType operator *( double , const complexType &);
friend complexType operator /( double , const complexType &);
friend complexType operator +( double , const complexType &);
friend complexType operator -( double , const complexType &);
friend bool operator ==( double , const complexType &);
friend bool operator !=( double , const complexType &);
friend istream & operator > >( istream & , complexType &);
friend ostream & operator < <( ostream & , const complexType &);
private :
double rpart ;
double ipart ;
};
Here is my main:
# include < iostream >
# include " complexType . h "
using namespace std ;
int main ()
{
complexType c1 , c2 , cResult ;
double num ;
cout << " Enter complex number 1: " ;
cin >> c1 ;
cout << " Enter complex number 2: " ;
cin >> c2 ;
2
cout << " Enter a real number : " ;
cin >> num ;
cout << " c1 = " << c1 << endl << " c2 = " << c2 << endl
<< " num = " << num << endl ;
cout << endl << " Computations " << endl << endl ;
cResult = c1 + c2 ;
cout << " c1 + c2 = " << cResult << endl ;
cResult = c2 - c1 ;
cout << " c2 - c1 = " << cResult << endl ;
cResult = c2 * c1 ;
cout << " c2 * c1 = " << cResult << endl ;
cResult = c1 / c2 ;
cout << " c1 / c2 = " << cResult << endl ;
if ( c1 == c2 )
cout << " c1 equals c2 " << endl ;
else if ( c1 != c2 )
cout << " c1 does not equal c2 " << endl ;
cResult = c2 * num ;
cout << " c2 * num = " << cResult << endl ;
cResult = c1 + num ;
cout << " c1 + num = " << cResult << endl ;
cResult = c2 / num ;
cout << " c2 / num = " << cResult << endl ;
cResult = c2 - num ;
cout << " c2 - num = " << cResult << endl ;
cResult = num * c2 ;
cout << " num * c2 = " << cResult << endl ;
cResult = num / c2 ;
cout << " num / c2 = " << cResult << endl ;
cResult = num + c1 ;
cout << " num + c1 = " << cResult << endl ;
cResult = num - c2 ;
cout << " num - c2 = " << cResult << endl ;
if ( c1 == num )
cout << " c1 equals num " << endl ;
else if ( c1 != num )
cout << " c1 does not equal num " << endl ;
3
if ( num == c2 )
cout << " num equals c2 " << endl ;
else if ( num != c2 )
cout << " num does not equal c2 " << endl ;
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
