Sunday, 8 April 2018

Create a structure called Volume that uses three variables of type Distance (from the ENGLSTRC example) 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.


using namespace std;
#include<iostream>
#include<conio.h>
struct volume
{
int len,width,height,l_inch,w_inch,h_inch;
};
int main()
{
volume v;
cout<<"###First of all enter feet then inches###"<<endl;
cout<<"Enter the length of room in feet and inches : ";
cin>>v.len>>v.l_inch;
cout<<"Enter the width of room in feet and inches : ";
cin>>v.width>>v.w_inch;
cout<<"Enter the Height of room in feet and inches : ";
cin>>v.height>>v.h_inch;
//Now convert these values in float
float length,width,height,volume;
length=v.len+((float)(v.l_inch)/12);
width=v.width+((float)(v.w_inch)/12);
height=v.height+((float)(v.h_inch)/12);
cout<<"The length of room in foot is : "<<length<<endl;
cout<<"The Base of room in feet is: "<<width<<endl;
cout<<"The Height of room in feet is : "<<height<<endl;
volume=length*width*height;
cout<<"Volume of Room is: "<<volume;
}

4 comments: