Guest User

Untitled

a guest
Jan 5th, 2011
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.59 KB | None | 0 0
  1. #pragma once
  2. #include <vector>
  3. #include <iostream>
  4.  
  5. //a+bi
  6. struct Complex{
  7.     double a, b;
  8.     Complex(double a, double b);
  9.     Complex(double a);
  10.     Complex();
  11. };
  12.  
  13. Complex operator + (Complex A, Complex B);
  14. Complex operator - (Complex A, Complex B);
  15. Complex operator * (Complex A, Complex B);
  16. Complex operator / (Complex A, Complex B);
  17. bool operator == (Complex A, Complex B);
  18.  
  19. std::ostream& operator << (std::ostream& out, Complex c);
  20.  
  21. struct Base;
  22.  
  23. //smart ptr
  24. struct Element{
  25.     Base* b;
  26.     int* ref;
  27.  
  28.     Element();
  29.     Element(Base* b);
  30.     Element(const Element& e);
  31.  
  32.     ~Element();
  33.  
  34.     Element& operator = (const Element& e);
  35.  
  36.     void rem();
  37. };
  38.  
  39. struct Base{
  40.     virtual enum Type{ number, x, mono, poly } type() = 0;
  41.     virtual void print(std::ostream& out) = 0;
  42.     virtual Element simplify() = 0;
  43.    
  44.     virtual Complex eval(Complex x) = 0;
  45.     virtual std::vector<Complex> solve() = 0;
  46.  
  47.     virtual Element coefficient() = 0;
  48.     virtual unsigned degree() = 0;
  49.  
  50.     virtual ~Base(){};
  51. };
  52.  
  53. typedef Element (*Operator) (Element, Element);
  54. Element operator + (Element a, Element b);
  55. Element operator * (Element a, Element b);
  56. Element operator / (Element a, Element b);
  57.  
  58. std::ostream& operator << (std::ostream& out, Element);
  59.  
  60. //rational constant
  61. struct Number : Base{
  62.     int num;
  63.     unsigned den;
  64.  
  65.     Number();
  66.     Number(int i);
  67.     Number(int n, int d);
  68.     Number(const char*& str);
  69.  
  70.     int gcd(int a, int b);
  71.  
  72.     Element simplify();
  73.     Base::Type type();
  74.     void print(std::ostream& out);
  75.  
  76.     Complex eval(Complex x);
  77.     std::vector<Complex> solve();
  78.  
  79.     Element coefficient();
  80.     unsigned degree();
  81. };
  82.  
  83. //variable
  84. struct X : Base{
  85.     X();
  86.     X(const char*& str);
  87.  
  88.     Element simplify();
  89.     Base::Type type();
  90.     void print(std::ostream& out);
  91.  
  92.     Complex eval(Complex x);
  93.     std::vector<Complex> solve();
  94.  
  95.     Element coefficient();
  96.     unsigned degree();
  97. };
  98.  
  99. //monomial
  100. struct Mono : Base{
  101.     std::vector<Element> num;
  102.     std::vector<Element> den;
  103.  
  104.     Mono();
  105.     Mono(const char*& str);
  106.    
  107.     Element simplify();
  108.     Base::Type type();
  109.     void print(std::ostream& out);
  110.  
  111.     Complex eval(Complex x);
  112.     std::vector<Complex> solve();
  113.  
  114.     Element coefficient();
  115.     unsigned degree();
  116. };
  117.  
  118. //polynomial
  119. struct Poly : Base{
  120.     std::vector<Element> num;
  121.  
  122.     Poly();
  123.     Poly(const char*& str);
  124.  
  125.     Element simplify();
  126.     Base::Type type();
  127.     void print(std::ostream& out);
  128.  
  129.     Complex eval(Complex x);
  130.     std::vector<Complex> solve();
  131.  
  132.     Element coefficient();
  133.     unsigned degree();
  134. };
  135.  
  136. //a construct to deal with parsing and solving more comfortably.
  137. struct Equation{
  138.     Element e;
  139.  
  140.     Equation(const char* str);
  141.     std::vector<Complex> solve();
  142. };
Advertisement
Add Comment
Please, Sign In to add comment