fork download
  1. #include "header.h"
  2.  
  3. //Przypisanie wartości wprowadzonych do elementow kwaternionu
  4. Quaternion::Quaternion(int a, int b, int c, int d)
  5. {
  6. Dfactor = d;
  7. Afactor = a;
  8. Bfactor = b;
  9. Cfactor = c;
  10. }
  11. //Algebraiczne dodawanie dwoch kwaternionow
  12. Quaternion Quaternion::operator+(Quaternion&q){
  13. Quaternion q2(q.Afactor + this->Afactor, q.Bfactor + this->Bfactor, q.Cfactor + this->Cfactor, q.Dfactor + this->Dfactor);
  14. return q2;
  15. }
  16. //Algebraiczne odejmowanie dwoch kwaternionow
  17. Quaternion Quaternion::operator-(Quaternion&q){
  18. Quaternion q2(q.Afactor - this->Afactor, q.Bfactor - this->Bfactor, q.Cfactor - this->Cfactor, q.Dfactor - this->Dfactor);
  19. return q2;
  20. }
  21. //Algebraiczne dodawanie drugiego kwaternionu do pierwszego
  22. Quaternion& Quaternion::operator+=(Quaternion&q){
  23. this->Afactor += q.Afactor;
  24. this->Bfactor += q.Bfactor;
  25. this->Cfactor += q.Cfactor;
  26. this->Dfactor += q.Dfactor;
  27. return *this;
  28. }
  29. //Algebraiczne odejmowanie drugiego kwaternionu od pierwszego
  30. Quaternion& Quaternion::operator-=(Quaternion&q){
  31. this->Afactor -= q.Afactor;
  32. this->Bfactor -= q.Bfactor;
  33. this->Cfactor -= q.Cfactor;
  34. this->Dfactor -= q.Dfactor;
  35. return *this;
  36. }
  37. //Algebraiczne mnozenie kwaternionow
  38. Quaternion Quaternion::operator*(Quaternion&q){
  39. Quaternion q2(0,0,0,0);
  40. q2.Afactor = q.Afactor * this->Dfactor + q.Dfactor * this->Afactor - q.Bfactor * this->Cfactor - q.Cfactor * this->Bfactor;
  41. q2.Bfactor = q.Bfactor * this->Dfactor + q.Dfactor * this->Bfactor - q.Afactor * this->Cfactor - q.Cfactor * this->Afactor;
  42. q2.Cfactor = q.Cfactor * this->Dfactor + q.Dfactor * this->Cfactor - q.Bfactor * this->Afactor - q.Afactor * this->Bfactor;
  43. q2.Dfactor = q.Dfactor * this->Dfactor - q.Afactor * this->Afactor - q.Bfactor * this->Bfactor - q.Cfactor * this->Cfactor;
  44. return q2;
  45. }
  46. //algebraiczne domnazanie kwaternionu drugiego do pierwszego
  47. Quaternion& Quaternion::operator*=(Quaternion&q){
  48. this->Afactor = q.Afactor * this->Dfactor + q.Dfactor * this->Afactor - q.Bfactor * this->Cfactor - q.Cfactor * this->Bfactor;
  49. this->Bfactor = q.Bfactor * this->Dfactor + q.Dfactor * this->Bfactor - q.Afactor * this->Cfactor - q.Cfactor * this->Afactor;
  50. this->Cfactor = q.Cfactor * this->Dfactor + q.Dfactor * this->Cfactor - q.Bfactor * this->Afactor - q.Afactor * this->Bfactor;
  51. this->Dfactor = q.Dfactor * this->Dfactor - q.Afactor * this->Afactor - q.Bfactor * this->Bfactor - q.Cfactor * this->Cfactor;
  52. return *this;
  53. }
  54. //Algebraiczne wyznaczanie modulu
  55. double Quaternion::module(){
  56. return sqrt(this->Afactor * this->Afactor + this->Bfactor * this->Bfactor + this->Cfactor * this->Cfactor + this->Dfactor * this->Dfactor);
  57. }
  58. //Wypisywanie kwaternionu w formie algebraicznej
  59. std::ostream & operator <<(std::ostream &strm, Quaternion &q){
  60. return strm << q.Afactor << "i + " << q.Bfactor << "j + " << q.Cfactor << "k + " << q.Dfactor;
  61. }
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:20: fatal error: header.h: No such file or directory
 #include "header.h"
                    ^
compilation terminated.
stdout
Standard output is empty