-
Notifications
You must be signed in to change notification settings - Fork 0
/
OOP_1.cpp
61 lines (47 loc) · 1.17 KB
/
OOP_1.cpp
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
#include <bits/stdc++.h>
using namespace std;
// simple class creation
class ComplexNumbers {
private:
int real;
int imaginary;
public:
// Constructor
ComplexNumbers(int r,int i){
real=r;
imaginary=i;
}
// Member functions
void print(){
cout<<real<<' '<<'+'<<' '<<'i'<<imaginary<<endl;
}
void plus(ComplexNumbers const &c2){
real=real+c2.real;
imaginary=imaginary+c2.imaginary;
}
void multiply(ComplexNumbers const & c2){
int r=real*(c2.real)-imaginary*(c2.imaginary);
imaginary=real*(c2.imaginary)+imaginary*(c2.real);
real=r;
}
};
int main() {
int real1, imaginary1, real2, imaginary2;
cin >> real1 >> imaginary1;
cin >> real2 >> imaginary2;
ComplexNumbers c1(real1, imaginary1);
ComplexNumbers c2(real2, imaginary2);
int choice;
cin >> choice;
if(choice == 1) {
c1.plus(c2);
c1.print();
}
else if(choice == 2) {
c1.multiply(c2);
c1.print();
}
else {
return 0;
}
}