Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <typename T>
  5. class My_Point {
  6. T x;
  7. T y;
  8. public:
  9. My_Point(T x, T y) : x(x), y(y) {};
  10. My_Point() {
  11. string wyjatek = "Wyjatek!";
  12. throw wyjatek;
  13. }
  14. T X() {
  15. return x;
  16. }
  17. T Y() {
  18. return y;
  19. }
  20. };
  21.  
  22.  
  23. template <typename T>
  24. class My_Vector {
  25. My_Point<T>* a;
  26. My_Point<T>* b;
  27. public:
  28. My_Vector() {
  29. std::string wyjatek = "Konstruktor domyslny Vector!";
  30. throw wyjatek;
  31. }
  32. My_Vector(My_Point<T> &a, My_Point<T> &b) {
  33.  
  34. this->a = new My_Point<T>(a.X(), a.Y());
  35. this->b = new My_Point<T>(b.X(), b.Y());
  36. }
  37. ~My_Vector() {
  38. delete a;
  39. delete b;
  40. }
  41.  
  42. double dlugosc() {
  43. return sqrt(pow((a->X() - b->X()), 2) + pow((a->Y() - b->Y()), 2));
  44. }
  45.  
  46. T getX() {
  47. return a->X();
  48. }
  49. T getY() {
  50. return a->Y();
  51. }
  52. T getXb() {
  53. return b->X();
  54. }
  55. T getYb() {
  56. return b->Y();
  57. }
  58.  
  59. double iloczyn(My_Vector<T> &R, My_Vector<T> &M) {
  60. return ((R.getXb() - R.getX())*(M.getXb() - M.getX())) + ((R.getYb() - R.getY())*(M.getYb() - M.getY()));
  61. }
  62. };
  63.  
  64.  
  65. int main()
  66. {
  67. My_Point<int> A(1, 2);
  68. My_Point<int> B(3, 5);
  69.  
  70. My_Point<int> A1(1, 2);
  71. My_Point<int> B1(1, 2);
  72.  
  73. My_Vector<int> C(A, B);
  74. My_Vector<int> D(A1, B1);
  75.  
  76. double g;
  77. double h;
  78. double j;
  79. g = C.dlugosc();
  80. h = D.dlugosc();
  81. j = C.iloczyn(C, D);
  82.  
  83. cout << "Dlugosc wektora 1: " << g << "\n";
  84. cout << "Dlugosc wektora 2: " << h << "\n";
  85. cout << "Iloczyn skalarny: " << j << "\n";
  86.  
  87. return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement