Question #50074

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

Expert's answer

2014-12-24T13:37:49-0500

Answer on Question# 50074 - <programming> - <c++>

Program

#include <iostream>
#include <string>
using namespace std;
struct Distance  //English distance
{
    int feet;
    float inches;
};
struct Volume
{
    Distance width;
    Distance height;
    Distance length;
};
float ToFoot(Distance x)
{
    return (x.feet + x.inches / 12.);
}
int main()
{
    Volume room;
    cout << "Input height (feet, inches): ";
    cin >> room.height.feet >> room.height.inches;
    cout << "Input width (feet, inches): ";
    cin >> room.width.feet >> room.width.inches;
    cout << "Input length (feet, inches): ";
    cin >> room.length.feet >> room.length.inches;
    float V = ToFoot(room.height) * ToFoot(room.width) * ToFoot(room.length);
    cout << "Volume of room is " << V << " solid foot";
    return 0;
}

Example of execute program:

Input height <feet, inches="">: 2 3
Input width <feet, inches="">: 10 7
Input length <feet, inches="">: 15 3
Volume of room is 363.141 solid foot
Process returned 0 <0x0> execution time : 29.550 s
Press any key to continue.


http://www.AssignmentExpert.com/</feet,></feet,></feet,></v<<"></feet,></string></iostream>

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!
LATEST TUTORIALS
APPROVED BY CLIENTS