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. Relevant geometry equations:
Volume = base area x height x 1/3
Base area = base length x base width.
(Watch out for integer division).
#include<iostream>
using namespace std;
double CalcPyramidVolume(double baseLength, double baseWidth, double pyramidHeight)
{
double BaseArea = baseLength * baseWidth;
double Volume = BaseArea*pyramidHeight/ 3;
return Volume;
}
int main()
{
double baseLength, baseWidth, pyramidHeight;
cout << "Please, enter a baseLength of piramid: ";
cin >> baseLength;
cout << "Please, enter a baseWidth of piramid: ";
cin >> baseWidth;
cout << "Please, enter a pyramidHeight of piramid: ";
cin >> pyramidHeight;
cout << "The Volume pf piaramid is " << CalcPyramidVolume(baseLength, baseWidth,pyramidHeight);
}
Comments
Leave a comment