Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ C ++ complex class of operator overloading     - Linux Platform Oracle 11g Single Instance Installation Deployment Configuration Quick Reference (Database)

- osprofiler use OpenStack Cinder Lane (Server)

- How to generate Linux, random password encryption or decryption (Linux)

- Linux into single user mode to modify the administrator password (Linux)

- Three strategies to teach you to release the device memory (Linux)

- Linux rename command usage in learning to modify the file name (Linux)

- Oracle data row split multiple lines (Database)

- Basic Java JNI (Programming)

- KVM usb passthrough configuration (Linux)

- Java garbage collection (Programming)

- Delete specific files using bash directory under Linux (Linux)

- CentOS7 + Redis Live Installation and Configuration (Linux)

- Use netcat [nc] command on Linux and Unix port scan (Server)

- Linux basic articles of the boot process (Linux)

- Java String type time compare the size (Programming)

- Linux systems use logwatch log file monitoring (Linux)

- Getting Started with Linux system to learn: how to install autossh (Linux)

- CentOS yum configuration under local sources (Linux)

- About Auto Layout and frame (Programming)

- Oracle how to maintain the consistency of read? (Database)

 
         
  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:      
 
- PostgreSQL-- run Supervisord on Docker in Ubuntu (Database)
- Oracle Standby Redo Log experiment (Database)
- Getting Started with Linux system to learn: how to get the process ID (PID) in the script (Linux)
- Linux system security Comments (Linux)
- Ubuntu update bug fixes Daquan (Linux)
- Oracle utilized undo data recovery operations (Database)
- Linux AS4 VPN server in conjunction with a firewall perfect (Linux)
- Android Fragment everything you need to know (Programming)
- Spring Data JPA @EnableJpaRepositories configuration in detail (Programming)
- Ubuntu is expected to allow you to install the latest Nvidia Linux drivers easier (Linux)
- Installation salt-minion on RHEL5 (Linux)
- The Gitlab migrated to Docker container (Server)
- FFmpeg compiled with only H264 decoding library (Programming)
- Ubuntu Linux use ufw or iptables firewall configuration (Linux)
- Circular list of Java programming (Programming)
- About MongoDB query method according to fuzzy field (Database)
- ElasticSearch basic usage and cluster structures (Server)
- Use a soft Raid play multiple SSD hard drive performance and enhance data security (Linux)
- Use the command line MySQL database backup and recovery (Database)
- Linux firewall settings instance (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.