-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclasses
31 lines (25 loc) · 1000 Bytes
/
classes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* This is testing about book <The C++ Programming Language>
* 3.2 Classes
* The central language feature of C++ is the class
*/
#include <iostream>
using namespace std;
class complex {
double re, im; // representation: two doubles
public:
complex(double r, double i) :re{r}, im{i} {} // construct complex from two scalars
complex(double r) :re{r}, im{0} {} // construct complex from one scalar
complex() :re{0}, im{0} {} // default complex: {0,0}
double real() const { return re; }
void real(double d) { re=d; }
double imag() const { return im; }
void imag(double d) { im=d; }
complex& operator+=(complex z) { re+=z.re, im+=z.im; return *this; } // add to re and im
complex& operator-=(complex z) { re-=z.re, im-=z.im; return *this; }
complex& operator*=(complex); // defined out-of-class somewhere
complex& operator/=(complex); // defined out-of-class somewhere
};
int main() {
// your code goes here
return 0;
}