Skip to content

Instantly share code, notes, and snippets.

@bojieli
Last active August 29, 2015 14:20
Show Gist options
  • Save bojieli/ed62d6559ee23832869e to your computer and use it in GitHub Desktop.
Save bojieli/ed62d6559ee23832869e to your computer and use it in GitHub Desktop.
Exercise 1-2
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