Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <vector>
- #include <iostream>
- //a+bi
- struct Complex{
- double a, b;
- Complex(double a, double b);
- Complex(double a);
- Complex();
- };
- Complex operator + (Complex A, Complex B);
- Complex operator - (Complex A, Complex B);
- Complex operator * (Complex A, Complex B);
- Complex operator / (Complex A, Complex B);
- bool operator == (Complex A, Complex B);
- std::ostream& operator << (std::ostream& out, Complex c);
- struct Base;
- //smart ptr
- struct Element{
- Base* b;
- int* ref;
- Element();
- Element(Base* b);
- Element(const Element& e);
- ~Element();
- Element& operator = (const Element& e);
- void rem();
- };
- struct Base{
- virtual enum Type{ number, x, mono, poly } type() = 0;
- virtual void print(std::ostream& out) = 0;
- virtual Element simplify() = 0;
- virtual Complex eval(Complex x) = 0;
- virtual std::vector<Complex> solve() = 0;
- virtual Element coefficient() = 0;
- virtual unsigned degree() = 0;
- virtual ~Base(){};
- };
- typedef Element (*Operator) (Element, Element);
- Element operator + (Element a, Element b);
- Element operator * (Element a, Element b);
- Element operator / (Element a, Element b);
- std::ostream& operator << (std::ostream& out, Element);
- //rational constant
- struct Number : Base{
- int num;
- unsigned den;
- Number();
- Number(int i);
- Number(int n, int d);
- Number(const char*& str);
- int gcd(int a, int b);
- Element simplify();
- Base::Type type();
- void print(std::ostream& out);
- Complex eval(Complex x);
- std::vector<Complex> solve();
- Element coefficient();
- unsigned degree();
- };
- //variable
- struct X : Base{
- X();
- X(const char*& str);
- Element simplify();
- Base::Type type();
- void print(std::ostream& out);
- Complex eval(Complex x);
- std::vector<Complex> solve();
- Element coefficient();
- unsigned degree();
- };
- //monomial
- struct Mono : Base{
- std::vector<Element> num;
- std::vector<Element> den;
- Mono();
- Mono(const char*& str);
- Element simplify();
- Base::Type type();
- void print(std::ostream& out);
- Complex eval(Complex x);
- std::vector<Complex> solve();
- Element coefficient();
- unsigned degree();
- };
- //polynomial
- struct Poly : Base{
- std::vector<Element> num;
- Poly();
- Poly(const char*& str);
- Element simplify();
- Base::Type type();
- void print(std::ostream& out);
- Complex eval(Complex x);
- std::vector<Complex> solve();
- Element coefficient();
- unsigned degree();
- };
- //a construct to deal with parsing and solving more comfortably.
- struct Equation{
- Element e;
- Equation(const char* str);
- std::vector<Complex> solve();
- };
Advertisement
Add Comment
Please, Sign In to add comment