Question: #include #include using namespace std; class triangle { public: triangle(int base, int hypotenuse); //Parameterized Constructor triangle(); //Default Constructor; Default base is 3 and default hypotenuse

#include

#include

using namespace std;

class triangle

{

public:

triangle(int base, int hypotenuse); //Parameterized Constructor

triangle(); //Default Constructor; Default

base is 3 and default hypotenuse is 5

void setBase(int newBase); //Mutator function

void setHypotenuse(int newHypotense);//Mutator function

int getBase() const;//Accessor function

int getHypotenuse() const;//Accessor function

void printTriangle(); //Print function HINT: b = sqrt(pow(c, 2) -

pow(a, 2))

double getArea();//Find Area HINT: HINT: b (height) = sqrt(pow(c, 2)

- pow(a, 2))

double getPerimeter();//Find Perimeter HINT: b = sqrt(pow(c, 2) -

pow(a, 2))

private:

int a; //variable to store base HINT: HINT: b = sqrt(pow(c, 2) -

pow(a, 2))

int b; //variable to store height HINT: b = sqrt(pow(c, 2) - pow(a,

2))

int c; //variable to store hypotenuse

};

//Start your class functions codes from here!

// Driver program for the triangle class

int main()

{

triangle t1;

triangle t2(5, 13);

triangle t3;

cout << "TRIANGLE CLASS -------------- ";

//Display rectangles

cout << "Triangle t1 " << endl;

t1.printTriangle();

cout << " Triangle t2 " << endl;

t2.printTriangle();

cout << " Triangle t3 " << endl;

t3.printTriangle();

cout << " NEW Triangle t3 " << endl;

t3.setBase(8);

t3.setHypotenuse(17);

cout << "NEW A: " << t3.getBase() << " NEW B: " <<

(sqrt(pow(t3.getHypotenuse(), 2) - pow(t3.getBase(), 2))) << " NEW C: "

<<

t3.getHypotenuse() << endl << endl;

//Display area and perimeter

cout << "Area of t1: " << t1.getArea() << endl;

cout << "Perimeter of t1: " << t1.getPerimeter() << endl;

cout << " Area of t2: " << t2.getArea() << endl;

cout << "Perimeter of t2: " << t2.getPerimeter() << endl;

cout << " Area of t3: " << t3.getArea() << endl;

cout << "Perimeter of t3: " << t3.getPerimeter() << endl << endl <<

endl;

system("pause");

return 0;

}

In this assignment, you are asked to write the definition for a triangle class and test it with the test program provided. The description of the rectangle class and the driver program are given on the attached file triangle.cpp. Download the triangle.cpp and without removing or changing any of the member functions or member variables of this class, complete 9 member functions bodies such that your program produces exact output as provided. You should keep the class definition and the main function in the same source file, and you are not allowed to use global variables. Do not add any new member functions.

Member Functions:

triangle(int base, int hypotenuse); sets base = a and hypotenuse = c

triangle(); initializes base to 3 and hypotenuse to 5

void setBase(int newBase); lets user change base to a different number

void setHypotenuse(int newHypotense); lets user change hypotenuse to a different number

int getBase() const; returns base a

int getHypotenuse() const; returns hypotenuse c

void printTriangle(); prints the lengths of each side of the triangle a, b, and c

double getArea(); returns the area of the triangle

double getPerimeter(); returns the perimeter of the triangle

HINT: to find the height of the triangle, you must solve the Pythagorean theorem for b.

[b = sqrt(pow(c, 2) - pow(a, 2))]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!