Created
June 19, 2025 11:03
-
-
Save lrobidou/309bfed97825d77eadb9449e4ee0c771 to your computer and use it in GitHub Desktop.
Course material : simple implementation of complex numbers in C++
This file contains hidden or 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
#include "complex.hpp" | |
Complex::Complex(int32_t r, int32_t i) : _r(r), _i(i) {} | |
int32_t Complex::r() const { return this->_r; } | |
int32_t Complex::i() const { return this->_i; } | |
void Complex::r(int32_t r) { this->_r = r; } | |
void Complex::i(int32_t i) { this->_i = i; } | |
Complex Complex::conjugate() const { return Complex(this->_r, -this->_i); } |
This file contains hidden or 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
#ifndef STUPID_COMPLEX_H | |
#define STUPID_COMPLEX_H | |
#include <cstdint> | |
class Complex { | |
private: | |
int32_t _r; | |
int32_t _i; | |
public: | |
// constructor | |
Complex(int32_t r, int32_t i); | |
// getters | |
int32_t r() const; | |
int32_t i() const; | |
// setters | |
void r(int32_t r); | |
void i(int32_t i); | |
// methods | |
Complex conjugate() const; | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment