Answer to Question #328591 in C++ for Program Training

Question #328591

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). 


1
Expert's answer
2022-04-15T08:24:32-0400


#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS