You are required to write a C program that will calculate th
You are required to write a C program that will calculate the following: Perimeter: Square, Rectangle, Triangle, Circle. Area: Square, Rectangle, Triangle, Circle. Volume: Cube, Rectangular Prism, Triangular Pyramid, Sphere.
DETAILS Your program must allow the user to choose whether they want to calculate the Perimeter, Area or Volume. Provide a menu. Once they’ve chosen their calculation from the Perimeter, Area or Volume menu your program must provide a menu with the available geometric shapes in the corresponding option. You must provide a menu again. Your program must ask the user for the appropriate measurements needed to perform the calculations. Don’t forget to validate the user’s input. Make sure that user knows the units in which the calculations are performed and display the units in the final result. You are free to use your own measuring units. Your program should print the result of the calculations to 2 decimal places. Make sure that your formulae use the correct data type to give the correct result. The user must be able to make as many calculations as he wishes. Your program must include a user define library and must have the following 4 user defined functions: float validateInput(float userInput); //returns the userInput corrected if invalid , otherwise makes no corrections float perimeterSquare(float length); //returns the perimeter of a square with a given length float areaSquare(float length); //returns the area of a square with a given length float volumeSquare(float length); //returns the volume of a square or cube with a given length You will add at least 3 more user defined functions. Your source code must be readable and maintainable as possible by including meaningful comments, proper indentation, meaningful variable identifiers, constants, etc. Your program must be user friendly, this includes readability of results and prompts. WHAT TO SUBMIT You must submit the source file (Calculator.c) and the files library source file (*.c) and the header file (*.h) through the class website. EXAMPLE OF OUTPUT This program calculates the Perimeter, Area, and Volume of geometrical figures. Menu 1) Perimeter 2) Area 3) Volume What would you like to calculate? User choice: 1 What geometrical figure would you like to use for Perimeter? 1) Square 2) Rectangle 3) Triangle 4) Circle User choice: 2 Please enter the following values in meters. Length: - 0.25 ERROR: The value of Length must be a positive value. Please try again. Length: 0.25 Width: 0.50 The perimeter of the rectangle is: 1.50 m Would you like to make another Perimeter calculation (1 for Yes, 2 for No)? 1 What geometrical figure would you like to use for Perimeter? 1) Square 2) Rectangle 3) Triangle 4) Circle User choice: 1 Please enter the following values in meters: Length: 0.3 The perimeter of the square is: 1.20 m Would you like to make another Perimeter calculation (1 for Yes, 2 for No)? 2 Would you like to go back to the Main PAV menu (1 for Yes, 2 for No)? 1 Menu 1) Perimeter 2) Area 3) Volume What would you like to calculate? User choice: 2 Which geometrical figure would you like to use for Area? 1) Square 2) Rectangle 3) Triangle 5) Circle User choice: 1 Please enter the following values in meters: Length: 2.5 The area for the square is 6.25 m^2 Would you like to make another Perimeter calculation (1 for Yes, 2 for No)? 2 Would you like to go back to the Main PAV menu (1 for Yes, 2 for No)? 2 ****** Thank you for using this calculator. Goodbye. ******
Solution
#include <iostream>
 #include <stdlib.h>
 #include <stdio.h>
 using namespace std;
 void perimeterMenu();
 void areaMenu();
 void volumeMenu();
 float validateInput(float userInput);
 float perimeterSquare(float length);
 float areaSquare(float length);
 float areaRectangle(float length,float width);
 float perimeterRectangle(float length,float width);
 float areaTriangle(float base,float height);
 float perimeterTriangle(float a,float b, float c);
 float areaCircle(float radius);
 float perimeterCircle(float radius);
 float volumeCube(float side);
 float volumeRectangularPrism(float side1,float side2,float side3);
 float volumeTriangularPyramid(float base,float height);
 float volumeSphere(float radius);
 void mainMenu();
 void mainMenu(){
 printf(\"This program calculates the Perimeter, Area, and Volume of geometrical figures. Menu \  1) Perimeter \  2) Area \  3) Volume \  4) Exit \  What would you like to calculate? \ User choice:\");
 int choice;
    scanf(\"%d\",&choice);
    switch(choice){
 case 1:
        perimeterMenu();
            break;
        case 2:
        areaMenu();
            break;
        case 3:
        volumeMenu();
            break;
           
        case 4:
        printf(\"Good Bye!\");
 exit(1);         
            break;
        }  
}
 void areaMenu(){
 int innerChoice;
            float area,length,width;
            printf(\"\ What geometrical figure would you like to use for Area? \  1) Square \  2) Rectangle \  3) Triangle \  4) Circle \  User choice:\");
            scanf(\"%d\",&innerChoice);
            switch(innerChoice){
            case 1:
              
            printf(\"\ Please enter the following values in meters. Length\");
                scanf(\"%f\",&length);
                area=areaSquare(validateInput(length));
                printf(\"\  Area of square is : %.2f\", area);
                break;
            case 2:
           
            printf(\"\ Please enter the following values in meters. Length\");
                scanf(\"%f\",&length);
                printf(\"\ Please enter the following values in meters. Width\");
                scanf(\"%f\",&width);
                area=areaRectangle(validateInput(length),validateInput(width));
                 printf(\"\  Area of rectangle is : %.2f\", area);
                break;
            case 3:
            float base,height;
            printf(\"\ Please enter the following values in meters. Base\");
                scanf(\"%f\",&base);
                printf(\"\ Please enter the following values in meters. Height\");
                scanf(\"%f\",&height);
                  
                area=areaTriangle(validateInput(base),validateInput(height));
                printf(\"\  Area of triangle is : %.2f\", area);
                break;
              
            case 4:
            float radius;
            printf(\"\ Please enter the following values in meters. Radius\");
                scanf(\"%f\",&radius);
                area=areaCircle(validateInput(radius));
                printf(\"\  Area of circle is : %.2f\", area);
                break;
            }
            int choice2;
            printf(\"\ Would you like to make another Area calculation (1 for Yes, 2 for No)? \");
            scanf(\"%d\",&choice2);
            switch(choice2){
            case 1:
            perimeterMenu();
            break;
            case 2:
            mainMenu();
            break;
            }
}
void perimeterMenu(){
 int innerChoice;
            float perimeter,length,width;
            printf(\"\ What geometrical figure would you like to use for Perimeter? \  1) Square \  2) Rectangle \  3) Triangle \  4) Circle \  User choice:\");
            scanf(\"%d\",&innerChoice);
            switch(innerChoice){
            case 1:
              
            printf(\"\ Please enter the following values in meters. Length\");
                scanf(\"%f\",&length);
                perimeter=perimeterSquare(validateInput(length));
                printf(\"\  Perimeter of square is : %.2f\", perimeter);
                break;
            case 2:
           
            printf(\"\ Please enter the following values in meters. Length\");
                scanf(\"%f\",&length);
                printf(\"\ Please enter the following values in meters. Width\");
                scanf(\"%f\",&width);
                perimeter=perimeterRectangle(validateInput(length),validateInput(width));
                 printf(\"\  Perimeter of rectangle is : %.2f\", perimeter);
                break;
            case 3:
            float a,b,c;
            printf(\"\ Please enter the following values in meters. side a\");
                scanf(\"%f\",&a);
                printf(\"\ Please enter the following values in meters. side b\");
                scanf(\"%f\",&b);
                printf(\"\ Please enter the following values in meters. side b\");
                scanf(\"%f\",&c);
                perimeter=perimeterTriangle(validateInput(a),validateInput(b),validateInput(c));
                 printf(\"\  Perimeter of triangle is : %.2f\", perimeter);
                break;
              
            case 4:
            float radius ;
            printf(\"\ Please enter the following values in meters. Radius\");
                scanf(\"%f\",&radius);
                perimeter=perimeterCircle(validateInput(radius));
                printf(\"\  Perimeter of circle is : %.2f\", perimeter);
                break;
            }
            int choice2;
            printf(\"\ Would you like to make another Perimeter calculation (1 for Yes, 2 for No)? \");
            scanf(\"%d\",&choice2);
            switch(choice2){
            case 1:
            perimeterMenu();
            break;
            case 2:
            mainMenu();
            break;
            }
}
void volumeMenu(){
 int innerChoice;
            float volume;
            printf(\"\ What geometrical figure would you like to use for volume? \  1) Cube \  2) Rectangular Prism \  3) Triangular Pyramid \  4) Sphere \  User choice:\");
            scanf(\"%d\",&innerChoice);
            switch(innerChoice){
            case 1:
            float side;
            printf(\"\ Please enter the following values in meters. Side\");
                scanf(\"%f\",&side);
                volume=volumeCube(validateInput(side));
                printf(\"\  Volume of cube is : %.2f cubic meters\", volume);
                break;
            case 2:
            float side1,side2,side3;
            printf(\"\ Please enter the following values in meters. SIDE1\");
                scanf(\"%f\",&side1);
                printf(\"\ Please enter the following values in meters. SIDE2\");
                scanf(\"%f\",&side2);
                printf(\"\ Please enter the following values in meters. SIDE3\");
                scanf(\"%f\",&side3);
                volume=volumeRectangularPrism(validateInput(side1),validateInput(side2),validateInput(side3));
                 printf(\"\  Volume of Prism is : %.2f\", volume);
                break;
            case 3:
            float base,height;
            printf(\"\ Please enter the following values in meters. Base\");
                scanf(\"%f\",&base);
                printf(\"\ Please enter the following values in meters. Height\");
                scanf(\"%f\",&height);
                volume=volumeTriangularPyramid(validateInput(base),validateInput(height));
                 printf(\"\  Volume of Pyramid is : %.2f\", volume);
                break;
              
            case 4:
            float radius;
            printf(\"\ Please enter the following values in meters. Radius\");
                scanf(\"%f\",&radius);
                volume=volumeSphere(validateInput(radius));
                printf(\"\  Volume of sphere is : %.2f\", volume);
                break;
            }
            int choice2;
            printf(\"\ Would you like to make another Perimeter calculation (1 for Yes, 2 for No)? \");
            scanf(\"%d\",&choice2);
            switch(choice2){
            case 1:
            perimeterMenu();
            break;
            case 2:
            mainMenu();
            break;
            }
}
float perimeterSquare(float length){
return 4*length;
}
float perimeterRectangle(float length,float width){
return 2*(length+width);
}
 float perimeterTriangle(float a,float b, float c){
return a+b+c;
}
float perimeterCircle(float radius){
return 2*3.14*radius;
}
 float areaSquare(float length){
return length*length;
}
float areaRectangle(float length,float width){
return length*width;
}
 float areaTriangle(float base,float height){
return (base*height)/2;
}
float areaCircle(float radius){
return 3.14*radius*radius;
}
float volumeCube(float side){
return side*side*side;
}
float volumeRectangularPrism(float side1,float side2,float side3){
return side1*side2*side3;
}
 float volumeTriangularPyramid(float base,float height){
return 0.33*base*height;
}
float volumeSphere(float radius){
return (4.0/3) * (22/7) * radius * radius * radius;
}
float validateInput(float userInput){
if(userInput>0){
    return userInput;
    }
    printf(\"ERROR: The value must be a positive value and greater than 0.\");
    printf(\"please enter again\");
    scanf(\"%f\",userInput);
   
    return userInput;
}
int main() {
 
 
 mainMenu();
 
    return 0;
 }






