Create
a structure called Volume that
uses three variables of type Distance to model the volume of a room. Initialize
a variable of type Volume to specific dimensions, then calculate the volume it
represents, and print out the result.
To
calculate the volume, convert each dimension from a Distance variable to a
variable of type float representing feet and fractions of a foot, and then
multiply the resulting three numbers.
SOLUTION:
#include<iostream.h>
#include<conio.h>
/////////////////////////////////////////////////////////////
Define Structures
////////////////////////////////////////////////////////////
struct
distance
{
int feet,inches;
};
struct
volume
{
distance length,width,height;
};
/////////////////////////////////////////////////////
Define Structure Variables
/////////////////////////////////////////////////////
volume
room={ {20,6},{11,3},{10,6} };
void
main()
{
float l,w,h,v;
clrscr();
//////////////////////////////////////////////////////////////
Calculate Volume
///////////////////////////////////////////////////////////
l=room.length.feet+room.length.inches/12.0;
w=room.width.feet+room.width.inches/12.0;
h=room.height.feet+room.height.inches/12.0;
v=l*w*h;
//////////////////////////////////////////////////////////////////////
Output
/////////////////////////////////////////////////////////////////////
cout<<"Length of Room is:
"<<room.length.feet<<"\"
"<<room.length.inches<<"\'";
cout<<"\nWidth of Room is:
"<<room.width.feet<<"\"
"<<room.width.inches<<"\'";
cout<<"\nLength of Room is:
"<<room.length.feet<<"\"
"<<room.length.inches<<"\'";
cout<<"\n\nVolume of Room is:
"<<v<<" Cubic Feet";
getch();
}
OUTPUT:
![](file:///C:\Users\MUHAMM~1\AppData\Local\Temp\msohtmlclip1\01\clip_image002.jpg)
0 comments: