demonstrates nested structures : Struct « Data Type « C++






demonstrates nested structures

   
#include <iostream>   
  using namespace std;   
  struct Distance{   
     int feet;   
     float inches;   
  };   
  struct Room{   
     Distance length;
     Distance width;
  };   
  int main()   
  {   
     Room dining;   
    
     dining.length.feet = 13;    
     dining.length.inches = 6.5;   
     dining.width.feet = 10;   
     dining.width.inches = 0.0;   

     float l = dining.length.feet + dining.length.inches/12;   
     float w = dining.width.feet  + dining.width.inches/12;   

     cout << l * w;   
     return 0;   
    }
  
    
    
  








Related examples in the same category

1.Defines and uses a struct.Defines and uses a struct.
2.example about structures
3.pointers to structures
4.array of structures
5.uses parts inventory to demonstrate structures
6.demonstrates passing structure by reference
7.demonstrates passing structure as argument