Question: I feel like im doing my code right but its not right at all. Important: Make sure that all functions are properly documented with comments.
I feel like im doing my code right but its not right at all. Important: Make sure that all functions are properly documented with comments. "Every function declaration prototype should have comments
immediately preceding it that describe what the function does and how to use itfrom Google's C Style Guide The body of each function should contain
comments just like we have done for main in past assignments.
Write a program that prompts the user to enter two properties of the regular polygon: the number of sides and the length of each side. The program should then
output the polygon's name followed by the number of sides, length of each side, perimeter, interior angle, apothem, and area. If the shape has fewer than sides,
the program will only report the name, the number of sides, and the length of each side. Numbers should be displayed with digits of precision.
Name your source code file Polygons.cpp
First, define PI as a global constant assume to be used in some of the calculations. Note: All other variables, should be declared within your
functions.
Your program must have at least the following functions. Use the names given here:
a getPolygonName: This function accepts a single parameter, which is the number of sides of the polygon. The function returns the name of the polygon. Use
the following names in a switch statement:
If the input is not one of these values, return an empty string.
b getPerimeter: This function accepts two parameters: the number of sides and the length of a side in that order The function calculates and returns the
perimeter of the polygon by multiplying the parameters by each other. Hint: Make your function definitions succinct. The body of this function and several
others can be written in a single line just a return statement with no local variables.
c get InteriorAngle: This function calculates the angle in degrees within the shape based on the number of sides. The parameter will be the number of sides.
The formula for this calculation is where is the number of sides. Use a more meaningful identifier than in your code.
d getApothem: This function accepts two parameters the number of sides and the length of a side that are used to calculate the apothem of a regular polygon.
The apothem sometimes called the inradius is the shortest distance from the center to one of the sides. The formula for this calculation is
where is the length of a side and is the number of sides. Note use more meaningful identifiers for and in your program eg sideLength and
sideCount The tan function is predefined in the cmath library.
e getArea: This function also accepts the number of sides and the length of a side as its only parameters. However, the function will calculate the area from the
perimeter and apothem. Call the functions getPerimeter and getApothem within this function and use the formula: area where is the
perimeter and is the apothem. Again, use more meaningful identifiers than in the given formula.
The functions in the list above should NOT get any input from the user or display any information ie do not use cin or cout Use main andor another function to
get user input and display the results.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
