Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include "Chap1547.h"
  4. using namespace std;
  5.  
  6. //function prototypes
  7. void endPgm();
  8.  
  9. int main()
  10. {
  11. //triangle object
  12. Triangle myTriangle;
  13.  
  14. //calls to the setDimensions, calcArea, calcPerimeter functions of the triangle class
  15. myTriangle.setDimensions();
  16.  
  17. myTriangle.calcArea();
  18.  
  19. myTriangle.calcPerimeter();
  20.  
  21. //call to EOP
  22. endPgm();
  23.  
  24. return 0;
  25. }
  26.  
  27. //EOP message
  28. //no requirements
  29. void endPgm()
  30. {
  31. //EOP message
  32. cout << "End of Program.";
  33. }
  34.  
  35. #ifndef CHAP1547_H_
  36. #define CHAP1547_H_
  37. #include <iostream>
  38. #include <fstream>
  39. using namespace std;
  40.  
  41. // ***** CLASS DEFINITION *****
  42. class Triangle
  43. {
  44. public:
  45. Triangle();
  46. void setDimensions(double b, double h, double s1, double s2);
  47. double calcArea();
  48. double calcPerimeter();
  49. private:
  50. double b;
  51. double h;
  52. double s1;
  53. double s2;
  54. };
  55.  
  56. // ***** CLASS IMPLEMENTATION *****
  57. //default constructor
  58. Triangle::Triangle()
  59. {
  60. b = 0.0;
  61. h = 0.0;
  62. s1 = 0.0;
  63. s2 = 0.0;
  64. }
  65.  
  66. //setDimensins function
  67. //four type double parameters required
  68. void setDimensions(double b, double h, double s1, double s2)
  69. {
  70. //display console title to user
  71. cout << "TRIANGLE AREA AND PERIMETER CALCULATOR";
  72.  
  73. //loop as long as entry is greater than or equal to 0
  74. while (b >= 0)
  75. {
  76. cout << "Enter base (-1 to Quit): ";
  77. cin >> b;
  78.  
  79. cout << "Enter height: ";
  80. cin >> h;
  81.  
  82. cout << "Enter side one length: ";
  83. cin >> s1;
  84.  
  85. cout << "Enter side two length: ";
  86. cin >> s2;
  87. }
  88. }
  89.  
  90. //calcArea function
  91. //
  92. double Triangle::calcArea()
  93. {
  94. double area;
  95.  
  96. area = .50 * b * h;
  97.  
  98. return area;
  99. }
  100.  
  101. //calcPerimeter function
  102. //
  103. double Triangle::calcPerimeter()
  104. {
  105. double perimeter;
  106.  
  107. perimeter = b + s1 + s2;
  108.  
  109. return perimeter;
  110. }
  111.  
  112. #endif /* CHAP1547_H_ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement