Design a class named Triangle that extends
GeometricObject. The class contains:
• Three double data fields named side1, side2, and side3 with default values 1.0 to denote three sides of the triangle.
• A no-arg constructor that creates a default triangle.
• A constructor that creates a rectangle with the specified side1, side2, and side3.
• The accessor functions for all three data fields.
• A function named getArea() that returns the area of this triangle.
• A function named getPerimeter() that returns the perimeter of this triangle.
Draw the UML diagram that involving the classes Triangle and GeometricObject. Implement the class. Write a test program that creates a Triangle object with sides 1, 1.5, 1, setting color yellow and filled true, and displaying the area, perimeter, color, and whether filled or not.
```
#include
#include "GeometricObject.h"
#include
using namespace std;
class Triangle : public GeometricObject
{
private:
double side1, side2, side3;
/** Constructor */
public:
Triangle(double side1, double side2, double side3)
{
this->side1 = side1;
this->side2 = side2;
this->side3 = side3;
}
/** Implement the abstract method findArea in GeometricObject */
double getArea()
{
double s = (side1 + side2 + side3) / 2;
return sqrt(s * (s - side1) * (s - side2) * (s - side3));
}
/** Implement the abstract method findCircumference in GeometricObject */
double getPerimeter()
{
return side1 + side2 + side3;
}
double getSide1()
{
return side1;
}
double getSide2()
{
return side2;
}
double getSide3()
{
return side3;
}
};
int main()
{
Triangle shape(1, 1.5, 1);
shape.setColor("yellow");
shape.setFilled(true);
cout << shape.getArea() << endl;
cout << shape.getPerimeter() << endl;
cout << shape.getColor() << endl;
cout << shape.isFilled() << endl;
return 0;
}
``````
```
You might also like to view...
The letters “p” and “i” in the high-definition video picture format notations such as 720/30p and 1080/60i stand for _____ and _____ , respectively.
A. pixels; inches B. professional; intermediate C. progressive; interlaced D. pixels per inch; inches per pixel
The INFO2 file was a place for storing deleted files in which file system?
a. FAT16 b. NTFS c. Ext3 d. HPFS
Which protocol is used to remotely access the whole desktop of another computer?
A. Telnet B. Secure Shell C. Virtual Network Computing (VNC) D. HyperText Transfer Protocol (HTTP)
Which statement is false?
a) Symbolic constants are constants represented as symbols. b) Macros are operations defined as symbols. c) All text replacement with symbolic constants and macros occurs before the program is compiled. d) Symbolic constants may be redefined with new values.