Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Below you are given some code that will ask the user to enter in different polygon shapes and a number that represents the length of

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Below you are given some code that will ask the user to enter in different polygon shapes and a number that represents the length of one side of the polygon. Assume that the polygons are regular - i.e. all sides are the same length. The lab exercise consists of the following tasks: 1. create a struct polygon type that has two fields: shape and side_length. The shape field should be of type polygon_t 2. create a polygon_t enum with three members: Triangle, Square, and Pentagon. 3. Complete the calc_area function which will take in a struct polygon* pointer as an argument and calculate the area depending on the shape of the polygon. As a reminder, the area of a equilateral triangle is 43s2, the area of a square is s2, and the area of a regular pentagon is 45(5+25)s2, where s is the length of a side. 4. Complete the print_polygons function which takes in a struct polygon array and iterates through the array and prints out the shape of the polygon, the side length and the area as shown in the example below. Note that the polygon shape must be printed as a string not a number. 5. Add the end of the main function, add code to assign the len and the shape fields to the appropriate fields in the i 'th entry in the polygons array. You should not have to change anything else in the main function. The code you need to complete is marked TODO below. Enter number of polygons: 3 Enter polygon 0 shape [0-Triangle; 1-Square; 2-Pentagon] : 0 Enter side length: 1 Enter polygon 1 shape [0-Triangle; 1-Square; 2-Pentagon] : 2 Enter side length: 3 Enter polygon 2 shape [0-Triangle; 1-Square; 2-Pentagon] : 1 Enter side length: 4 Polygon 0 is a Triangle with side length 1.000000 The area is 0.433013 Polygon 1 is a Pentagon with side length 3.000000 The area is 15.484297 Polygon 2 is a Square with side length 4.000000 The area is 16.000000

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago