Last active
August 29, 2015 14:20
-
-
Save bojieli/ed62d6559ee23832869e to your computer and use it in GitHub Desktop.
Exercise 1-2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using namespace std; | |
#include <iostream> | |
class Complex { | |
private: | |
double real; | |
double im; | |
public: | |
Complex(double real, double im) { | |
this->real = real; | |
this->im = im; | |
} | |
Complex(double real) { | |
this->real = real; | |
this->im = 0; | |
} | |
void add(Complex c) { | |
this->real += c.real; | |
this->im += c.im; | |
} | |
void show(void) { | |
cout << this->real << "+" << this->im << "i" << endl; | |
} | |
}; | |
int main() { | |
Complex c1(3,5); | |
Complex c2 = 4.5; | |
c1.add(c2); | |
c1.show(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment