-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex.cpp
More file actions
69 lines (56 loc) · 885 Bytes
/
complex.cpp
File metadata and controls
69 lines (56 loc) · 885 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <sys/types.h>
#include <ctype.h>
#include <stdint.h>
#include<iostream>
#include <typeinfo>
using namespace std;
class complex
{
public:
double real;
double im;
//int a[10];
~complex()
{
printf("%f+%fiexit~\n",real,im);
}
complex()
{
printf("init\n");
}
complex(int r,int i)
{
real=r;
im=i;
printf("%f+%fiinit~\n",real,im);
}
complex operator + (const complex &k) {
complex c(real + k.real,im+k.im);
printf("inner class\n");
return c;
}
void operator += (const complex &k) {
this->real += k.real;
this->im += k.im;
printf("inner class\n");
return ;
}
};
void test()
{
complex a(3,9);
complex b(2,-3);
complex c=a+b;
if(c.real==5 && c.im==6)
printf("OK\n");
else printf("ERROR\n");
a+=b;
if(a.real==5 && a.im==6)
printf("OK\n");
else printf("ERROR\n");
}
int main(){
test();
return 0;
}