Friday 11 August 2017

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.



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:

0 comments: