Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ C ++ complex class of operator overloading     - How UTorrent download the ISO image from the command line (Linux)

- xCAT install and update software (Linux)

- Linux PXE unattended installation PXE-E32: TFTP OPen timeout the solution (Linux)

- Detailed steps - GAMIT solver (Linux)

- Write perfect printf (Programming)

- High-performance JavaScript loaded and executed (Programming)

- How to write a new Git protocol (Linux)

- To install Xen in Ubuntu 12.04 (Linux)

- Analysis of Java keyword final (Programming)

- Use MD5 transform algorithm to prevent exhaustive decipher passwords (Linux)

- Linux, Chrome browser font settings beautification (Linux)

- VirtualBox - Linux system virtual machine shared folders (Linux)

- To install PXE + Kickstart under CentOS 6.x operating system (Linux)

- Installation Elementary OS Freya to do some settings (Linux)

- Linux system security reinforcement system by masquerading method (Linux)

- JBPM6 Tutorial - taught you how to install JBPM (Linux)

- How to create an alternative Android / iOS connected wireless hotspot AP in Ubuntu 15.04 (Linux)

- Binding unofficial Google Drive and Ubuntu 14.04 LTS (Linux)

- CentOS 6.5 opens the Xmanager Remote Desktop login (Linux)

- Ubuntu 15.04 / 14.04 install Ubuntu After Install 2.6 (Linux)

 
         
  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:      
 
- Linux Command - ps: a snapshot of the current process (Linux)
- MongoDB uses aggregate, group, match mysql achieve in having (count (1)> 1) features (Database)
- Linux command line under HTTP traffic sniffing tool: httpry (Linux)
- Denyhosts prevent hackers using SSH scanning (Linux)
- Job achieve automation in Ubuntu 14.04 - Using Cron (Linux)
- Simple configuration shell scripts virtual machine environment experiment (Linux)
- CentOS7 build GlusterFS (Linux)
- MySQL multi-master-slave synchronization (Database)
- Vim useful plugin: YouCompleteMe (Linux)
- How to find out a Unix system library files are 32-bit or 64-bit (Linux)
- To create a secure network firewall with iptables Under Linux (Linux)
- Installation and use GAMIT / GLOBK Software (Linux)
- SSH service configuration to use a certificate login Linux server (Server)
- Oracle 12C modify spfile path (Database)
- shell script: a key to install LAMP, LNMP script (Server)
- Analysis of Java exception (Programming)
- CentOS 6.4 install and configure Squid Proxy Server (Linux)
- Linux operating system, the internal and external security overview (Linux)
- Interesting example of Linux Sort command (Linux)
- Linux boot process and run level (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.