Question: SPECIFICATIONS: Given the following symbolic constants and structure declarations: #define PI 3.141593 #define NUM 8 struct Shape { char name [32] ; int length, width,

![3.141593 #define NUM 8 struct Shape { char name [32] ; int](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/10/670e681e2c33e_406670e681e05054.jpg)



SPECIFICATIONS: Given the following symbolic constants and structure declarations: #define PI 3.141593 #define NUM 8 struct Shape { char name [32] ; int length, width, height, base, radius; double area, volume; Shape( ); // default constructor Shape (char type) ; // parameter overloaded constructor double computeAreaOrVolume( ); int displayShape( ); Q1. For the Shape class, write the code for the default constructor (a member function): Shape( ) that initializes all integer and double data members to e and sets the name to the string "unknown". Q2. For the Shape class, write the code for the parameter constructor (a member function): Shape (char type) that initializes all the data members to O and sets the name char array based on the value of the char parameter 'type' as follows: char : name : 'T sets name to "Triangle" sets name to "Sphere" "R' sets name to "Rectangle" "C sets name to "Cone" sets name to "unknown" for any other character other than 'T', 'S", 'R', or C'.Q3. For the Shape class, write the code for the member function: double computeAreaOrVolume( ) This function computes the area ONLY if the Shape's name is either "Triangle" or "Rectangle", otherwise the volume is computed using the correct formula based on whether the shape is a "Cone" or a "Sphere" (see below). If the name is "unknown" then this function does nothing and simply returns 0. 9ede. NOTE: You may use the stromp( ) function (prototyped in the string. h library) to perform string comparisons. The volume or area computed must be stored in the correct variable (area or volume) in the structure and must also be returned before the function ends. The formulas for computing area and volume are: Triangle: area = 1/2 x base x height Rectangle: area = length x width Cone : volume = 1/3 x PI x R^2 x H (* means exponent) Sphere: volume = 4/3 x PI x R*3 (* means exponent ) This function returns a double with the computed value of either the volume or the area. NOTE: DO NOT use the * symbol in your equation! It does not work as an exponent, but will not generate an error if used! ALSO: You MUST use the value of PI as represented by the symbolic constant PI already defined in the supplied main( ) function (ive. 3.141593) in your calculations. ALSO: Be careful with integer division! Recall what 1/2 evaluates to in C/C++. Q4. For the Shape class, write the code for the member function: int displayShape( ) This function displays the following information in EXACTLY the order listed below. value: name Followed by a newline (displays the string only). length followed by a newline (but only if the length is NOT @) (displays the integer only) width followed by a newline (but only if the width is NOT @) (displays the integer only) height followed by a newline (but only if the height is NOT @) (displays the integer only) base Followed by a newline (but only if the base is NOT @) (displays the integer only) radius followed by a newline (but only if the radius is NOT @) (displays the integer only) area Followed by a newline (but only if the name is either "Triangle" or "Rectangle") (displays the double only) volume followed by a newline (but only if the name is either "Sphere" or "Cone") (displays the double only) NOTE: The area or volume MUST be diplayed to EXACTLY 4 decimal places. This function returns the total number of length, width, height, base, and radius data members combined that ARE NOT EQUAL TO 8.MAIN PROGRAM: // Your solution may ONLY use functions from the following // included C/C++ library header files. #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
