demonstrates passing structure as argument : Struct « Data Type « C++






demonstrates passing structure as argument

   
#include <iostream>   
  using namespace std;   
  
  struct Distance{   
     int feet;   
     float inches;   
  };   
  void engldisp( Distance );
    
  int main(){   
     Distance d1, d2; 
     cout << "Enter feet: ";  
     cin >> d1.feet;   
     cout << "Enter inches: ";  
     cin >> d1.inches;   
    
     cout << "\nEnter feet: ";  
     cin >> d2.feet;   
     cout << "Enter inches: ";  
     cin >> d2.inches;   
    
     cout << "\nd1 = ";   
     engldisp(d1); 
     cout << "\nd2 = ";   
     engldisp(d2); 
     cout << endl;   
     return 0;   
  }   
  void engldisp( Distance dd ){   
     cout << dd.feet << "\'-" << dd.inches << "\"";   
  }
  
    
    
  








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 nested structures
7.demonstrates passing structure by reference