Skip to main content
Logo image

Section 26.3 Arrays of Structures: Triangle

We can now put multiple points together and store them in an array of points (which is an array of structures). Three points stored together could be viewed as the vertices of a triangle, for example. Four points might give you a quadrilateral, five points a pentagon, etc.

Subsection 26.3.1 Declare a Triangle

Activity 26.2.

So let’s declare a triangle. To do so, all we need is an array that holds three points, thus an array with three elements of type point_t. Declare a variable triangle with these features.

admin.....open in new window

When you are done, please paste your piece of code into the code submission box below:

Subsection 26.3.2 Store Vertices

Activity 26.3.

Now store the vertices (0,0), (2,0), (1,3) in the variable triangle, using the function initializePoint().

admin.....open in new window

When you are done, please paste your code into the code submission box below:

Subsection 26.3.3 Print Triangle

Activity 26.4.

Write a function printTriangle() to which you pass an array of three points, and which prints out the coordinates of these three points. The function printTriangle() should call the function printPoint().

admin.....open in new window

When you are done, please paste your code into the code submission box below: