Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef TCOMPLEX_H
- #define TCOMPLEX_H
- #include "tanumber.h"
- class TComplex : public TANumber
- {
- public:
- explicit TComplex() : real(0), imaginary(0) {}
- TComplex(double real, double imaginary) : real(real), imaginary(imaginary)
- {}
- TComplex(std::string complexString)
- {
- try {
- size_t pos = complexString.find("+i*");
- int k = 1;
- if (pos == std::string::npos) {
- pos = complexString.find("-i*");
- k = -1;
- }
- if (pos == std::string::npos) {
- real = std::stod(complexString);
- imaginary = 0;
- }
- else {
- real = std::stod(complexString.substr(0, pos));
- imaginary = std::stod(complexString.substr(pos + 3)) * k;
- }
- }
- catch (...) {
- real = 0;
- imaginary = 0;
- }
- }
- ~TComplex()
- {}
- TComplex* summ(TComplex *firstComplex, TComplex *secondComplex);
- TComplex* substract(TComplex firstComplex, TComplex secondComplex) override;
- TComplex* mult(TComplex firstComplex, TComplex secondComplex) override;
- TComplex* divide(TComplex firstComplex, TComplex secondComplex) override;
- TComplex square(TComplex complex);
- TComplex reverse(TComplex complex);
- TComplex power(int index);
- std::string getNumberAsString() override;
- private:
- double real;
- double imaginary;
- };
- #endif // TCOMPLEX_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement