Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include "Chap1547.h"
- using namespace std;
- //function prototypes
- void endPgm();
- int main()
- {
- //triangle object
- Triangle myTriangle;
- //calls to the setDimensions, calcArea, calcPerimeter functions of the triangle class
- myTriangle.setDimensions();
- myTriangle.calcArea();
- myTriangle.calcPerimeter();
- //call to EOP
- endPgm();
- return 0;
- }
- //EOP message
- //no requirements
- void endPgm()
- {
- //EOP message
- cout << "End of Program.";
- }
- #ifndef CHAP1547_H_
- #define CHAP1547_H_
- #include <iostream>
- #include <fstream>
- using namespace std;
- // ***** CLASS DEFINITION *****
- class Triangle
- {
- public:
- Triangle();
- void setDimensions(double b, double h, double s1, double s2);
- double calcArea();
- double calcPerimeter();
- private:
- double b;
- double h;
- double s1;
- double s2;
- };
- // ***** CLASS IMPLEMENTATION *****
- //default constructor
- Triangle::Triangle()
- {
- b = 0.0;
- h = 0.0;
- s1 = 0.0;
- s2 = 0.0;
- }
- //setDimensins function
- //four type double parameters required
- void setDimensions(double b, double h, double s1, double s2)
- {
- //display console title to user
- cout << "TRIANGLE AREA AND PERIMETER CALCULATOR";
- //loop as long as entry is greater than or equal to 0
- while (b >= 0)
- {
- cout << "Enter base (-1 to Quit): ";
- cin >> b;
- cout << "Enter height: ";
- cin >> h;
- cout << "Enter side one length: ";
- cin >> s1;
- cout << "Enter side two length: ";
- cin >> s2;
- }
- }
- //calcArea function
- //
- double Triangle::calcArea()
- {
- double area;
- area = .50 * b * h;
- return area;
- }
- //calcPerimeter function
- //
- double Triangle::calcPerimeter()
- {
- double perimeter;
- perimeter = b + s1 + s2;
- return perimeter;
- }
- #endif /* CHAP1547_H_ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement