143k views
1 vote
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

3 votes

Answer:

static double pyramidVolume(double baseLength, double baseWidth, double pyramidHeight){

double Volume,baseArea;

baseArea = baseLength * baseWidth;

Volume = baseArea * pyramidHeight * 1/3;

return Volume;

}

Step-by-step explanation:

Define a function PyramidVolume with double parameters baseLength, baseWidth, and-example-1
3 votes

Answer:

The Program to this question can be given as:

Program:

#include <iostream> //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 :"<<x; //print value.

return 0;

}

Output:

Enter baseLength :1.0

Enter baseWidth :1.0

Enter pyramidHeight :1.0

Volume of given value is :0.333333

Step-by-step 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.

User Kcbanner
by
4.8k points