Define a function CalcPyramidVolume() with double data type parameters baseLength, baseWidth, and pyramidHeight, that returns as a double the volume of a pyramid with a rectangular base. CalcPyramidVolume() calls the given CalcBaseArea() function in the calculation.
Relevant geometry equations:
Volume = base area x height x 1/3
(Watch out for integer division).
#include<iostream>
using namespace std;
double CalcBaseArea(double baseLength,double baseWidth)
{
return baseLength*baseWidth;
}
double CalcPyramidVolume(double baseLength,double baseWidth,double pyramidHeight){
return pyramidHeight*CalcBaseArea(baseLength,baseWidth)* (1.0/3.0);
}
int main(){
double baseLength;
double baseWidth;
double pyramidHeight;
cout<<"Enter base length: ";
cin>>baseLength;
cout<<"Enter base idth: ";
cin>>baseWidth;
cout<<"Enter pyramid height: ";
cin>>pyramidHeight;
cout<<"Volume of the pyramid: "<<CalcPyramidVolume(baseLength,baseWidth,pyramidHeight)<<"\n";
system("pause");
return 0;
}
Comments
Leave a comment