Triangle Class Reference

#include <triangle.h>

Inheritance diagram for Triangle:
Collaboration diagram for Triangle:

Public Member Functions

 Triangle (int b, int h, int x, int y)
 
 Triangle (int b, int h, Point c)
 
virtual std::string getType () const
 
virtual double getArea () const
 
- Public Member Functions inherited from Shape
 Shape (int x, int y)
 
 Shape (Point c)
 
Point getCenter () const
 
void setCenter (Point c)
 

Additional Inherited Members

- Protected Attributes inherited from Shape
Point center
 

Detailed Description

A class that represents a triangle on a 2D plane. Its only members are its base and height. It inherits all of its functionality from the Shape class.

Author
Brent Nash

Constructor & Destructor Documentation

◆ Triangle() [1/2]

Triangle::Triangle ( int  b,
int  h,
int  x,
int  y 
)

Overloaded constructor that takes in a base, a height and an (x,y) coordinate.

Parameters
bThe base of the triangle (must be greater than 0)
hThe height of the triangle (must be greater than 0)
xThe X coordinate of the triangle's center point in 2D space
yThe Y coordinate of the triangle's center point in 2D space

◆ Triangle() [2/2]

Triangle::Triangle ( int  b,
int  h,
Point  c 
)

Overloaded constructor that takes in a base, a height, and a center Point.

Parameters
bThe base of the triangle (must be greater than 0)
hThe height of the triangle (must be greater than 0)
cThe center point of the triangle in 2D space

Member Function Documentation

◆ getArea()

double Triangle::getArea ( ) const
virtual

Virtual function overridden from Shape. Returns the area of the triangle as (1/2)*base*height.

Precondition
The base and height must be set to valid numbers.
Postcondition
Does not change the object
Returns
The area of the circle as a floating point number.

Implements Shape.

◆ getType()

string Triangle::getType ( ) const
virtual

Virtual function overridden from Shape. Returns a string indicating what type of shape this object is.

Precondition
None
Postcondition
Does not change the object
Returns
The string "Triangle"

Implements Shape.


The documentation for this class was generated from the following files: