previous | start | next

## Triangle Numbers

- In this example, we will look at triangle shapes such as the one shown here:

  >     []
  >     [][]
  >     [][][]

- The n-th triangle number is the area of a triangle of width n.
- From above, the third triangle number is 6.
- Here is the outline of the class that we will develop:

  >     class Triangle
  >     {
  >     public:
  >        Triangle(int w);
  >        int get_area() const;
  >     private:
  >        int width;
  >     };
  >     Triangle::Triangle(int w)

  >     {
  >        width = w;
  >     }

previous | start | next