Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ C ++ complex class of operator overloading     - VMware virtual machine operating system log Error in the RPC receive loop resolve (Linux)

- iSCSI + multipath achieve DM multipath storage (Server)

- There is sort of a directed acyclic graph topology (Programming)

- Repair fatal error in Linux: lame / lame.h: No such file or dir Error (Linux)

- Check the Linux server performance with ten or so commands in a minute (Server)

- Paint with Vim (Linux)

- linux system optimization and security configuration (Linux)

- Linux, modify / retrieve the root password (Linux)

- Hibernate in profile (Database)

- Firewall chapter of Linux server security configuration (Linux)

- OpenStack / Dev stack with neutron on Ubuntu 14.04 (Server)

- Eclipse 3.7.2 can not start solving under Ubuntu 14.04 (Linux)

- Java proxy mode (Programming)

- Java8 Lambda expressions and flow operations (Programming)

- Ubuntu users to install voice switch instructs the applet (Linux)

- FileZilla FTP && TLS connection settings of (Linux)

- Install the latest ATI / Nvidia graphics driver on Ubuntu (Linux)

- CentOS7 install MySQL 5.5 (Database)

- SecureCRT use the configuration detailed tutorial (Linux)

- ASM Management - How to Rename diskgroup (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:      
 
- 256 with rich colors decorate your terminal (Linux)
- Getting Started with Linux: Learn how to upgrade Docker in Ubuntu (Server)
- Ubuntu 15.04 install Complete Guide (Linux)
- Security implementation of disk data protection under Linux (Linux)
- Bad name two variables (Linux)
- Cobbler automatic mass deployment of CentOS 6 and CentOS 7 (Linux)
- Linux, Chrome browser font settings beautification (Linux)
- MNIST presentation and database conversion (Database)
- How to achieve SSH without password login (Server)
- Oracle Linux 5.5 (64bit) Install Oracle 11gR2 RAC detailed tutorial (Database)
- Oracle rebuild index script (Database)
- You may not know the Linux command-line network monitoring tool (Linux)
- Linux package management operations Basic entry (Linux)
- 6 common PHP security attacks (Linux)
- Apache Spark1.1.0 deployment and development environment to build (Server)
- Prevent security threats caused Rootkit (Linux)
- Embedded Linux to solve the problem in the time zone (Linux)
- SUSE Linux install Oracle 10g and problem solving (Linux)
- Linux compiler installation Redis (Database)
- ARM runtime environment built from scratch using QEMU emulator (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.