fork download
  1. #include<iostream>
  2. #include<cmath>
  3. #include "quadrilateral.h"
  4. #include "trapezoid.h"
  5. #include "parallelogram.h"
  6. #include "rectangle.h"
  7. #include "square.h"
  8. using namespace std;
  9.  
  10. bool Equals(double xVal, double yVal)
  11. {
  12. const double epsilon = 10e-10;
  13. if(abs(xVal - yVal) <= epsilon * abs(xVal))
  14. {
  15. return true;
  16. }
  17. return false;
  18. }
  19.  
  20. int main()
  21. {
  22. double a1, a2, b1, b2, c1, c2, dx, dy, p1, p2, q1, q2, r1, r2, t1, t2;
  23. Point a, b, c, d, p, q, r, t;
  24. Quadrilateral quad;
  25. Trapezoid trap;
  26. Parallelogram par;
  27. Rectangle rect;
  28. Square sq;
  29. int number;
  30. //Point a(-4,-1), b(4,-1), c(4,7), d(-4,7);
  31. double s1 = b.Slope(a), s2 = c.Slope(b), s3 = d.Slope(c), s4 = a.Slope(d);
  32. double d1 = a.Distance(b), d2 = b.Distance(c), d3 = c.Distance(b);
  33. double d4 = d.Distance(a);
  34.  
  35. /*cout << "Test for Point" << endl;
  36. cout << "------------------" << endl;
  37. cout << "Enter the coordinates for point p: ";
  38. cin >> p1 >> p2;
  39. p.SetAll(p1,p2);
  40. cout << "Enter the coordinates for point q: ";
  41. cin >> q1 >> q2;
  42. q.SetAll(q1,q2);
  43. cout << "Enter the coordinates for point r: ";
  44. cin >> r1 >> r2;
  45. r.SetAll(r1,r2);
  46. cout << "Enter the coordinates for point t: ";
  47. cin >> t1 >> t2;
  48. t.SetAll(t1,t2);
  49. cout << "Point p: " << "(" << p.GetX() << "," << p.GetY() << ")" << endl;
  50. cout << "Point q: " << "(" << q.GetX() << "," << q.GetY() << ")" << endl;
  51. cout << "Point r: " << "(" << r.GetX() << "," << r.GetY() << ")" << endl;
  52. cout << "Point t: " << "(" << t.GetX() << "," << t.GetY() << ")" << endl;
  53. cout << "Slope: " << q.Slope(p) << endl;
  54. cout << "Distance: " << p.Distance(q) << endl;
  55. cout << endl;
  56. if(q.Slope(p) == t.Slope(r))
  57. {
  58. cout << "Two lines are parallel lines" << endl;
  59. }
  60. else if((((q.Slope(p)) * -(r.Slope(q))) == -1)
  61. || (((q.Slope(p)) == UNDEFINED && (r.Slope(q)) == 0)
  62. || ((r.Slope(q)) == UNDEFINED && (q.Slope(p)) == 0)))
  63. {
  64. cout << "Two lines are perpendicular" << endl;
  65. }
  66. cout << endl;*/
  67. cout << "Test for different shapes" << endl;
  68. cout << "---------------------------" << endl;
  69. cout << "Enter the coordinates for the first point: ";
  70. cin >> a1 >> a2;
  71. cout << "Enter the coordinates for the second point: ";
  72. cin >> b1 >> b2;
  73. cout << "Enter the coordinates for the third point: ";
  74. cin >> c1 >> c2;
  75. cout << "Enter the coordinates for the fourth point: ";
  76. cin >> dx >> dy;
  77. quad.SetAll(a, b, c, d);
  78. trap.SetAll(a, b, c, d);
  79. par.SetAll(a, b, c, d);
  80. rect.SetAll(a, b, c, d);
  81. sq.SetAll(a, b, c, d);
  82. cout << "Enter 0 for quadrilateral, 1 for trapezoid," << endl;
  83. cout << "2 for paralleogram, 3 for rectangle, or 4 for square: ";
  84. cin >> number;
  85. if(number == 0)
  86. {
  87. quad.Print();
  88. cout << "Perimeter of quadrilateral: " << quad.Perimeter() << endl;
  89. cout << "Area of quadrilateral: " << quad.Area() << endl;
  90. }
  91. else if(number == 1)
  92. {
  93. trap.Print();
  94. if(Equals(s1,s3))
  95. {
  96. cout << "Perimeter of trapezoid: " << trap.Perimeter() << endl;
  97. cout << "Area of trapezoid: " << trap.Area() << endl;
  98. }
  99. else
  100. {
  101. cout << "The lines are not parallel." << endl;
  102. }
  103. }
  104. else if(number == 2)
  105. {
  106. par.Print();
  107. if(Equals(s1,s3) && Equals(s2,s4) && Equals(d1,d3) && Equals(d2,d4))
  108. {
  109. cout << "Perimeter of parallelogram: " << par.Perimeter() << endl;
  110. cout << "Area of parallelogram: " << par.Area() << endl;
  111. }
  112. else
  113. {
  114. cout << "The lines are not parallel or the sides" << endl;
  115. cout << "are not the same length." << endl;
  116. }
  117. }
  118. else if(number == 3)
  119. {
  120. rect.Print();
  121. if(Equals(s1,s3) && Equals(s2,s4) && Equals(d1,d3) && Equals(d2,d4)
  122. && (((s1 * -s2) == -1) || ((s1 == UNDEFINED && s2 == 0)
  123. || (s2 == UNDEFINED && s1 == 0))) && (((s2 * -s3) == -1)
  124. || ((s2 == UNDEFINED && s3 == 0) || (s3 == UNDEFINED && s2 == 0)))
  125. && (((s3 * -s4) == -1) || ((s3 == UNDEFINED && s4 == 0)
  126. || (s4 == UNDEFINED && s3 == 0))) && (((s4 * -s1) == -1)
  127. || ((s4 == UNDEFINED && s1 == 0) || (s1 == UNDEFINED && s4 == 0))))
  128. {
  129. cout << "Perimeter of rectangle: " << rect.Perimeter() << endl;
  130. cout << "Area of rectangle: " << rect.Area() << endl;
  131. }
  132. else
  133. {
  134. cout << "The lines are not parallel or the" << endl;
  135. cout << "sides are not the same length to the opposites." << endl;
  136. }
  137. }
  138. else if(number == 4)
  139. {
  140. sq.Print();
  141. if(Equals(s1,s3) && Equals(s2,s4) && Equals(d1,d2) && Equals(d1,d3)
  142. && Equals(d1,d4) && Equals(d2,d3) && Equals(d2,d4) && Equals(d3,d4)
  143. && (((s1 * -s2) == -1) || ((s1 == UNDEFINED && s2 == 0)
  144. || (s2 == UNDEFINED && s1 == 0))) && (((s2 * -s3) == -1)
  145. || ((s2 == UNDEFINED && s3 == 0) || (s3 == UNDEFINED && s2 == 0)))
  146. && (((s3 * -s4) == -1) || ((s3 == UNDEFINED && s4 == 0)
  147. || (s4 == UNDEFINED && s3 == 0))) && (((s4 * -s1) == -1)
  148. || ((s4 == UNDEFINED && s1 == 0) || (s1 == UNDEFINED && s4 == 0))))
  149. {
  150. cout << "Perimeter of square: " << sq.Perimeter() << endl;
  151. cout << "Area of square: " << sq.Area() << endl;
  152. }
  153. else
  154. {
  155. cout << "The lines are not parallel or the sides" << endl;
  156. cout << "are not the same length to each other." << endl;
  157. }
  158. }
  159. else
  160. {
  161. cout << "There was an error for input." << endl;
  162. }
  163. return 0;
  164. }
  165.  
  166.  
  167.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:27: fatal error: quadrilateral.h: No such file or directory
 #include "quadrilateral.h"
                           ^
compilation terminated.
stdout
Standard output is empty