Skip to main content

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

Subsection 26.3.2 Store Vertices

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