Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ C ++ complex class of operator overloading     - Python object-oriented programming (Programming)

- Ubuntu Froxlor Server Administration panel installation (Server)

- Depth understanding of Python character set encoding (Programming)

- Linux kernel modules related to the management Comments (Linux)

- MongoDB configuration in Ubuntu 14.04 (Database)

- C ++ virtual functions Classic Insights (Programming)

- Shell Scripting Interview Questions (Programming)

- Thinking in Java study notes - Access modifiers (Programming)

- Making Linux root file system problems on-link library (Programming)

- Using iptables achieve NAT (Linux)

- Give your photos Instagram style filters plus program in ubuntu (Linux)

- Some common Linux commands Study Notes (Linux)

- MySQL Tutorial: Using tpcc-mysql pressure measurement (Database)

- Java Network Programming Internet address lookup (Programming)

- Openfire Hazelcast cluster Detailed (Server)

- JavaScript cross-browser event object library (Programming)

- ORA-01839 error caused by incorrect system date setting (Database)

- Linux Command - ps: a snapshot of the current process (Linux)

- Getting CentOS Learning Notes (Linux)

- Erlang concurrency and foundation (Programming)

 
         
  C ++ complex class of operator overloading
     
  Add Date : 2018-11-21      
         
         
         
  Here implement complex class operator overloading online less cout cin is overloaded, and math *, /, I realize what a statement:

Complex.h:
#ifndef __COMPLEX__
#define __COMPLEX__
#include
using namespace std;
class Complex
{
public:
friend ostream & operator << (ostream & out, const Complex & num) // overloaded cout, cin, a direct transfer Lesson
{// Use >>, << operator input output
if (num._imgic <0.0) // out, I write overloaded define friend
{// The header file
out << num._real << "-" << - (num._imgic) << "i";
}
else
{
out << num._real << "+" << num._imgic << "i";
}
return out;
}
friend istream & operator >> (istream & in, Complex & num)
{
in >> num._real;
in >> num._imgic;
return in;
}
Complex (double real = 0, double imgic = 0)
: _real (Real)
, _imgic (Imgic)
{
}
~ Complex ()
{
}
bool operator> (const Complex & num);
bool operator <(const Complex & num);
bool operator == (const Complex & num);
bool operator> = (const Complex & num);
bool operator <= (const Complex & num);
! Bool operator = (const Complex & num);
Complex operator + (const Complex & num); // arithmetic operator overloading
Complex operator - (const Complex & num);
Complex operator ++ (); // Front +, -, rear +, - and here I fully realized as +, - real
Complex operator ++ (int); // do calculation of the imaginary part
Complex operator - ();
Complex operator - (int);
Complex operator + = (const Complex & num);
Complex operator - = (const Complex & num);
Complex operator * (const Complex & num); // multiply, and divide operations to achieve
Complex operator * = (const Complex & num); // if realized / arithmetic function, we must first realize ~ (conjugated)
Complex operator / (Complex & num);
Complex operator / = (Complex & num);
Complex operator ~ (); // conjugate operator realization
private:
double _real;
double _imgic;
};
#endif

Codes are as follows, Complex.cpp:

#include "Complex.h"
bool Complex :: operator> (const Complex & num)
{
if ((_real * _real + _imgic * _imgic)>
(Num._real * num._real + num._imgic * num._imgic))
return true;
return false;
}
bool Complex :: operator <(const Complex & num)
{
return (* this> = num)!;
}
bool Complex :: operator == (const Complex & num)
{
if ((_real == num._real) &&
(_imgic == Num._imgic))
return true;
return false;
}
bool Complex :: operator! = (const Complex & num)
{
return (* this == num)!;
}
bool Complex :: operator> = (const Complex & num)
{
return (* this> num) || (* this == num);
}
bool Complex :: operator <= (const Complex & num)
{
return (* this> num)!;
}
Complex Complex :: operator + (const Complex & num)
{
return Complex (_real + num._real, _imgic + num._imgic);
}
Complex Complex :: operator - (const Complex & num)
{
return Complex (_real - num._real, _imgic - num._imgic);
}
Complex Complex :: operator ++ ()
{
_real ++;
return * this;
}
Complex Complex :: operator ++ (int)
{
Complex ret = * this;
_real ++;
return * this;
}
Complex Complex :: operator - ()
{
_real--;
return * this;
}
Complex Complex :: operator - (int)
{
Complex ret = * this;
_real--;
return * this;
}
Complex Complex :: operator + = (const Complex & num)
{
_real + = num._real;
_imgic + = num._imgic;
return * this;
}
Complex Complex :: operator - = (const Complex & num)
{
_real - = num._real;
_imgic - = num._imgic;
return * this;
}
Complex Complex :: operator * (const Complex & num)
{
return Complex ((_ real * num._real - _imgic * num._imgic),
(_real * Num._imgic + (num._imgic * _real)));
}
Complex Complex :: operator * = (const Complex & num)
{
return * this = * this * num;
}
Complex Complex :: operator / (Complex & num)
{
return Complex (((* this * (~ num)) ._ real) / ((num * (~ num)) ._ real),
((* This * (~ num)) ._ imgic) / ((num * (~ num)) ._ real));
}
Complex Complex :: operator / = (Complex & num)
{
Complex ret = * this / num;
return ret;
}
Complex Complex :: operator ~ ()
{
return Complex (_real, -_imgic);
}
     
         
         
         
  More:      
 
- 2 minutes to read large data framework Hadoop and Spark similarities and differences (Server)
- Python extension module Ganglia 3.1.x (Linux)
- Construction Spark source and application development environment (Server)
- ORA-04031 Error Resolution (Database)
- Python objects (Programming)
- innodb storage engine backup tool --Xtrabackup (Database)
- The lambda expression Java8 (constructor references) (Programming)
- Redis 3.0.3 Cluster Setup (Database)
- Vagrant build LNMP environment (Server)
- How to use Xmanager Remote Desktop and VNC Log (Linux)
- Ubuntu root user profiles (Programming)
- Vim useful plugin: EasyGrep (Linux)
- Why do you need close contact Rust 1.0 (Programming)
- Ubuntu users install the video driver Nvidia Driver 334.21 (Linux)
- Oracle Execute to Parse perform analytical Ratio Analysis (Database)
- Linux C source code (sockettype: socket descriptor determination function) (Programming)
- Installation Atom text editor on Mint Ubuntu / Linux (Linux)
- Cobbler automatic mass deployment of CentOS 6 and CentOS 7 (Linux)
- Hadoop 0.23 compile common errors (Server)
- Linux compiler installation Redis (Database)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.