Ask Question
6 December, 03:50

Define a function PyramidVolume with double parameters baseLength, baseWidth, and pyramidHeight, that returns as a double the volume of a pyramid with a rectangular base. Relevant geometry equations: Volume = base area x height x 1/3 Base area = base length x base width. (Watch out for integer division).

+2
Answers (1)
  1. 6 December, 04:40
    0
    The Program to this question can be given as:

    Program:

    #include / /header file.

    using namespace std;

    double PyramidVolume (double baseLength, double baseWidth, double pyramidHeight) / /define a method PyramidVolume

    {

    double baseArea, Volume; / /declare variable.

    baseArea = baseLength * baseWidth; / /calculate baseArea

    Volume = ((baseArea * pyramidHeight) * 1/3); / /calculate Volume

    return Volume; / /return Volume

    }

    int main () / /define main method.

    {

    double x, baseLength, baseWidth, pyramidHeight; / /define variable.

    cout<<"Enter baseLength : "; / /message.

    cin>>baseLength; / /input value.

    cout<<"Enter baseWidth : "; //message.

    cin>>baseWidth; / /input value.

    cout<<"Enter pyramidHeight : "; //message.

    cin>>pyramidHeight; / /input value.

    x=PyramidVolume (baseLength, baseWidth, pyramidHeight); / /calling

    cout << "Volume of given value is : "<
    return 0;

    }

    Output:

    Enter baseLength : 1.0

    Enter baseWidth : 1.0

    Enter pyramidHeight : 1.0

    Volume of given value is : 0.333333

    Explanation:

    The description of the above program can be given as:

    In the above c+ + language program firstly we include the header file. Then we define a function that is " PyramidVolume". The return type of this function is double because it return value and in this function, we pass three-parameter that is baseLength, baseWidth, and pyramidHeight. The data type of this variable is double. In this function, we define two variable that is "baseArea and Volume" that is used for holding the calculated value. The variable baseArea holds the area of the pyramid and the volume variable holds the volume of the pyramid. Then we define a main function. In this function, we define four variables that is "x, baseLength, baseWidth, and pyramidHeight". The baseLength, baseWidth, and pyramidHeight variable are used to take input from the user and pass into the function. The variable x is used to hold the return value of the function and we print this variable.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Define a function PyramidVolume with double parameters baseLength, baseWidth, and pyramidHeight, that returns as a double the volume of a ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers