85.7k views
0 votes
Define a function pyramid volume with double parameters baselength, basewidth, and pyramid height, 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).

User Soulmerge
by
8.3k points

1 Answer

5 votes
Declaring the volume function double PyramidVolume(double baseLength, double baseWidth, double pyramidHeight){ double baseArea = baseLength * baseWidth; double vol = ((baseArea * pyramidHeight) * 1/3); return vol; } int main() { cout << "Volume for 1.0, 1.0, 1.0 is: " << PyramidVolume(1.0, 1.0, 1.0) << endl; return 0; } Defining the function, include <iostream> double PyramidVolume(double, double, double); int main() { std::cout << "Volume for 1.0, 1.0, 1.0 is: " << PyramidVolume(1.0, 1.0, 1.0) << std::endl; return 0; } double PyramidVolume(double length, double width, double height) { return length * width * height / 3; }
User Stephen Byrne
by
7.3k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.