Demonstrate nested structures - C++ Data Type

C++ examples for Data Type:struct

Description

Demonstrate nested structures

Demo Code

#include <iostream>
using namespace std;
struct Measure//from   ww w.  j  a  va2s  .  c om
{
   int feet;
   float inches;
};
struct Room                      //rectangular area
{
   Measure length;              //length of rectangle
   Measure width;               //width of rectangle
};
int main()
{
   Room dining;                  //define a room
   dining.length.feet = 13;      //assign values to room
   dining.length.inches = 6.5;
   dining.width.feet = 10;
   dining.width.inches = 0.0;
   //convert length & width
   float l = dining.length.feet + dining.length.inches/12;
   float w = dining.width.feet  + dining.width.inches/12;
   //find area and display it
   cout << "Dining room area is " << l * w << " square feet\n" ;
   return 0;
}

Result


Related Tutorials