Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ C ++ complex class of operator overloading     - RabbitMQ tutorial examples: RabbitMQ installation under Windows (Linux)

- ARM runtime environment built from scratch using QEMU emulator (Linux)

- To resolve Ubuntu 14.04 Unity Desktop Environment Login freeze problem (Linux)

- How to install GIMP 2.8.16 in Ubuntu 16.04,15.10,14.04 (Linux)

- How to configure FirewallD in RHEL / CentOS 7 and Fedora in (Linux)

- Laravel 4 Expansion Pack (Server)

- The Hill sorting algorithm (Programming)

- Oracle physical storage structure outline (Database)

- OpenJDK 7 compiled under Ubuntu 14.04.3 64-bit (Linux)

- Shell script to crawl through AWR SQL Report Problems (Database)

- Ubuntu 15.04 / CentOS 7.0 to set custom boot (Linux)

- Awk include binding capacity larger than the specified size of all files directory (Linux)

- MySQL is configured to access external networks under Ubuntu (Database)

- Node.js v4.0.0 installation configuration on Ubuntu 14.04 / 15.04 (Linux)

- Appweb configuration in detail (Server)

- Linux scp remote file copy (Linux)

- To achieve Linux Security (Linux)

- Udev: Device Manager for Linux Fundamentals (Linux)

- How do I use Linux development environment (Linux)

- Linux simple commands (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:      
 
- Java thread pool: ExecutorService, Executors (Programming)
- Node.js developers must know four JavaScript concepts (Programming)
- LogStash log analysis display system (Linux)
- CentOS 6.x systems installation + NIC driver installation (Realtek PCIe GBE Family Controller for Linux) (Linux)
- Varnish achieve page jump (Server)
- Install Xshell on Mac OS X (Linux)
- To install the Ubuntu Touch emulator on Ubuntu (Linux)
- Iptables Instructions (Linux)
- CentOS directory structure Explanation (Linux)
- Ubuntu study notes and related problem solving (Linux)
- Ubuntu install video playback software SMPlayer 14.9.0.7042 (Linux)
- Linux Security Raiders SSH tools SCP uses examples to explain in detail (Linux)
- Ubuntu Server 14.04 installation Web server (Linux + Apache + MySQL + PHP) (Server)
- High-performance JavaScript reflows and repaints (Programming)
- Not safe procedure under Linux (Linux)
- Installation and Configuration Tomcat environment CentOS 6.6 (Server)
- Ubuntu 14.10 installation GNOME 3.14 (Linux)
- Redmine Installation (Linux)
- Linux file system (inode and block) (Linux)
- Ansible installation configuration and simple to use (Server)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.