Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ C ++ complex class of operator overloading     - Build their own recursive DNS server (Server)

- How to install Git client in Ubuntu (Linux)

- How to Install Sticky Notes on Ubuntu and Derivatives (Linux)

- Detailed iptables (Linux)

- Linux Live CD lets your PC is no longer secure (Linux)

- Close common port to protect server security (Linux)

- CentOS 7 Add yum source (Linux)

- RAID disk array Description (Linux)

- Vi editor Introduction (Linux)

- Build and verify MongoDB3.0.7 version (shard + replica) Cluster (Database)

- Oracle database on the hit rate of query summary (Database)

- Vim (Linux)

- JavaScript in this usage (Programming)

- Recovery from MySQL master data consistency summary (Database)

- Under Ubuntu 15.04 installation JDK8 (Linux)

- Ubuntu FAQ solutions (Linux)

- PL / SQL data types (Database)

- Java NIO2: Buffer (Programming)

- Use PXE with kickstart to install Linux automatically (Linux)

- C # how to generate a folder or file automatically rename (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:      
 
- Java Adapter Mode (Programming)
- Ubuntu users Steam controller does not work solutions (Linux)
- LVM basic concepts, management (Linux)
- DataGuard the MRP can not start to analyze and solve problems (Database)
- Linux dynamic libraries and Guide (Programming)
- Ubuntu users to install Gnome-Pie 0.6.5 (Linux)
- Use cmake to compile and install MySQL 5.5 (Database)
- Linux, how to filter, split, and merge pcap file (Linux)
- Oracle () trunc function usage (Database)
- Linux System Getting Started Learning: rename multiple files in Linux (Linux)
- Linux vi command list (Linux)
- Echo Command Examples (Linux)
- Linux RPM default installation path (Linux)
- Linux System Getting Started Tutorial: Installing Git on Linux (Linux)
- File easier to compare tools under Linux (Linux)
- Ubuntu 14.04 build Android 5.1 development environment and compiler (Linux)
- String JavaScript type system (Programming)
- DVD production using CentOS installation source within the company Yum (Linux)
- tar decompression problems gzip: stdin: not in gzip format (Linux)
- Ubuntu 32 compile Android 4.0.4 Problems (Linux)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.