How do you program this using basic C++ coding? Problem 2- Purpose: Find the dim
ID: 3875360 • Letter: H
Question
How do you program this using basic C++ coding?
Problem 2-
Purpose: Find the dimensions of a tetragonal box that has the same volume
as a cubic box when knowing the height of the tetragonal box is 1.2 times
the height of the cubic box.
Input: Height of cubic box
Output: Dimensions of tetragonal box
Algorithm:
-Get height of cubic box
-Calulate volume of cubic box using Volume = (width)(length)(height)
-Calulate height of tetragonal box by mutliplying the height of the cubic box
by 1.2
-Calculate area of the base of the tetragonal box by dividing the volume of
the cubic box by the height of the tetragonal box
-Calculate the width and length of the tetragonal box by dividing the area of
the base by 2
-Output tetragonal box's length, width, and height
Test data:
Cubic box's volume = Tetragonal box's volume
Tetragonal box's height = 1.2(cubic box's height)
Explanation / Answer
#include<iostream> //It is a library contains I/O functions cin() and cout()
using namespace std;
int main(){
double cube_height,tet_height,tet_width,tet_length;
cout << "enter height of cubic box:";
cin >> cube_height;
double volume_cube = cube_height*cube_height*cube_height;
tet_height = 1.2 * cube_height;
double area_base = volume_cube/tet_height;
tet_width = area_base/2.0;
tet_length = tet_width;
cout << "length " << tet_length << endl;
cout << "width " << tet_width << endl;
cout << "heigth " << tet_height << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.