Advertisement
Guest User

Untitled

a guest
May 21st, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. #include <iostream>
  2. #include "Triangle.h"
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. Triangle T1;
  8. T1.a = 2;
  9. T1.b = 3;
  10. T1.c = 4;
  11. T1.print();
  12. Triangle *T2 = new Triangle(3 , 4, 5);
  13. T2->print();
  14. cout << "Obwod = " << T2->circuit() << endl;;
  15.  
  16. Point A, B, C;
  17. A.x = 1; A.y = 2;
  18. B.x = 5; B.y = 4;
  19. C.x = 3; C.y = -2;
  20.  
  21. Triangle *T3 = new Triangle(A, B, C);
  22. T3->print();
  23.  
  24. Triangle *T4 = new Triangle(Point(1,2), Point(5,4), Point(3,-2));
  25. T4->print();
  26. cout << "Pole: " << T4->area();
  27. return 0;
  28. }
  29.  
  30. ---------------------------------------------------------------------------------------
  31.  
  32. #ifndef TRIANGLE_H
  33. #define TRIANGLE_H
  34. #include "Point.h"
  35.  
  36. class Triangle
  37. {
  38. public:
  39. double a;
  40. double b;
  41. double c;
  42.  
  43. public:
  44. Triangle();
  45. Triangle(double a, double b, double c);
  46. Triangle(Point A, Point B, Point C);
  47. ~Triangle();
  48. void print();
  49. double circuit();
  50. static double section(Point A, Point B);
  51. double area();
  52. protected:
  53.  
  54. private:
  55. };
  56.  
  57. #endif // TRIANGLE_H
  58.  
  59. ------------------------------------------------------------------------------------
  60.  
  61. #include "Triangle.h"
  62. #include <iostream>
  63. #include <cmath>
  64.  
  65. using namespace std;
  66.  
  67. Triangle::Triangle()
  68. {
  69. //ctor
  70. }
  71.  
  72. Triangle::Triangle(double a, double b, double c)
  73. {
  74. this->a = a;
  75. this->b = b;
  76. this->c = c;
  77. }
  78.  
  79. Triangle::Triangle(Point A, Point B, Point C)
  80. {
  81. a = section(A,B);
  82. b = section(A,C);
  83. c = section(B,C);
  84. }
  85.  
  86. Triangle::~Triangle()
  87. {
  88. //dtor
  89. }
  90. void Triangle::print()
  91. {
  92. cout << "Trojkat o bokach: " << a << ", " << b << ", " << c << endl;
  93. }
  94.  
  95. double Triangle::circuit()
  96. {
  97. return a+b+c;
  98. }
  99.  
  100. double Triangle::section(Point A, Point B)
  101. {
  102. return sqrt(pow(B.x-A.x,2) + pow(B.y-A.y,2));
  103. }
  104.  
  105. double Triangle::area()
  106. {
  107. double p =(a+b+c)/2;
  108. return sqrt(p*(p-a)*(p-b)*(p-c));
  109. }
  110.  
  111. ---------------------------------------------------------------------------
  112.  
  113. #ifndef POINT_H
  114. #define POINT_H
  115.  
  116.  
  117. class Point
  118. {
  119. public:
  120. int x;
  121. int y;
  122.  
  123. public:
  124. Point();
  125. Point(int x, int y);
  126. ~Point();
  127.  
  128. };
  129.  
  130. #endif // POINT_H
  131.  
  132. -----------------------------------------------------------------------------
  133.  
  134. #include "Point.h"
  135.  
  136. Point::Point()
  137. {
  138. x = 0;
  139. y = 0;
  140. }
  141. Point::Point(int x, int y)
  142. {
  143. this->x = x;
  144. this->y = y;
  145. }
  146. Point::~Point()
  147. {
  148. //dtor
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement