Starting from:

$25

CSE102 - Computer Programming - Homework 5 - Solved

Write a complete program that performs geometric calculations. All the requirements requested from you must be fulfilled. In this homework you have to create a calculator that calculates the area, perimeter, and volume values of various shapes. You must have 2 enumerated types. You have to call these enumerated types shapes and calculators.

Shapes must have;

Triangle,

Quadrilateral,

Circle,

Pyramid,

Cylinder
Calculators must have;

Area

Perimeter

Volume

 
 

You must use these enumerated types in all subsequent operations and selections. Except for the Main function, the following 3 functions have to be.

 

Function prototypes are : int select_shape () int select_calc () int calculate (int (), int ()) 

The calculate function has to take select_shape() and select_calc() functions as parameters. This calculate function has to be called inside the main function and the program will continue to run unless the user sends an exit command. First, the user must select the shape, then choose the area, perimeter or volume to calculate it. A character or negative value cannot be entered. All incorrect entries in the program should be checked. Wherever in the program or selection, if the user enters input incorrectly, the program should handle this situation and issue a warning message then the program flow should continue. The program must not be interrupted by any wrong input.  

 

Expected Menu Output
 

 

You have to use the switch-case structure in the calculate function. You must assume and define the PI value as 3.14. For each shape, you should write a calculation function that takes the enum type of the value to be calculated (area, volume, or perimeter) as a parameter.

Function prototypes are: int calc_triangle(int); int calc_quadrilateral(int); int calc_circle(int); int calc_pyramid(int); int calc_cylinder(int); 

In all calculation functions, you have to create the sections where the area, volume or perimeter values are calculated by using the switch-case structure. You have to use Heron's formula when calculating the area of a triangle, and Brahmagupta's formula when calculating the area of a quadrilateral.

Formulas: 

TRİANGLE 

 

𝑯𝒆𝒓𝒐𝒏′𝒔 𝑭𝒐𝒓𝒎𝒖𝒍𝒂 = √𝒔 ∗ (𝒔 − 𝒂) ∗ (𝒔 − 𝒃) ∗ (𝒔 − 𝒄) 

𝒂 + 𝒃 + 𝒄

𝒔 =    

𝟐

Important: In any triangle, sum of any two sides of is always greater than the third side. Hence in any triangle, the semi perimeter can not be less than any side. You have to check this situation in the program. Since the volume cannot be calculated for Triangles and Quadrilaterals, you should give a warning and continue the program.

 

 

QUADRILATERAL
   𝑩𝒓𝒂𝒉𝒎𝒂𝒈𝒖𝒑𝒕𝒂′𝒔 𝑭𝒐𝒓𝒎𝒖𝒍𝒂   

CIRCLE
𝑪𝒊𝒓𝒄𝒖𝒎𝒇𝒆𝒓𝒆𝒏𝒄𝒆   𝒓 

𝑨𝒓𝒆𝒂   𝒓𝟐 

 

PYRAMID
 𝑽𝒐𝒍𝒖𝒎𝒆 = 𝟏 𝟐 ∗ 𝒉 ∗ 𝒂

𝟑

𝑩𝒂𝒔𝒆 𝑺𝒖𝒓𝒇𝒂𝒄𝒆 𝑨𝒓𝒆𝒂 = 𝑩 = 𝒂𝟐  

𝑳𝒂𝒕𝒆𝒓𝒂𝒍 𝑺𝒖𝒓𝒇𝒂𝒄𝒆 𝑨𝒓𝒆𝒂 = 𝑳 = 𝟐 ∗ 𝒂 ∗ 𝒍   

 

CYLINDER
𝑽𝒐𝒍𝒖𝒎𝒆 = 𝝅 ∗ 𝒓𝟐 ∗ 𝒉 

𝑩𝒂𝒔𝒆 𝑺𝒖𝒓𝒇𝒂𝒄𝒆 𝑨𝒓𝒆𝒂 = 𝝅 ∗ 𝒓𝟐  

𝑳𝒂𝒕𝒆𝒓𝒂𝒍 𝑺𝒖𝒓𝒇𝒂𝒄𝒆 𝑨𝒓𝒆𝒂 = 𝟐 ∗ 𝝅 ∗ 𝒓 ∗ 𝒉   

𝑺𝒖𝒓𝒇𝒂𝒄𝒆 𝑨𝒓𝒆𝒂 = 𝟐 ∗ 𝝅 ∗ 𝒓 ∗ (𝒓 + 𝒉)

 

 

Not all states are shown in the expected outputs, but you have to check all states and incorrect entries for each calculation. You must also perform the calculations that are not shown exactly. The important formulas are all given, you have to look for the necessary formulas for the calculation. You cannot use Arrays. You cannot use Recursion. You can use fflush(stdin) if you are getting a character error while getting input from the user. You can only use "math.h", "stdlib.h" and "stdio.h" libraries.

More products