- Write A C Program That Finds Calculates The Area Of A Shape Selected By The User Square Rectangle Triangle And C 1 (187.62 KiB) Viewed 38 times
Write a C++ program that finds (calculates) the area of a shape selected by the user (Square, Rectangle, triangle, and c
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Write a C++ program that finds (calculates) the area of a shape selected by the user (Square, Rectangle, triangle, and c
Write a C++ program that finds (calculates) the area of a shape selected by the user (Square, Rectangle, triangle, and circle) and prints the result to the screen. Each shape has a designated function to calculate its area and receives the required information to conduct the calculation. However, the results are returned by the function (not void) to the caller (main function) such that the required information to calculate the area is read in the main function and passed to the right function based on the user selection. In this program, you are expected to implement the functions inside a different file (implementation.cpp) and have the signatures of the functions stored in a header file (areas.h) which is included by the main file. That is, your project will have 3 files: 1) main cpp files (mainFile.cpp) 2) header file (areas.h), 3) implementation cpp file (implementation.cpp) The first main file includes the header file (#include "areas.h") and all the needed libraries and is responsible for reading the user selection and the proper information needed for calculating the area of the selected shape. This file is expected to recognize the user selection and invoke (call) the proper function with the required pieces of information and then receive the returned value from the called function and prints it to the screen. The idea is to try to avoid any side effects to the functions (see the slides) by making the input and the output conducted in the main function and outside the calculating functions. The program repeatedly asks the user to select the shape or 5 to quit. The header file (areas.h) (5 Points) will contain function signatures and global variables if needed. The implementation file (implementation.cpp) (5 Points) is where you need to fully implement your functions declared in the header file. You also need to make sure that your header file is included here as well. Note: for the circle, you can assume that PI (T) is 3.14 See an example dialog below: Please select the shape 1. Square 2. Rectangle 3. Triangle 4. Circle 5. Quit select figure: 4 Radius in cm: 0.5 The area is: 0.785 cm. //file name: mainFile.cpp (5 Points) //main function goes here //make sure that you include the header file areas.h //typically, all info are read and printed from here includes //file name: areas.h //mostly function signatures //global variables, if needed. includes //file name: implementation.cpp //here where you need to implement your functions //make sure that you include the header file areas.h