Answer to Question #186033 in C++ for python

Question #186033

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.


1
Expert's answer
2021-04-27T19:00:11-0400
#include <iostream>
using namespace std;
struct distance{
    float feet;
    float inches;
};
struct Volume{
    struct distance length;
    struct distance width;
    struct distance height;
    float volume() {
        return (length.feet + length.inches / 12) * (width.feet + width.inches / 12) * (height.feet + height.inches / 12);
    }
};
int main(){
    struct distance length = {4, 6}, width = {3, 5}, height = {5, 3};
    struct Volume Vol;
    Vol.length = length;
    Vol.width = width;
    Vol.height = height;
    cout<<"Volume in cubic feet: "<<Vol.volume();
    return 0;
}

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!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS