Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ C ++ complex class of operator overloading     - JEdit 5.2 Pro Edition installation on Ubuntu 14.04 (Linux)

- Questions about Linux compiler u-boot (Programming)

- MySQL appears data too long for column 'name' at row 1 to solve (Database)

- Modifying the system registry protection server security (Linux)

- C ++ constant definition (Programming)

- Talking about modern programming language syntax and standard library tightly bound phenomenon (Programming)

- Android main thread message system (Handler Looper) (Linux)

- Using C / C ++ extensions Python (Programming)

- Netapp storage routine inspections and information gathering (Linux)

- Ubuntu 10.10 install Oracle 10g graphic tutorials (Database)

- CentOS7 install JDK (Linux)

- Linux System Getting Started Learning: The Linux logrotate (Linux)

- RedHat6.4 installation tutorial --- Minimal Edition (Linux)

- Hadoop 2.6.0 standalone configuration and pseudo-distributed configuration under Ubuntu 14.04 (Server)

- JavaScript: understanding regular expressions (Programming)

- iOS GCD multithreading simple to use (Programming)

- Let your PHP 7 faster the Hugepage (Linux)

- How to upgrade to Oracle 11g Oracle 12c (Database)

- Java look and feel mode (Facade mode) (Programming)

- Ubuntu install video conversion tool Selene (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:      
 
- Spring Boot + Nginx + Tomcat + SSL configuration notes (Server)
- MongoDB Study Notes (1) - Install MongoDB on Windows systems (Database)
- Nagios (centreon) monitoring LVS (Server)
- Linux Command Tutorial: du command to view disk space (Linux)
- RedHat install GCC problem --- Depends (Linux)
- Docker Private Registry Installation Guide at CentOS6.X (Linux)
- Oracle 11R2 Grid Infrastructure execute root.sh script rootcrs.pl execution failed treatment (Database)
- Getting jQuery - progress bar (Programming)
- Oracle 11g dataguard main library backup and recovery to the test environment in one database error (Database)
- Oracle 11g through SCN do incremental backup repair standby library detailed process (Database)
- Git Advanced Tutorial (Linux)
- When RHEL7 use fdisk partition, all partitions can not be used (Linux)
- Java rewrite equals method (Programming)
- Oracle GoldenGate tutorial Second, configure and use (Database)
- Oracle 11g manually create a database (Database)
- Install Ruby on Rails in Ubuntu 15.04 in (Linux)
- wget command Walkthrough (Linux)
- Haproxy multi-domain certificate HTTPS (Server)
- Linux Fundamentals of the memory management mechanism (Linux)
- Tip: Use Cryptsetup U disk encryption (Linux)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.