Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.20 KB | None | 0 0
  1. #include <iostream>
  2. #include "Rectangle.h"
  3. #include "MathObject.h"
  4.  
  5.  
  6. using namespace std;
  7.  
  8.  
  9. // Constructors
  10.  
  11. Rectangle::Rectangle() {
  12. //memset(angleCoordinates, 0, sizeof(angleCoordinates[0][0]) * 4 * 2);
  13. //setAllAnglesCoordinatesByHand();
  14. angleCoordinates[0][0] = 0;
  15. angleCoordinates[0][1] = 0;
  16. angleCoordinates[1][0] = 0;
  17. angleCoordinates[1][1] = 0;
  18. angleCoordinates[2][0] = 0;
  19. angleCoordinates[2][1] = 0;
  20. angleCoordinates[3][0] = 0;
  21. angleCoordinates[3][1] = 0;
  22. }
  23.  
  24. Rectangle::Rectangle(double leftTopAngleX, double leftTopAngleY, double leftBottomAngleX, double leftBottomAngleY,
  25. double rightTopAngleX, double rightTopAngleY, double rightBottomAngleX, double rightBottomAngleY) {
  26.  
  27. angleCoordinates[0][0] = leftTopAngleX;
  28. angleCoordinates[0][1] = leftTopAngleY;
  29. angleCoordinates[1][0] = leftBottomAngleX;
  30. angleCoordinates[1][1] = leftBottomAngleY;
  31. angleCoordinates[2][0] = rightTopAngleX;
  32. angleCoordinates[2][1] = rightTopAngleY;
  33. angleCoordinates[3][0] = rightBottomAngleX;
  34. angleCoordinates[3][1] = rightBottomAngleY;
  35.  
  36. if (checkAngleCoordinates() == false) {
  37. cout << "Fill in coordinates correctly please !" << endl;
  38. system("pause");
  39. }
  40. else {
  41. system("CLS");
  42. cout << "Your entered correct coordinates for rectangle !" << endl;
  43. system("pause");
  44. printSideValue();
  45. printBottomValue();
  46. setArea();
  47. printArea();
  48. printCounter();
  49. system("pause");
  50. }
  51.  
  52. }
  53.  
  54. // Changing all values
  55.  
  56. // by hand
  57. void Rectangle::setAllAnglesCoordinatesByHand() {
  58. system("CLS");
  59. cout << "Iveskite virsutiniojo kairiojo kampo koordinate x : ";
  60. cin >> angleCoordinates[0][0];
  61. cout << "Iveskite virsutiniojo kairiojo kampo koordinate y : ";
  62. cin >> angleCoordinates[0][1];
  63. cout << "Iveskite apatiniojo kairiojo kampo koordinate x : ";
  64. cin >> angleCoordinates[1][0];
  65. cout << "Iveskite apatiniojo kairiojo kampo koordinate y : ";
  66. cin >> angleCoordinates[1][1];
  67. cout << "Iveskite virsutiniojo desniojo kampo koordinate x : ";
  68. cin >> angleCoordinates[2][0];
  69. cout << "Iveskite virsutiniojo desniojo kampo koordinate y : ";
  70. cin >> angleCoordinates[2][1];
  71. cout << "Iveskite apatiniojo desniojo kampo koordinate x : ";
  72. cin >> angleCoordinates[3][0];
  73. cout << "Iveskite apatiniojo desniojo kampo koordinate y : ";
  74. cin >> angleCoordinates[3][1];
  75.  
  76. if (checkAngleCoordinates() == false) {
  77. cout << "Fill in coordinates correctly please !" << endl;
  78. system("pause");
  79. }
  80. else {
  81. system("CLS");
  82. cout << "Your entered correct coordinates for rectangle !" << endl;
  83. system("pause");
  84. printSideValue();
  85. printBottomValue();
  86. printArea();
  87. system("pause");
  88. }
  89. }
  90.  
  91. // Checking if values inserted correctly
  92. bool Rectangle::checkAngleCoordinates() {
  93.  
  94. bool check = true;
  95.  
  96. if (angleCoordinates[0][0] != angleCoordinates[1][0] & angleCoordinates[0][1] <= angleCoordinates[1][1]) {
  97. return false;
  98. }
  99. if (angleCoordinates[2][0] != angleCoordinates[3][0] & angleCoordinates[2][1] <= angleCoordinates[3][1]) {
  100. return false;
  101. }
  102. if (angleCoordinates[0][1] != angleCoordinates[2][1] & angleCoordinates[2][0] <= angleCoordinates[0][0]) {
  103. return false;
  104. }
  105. if (angleCoordinates[1][1] != angleCoordinates[3][1] & angleCoordinates[3][0] <= angleCoordinates[1][0]) {
  106. return false;
  107. }
  108.  
  109. return check;
  110. }
  111.  
  112. //Calculations
  113.  
  114. //Getters
  115. double Rectangle::getBottomValue() {
  116.  
  117. double bottomValue = sqrt(pow(angleCoordinates[3][0] - angleCoordinates[1][0], 2) + pow(angleCoordinates[3][1] - angleCoordinates[1][1], 2));
  118. return bottomValue;
  119. }
  120.  
  121. double Rectangle::getSideValue() {
  122. double sideValue = sqrt(pow(angleCoordinates[0][0] - angleCoordinates[1][0], 2) + pow(angleCoordinates[0][1] - angleCoordinates[1][1], 2));
  123. return sideValue;
  124. }
  125.  
  126. double Rectangle::getArea() {
  127. return area;
  128. }
  129. // Setters
  130. void Rectangle::setArea() {
  131. area = pow(getSideValue()) + pow(getBottomValue());
  132. }
  133.  
  134. // Printing values
  135. void Rectangle::printAngleCoordinates() {
  136.  
  137. for (int i = 0; i < 4; i++) {
  138.  
  139. for (int j = 0; j < 2; j++) {
  140. cout << angleCoordinates[i][j];
  141. }
  142.  
  143. cout << endl;
  144.  
  145. }
  146. }
  147.  
  148. void Rectangle::printBottomValue() {
  149. cout << "Bottom value side is : " << getBottomValue() << endl;
  150. }
  151.  
  152. void Rectangle::printSideValue() {
  153. cout << "Side value is : " << getSideValue() << endl;
  154. }
  155.  
  156. void Rectangle::printArea() {
  157. cout << "Area value is : " << getArea() << endl;
  158. }
  159.  
  160. void Rectangle::printCounter() {
  161. cout << "Your object number is : " << getCount() << endl;
  162. }
  163.  
  164. // OPERATOR OVERLOAD
  165.  
  166. void Rectangle::operator++() {
  167.  
  168. /*
  169. for (int i = 0; i < 4; i++){
  170. for (int j = 0; j < 2; j++)
  171. {
  172. ++angleCoordinates[i][j];
  173. }
  174.  
  175. }
  176. */
  177. area++;
  178. }
  179.  
  180. Rectangle operator+(Rectangle op1, Rectangle op2) {
  181. Rectangle temp;
  182. for (int i = 0; i < 4; i++) {
  183. for (int j = 0; j < 2; j++){
  184. temp.angleCoordinates[i][j] = op1.angleCoordinates[i][j] + op2.angleCoordinates[i][j];
  185. }
  186. }
  187.  
  188. temp.setArea();
  189.  
  190. return temp;
  191. }
  192.  
  193. Rectangle Rectangle::operator= (Rectangle op1) {
  194.  
  195. for (int i = 0; i < 4; i++) {
  196. for (int j = 0; j < 2; j++) {
  197. angleCoordinates[i][j] = op1.angleCoordinates[i][j];
  198. }
  199. }
  200.  
  201. setArea();
  202.  
  203. return *this;
  204. }
  205.  
  206. bool Rectangle:: operator==(Rectangle op1) {
  207. if (getArea() == op1.getArea()) return true;
  208. else return false;
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement