structure variables as array elements : structure parameter « Structure « C++ Tutorial






#include <iostream>  
  using namespace std;  
  const int SIZE = 4;  

  struct part{  
     int modelnumber;              
     int partnumber;               
     float cost;                   
  };  
  int main(){  
     int n;  
     part apart[SIZE];
    
     for(n=0; n<SIZE; n++){  
        cout << endl;  
        cout << "Enter model number: ";  
        cin >> apart[n].modelnumber;
        cout << "Enter part number: ";  
        cin >> apart[n].partnumber; 
        cout << "Enter cost: ";  
        cin >> apart[n].cost;       
     }  
     
     for(n=0; n<SIZE; n++) {  
        cout << "Model " << apart[n].modelnumber;  
        cout << "  Part "  << apart[n].partnumber;  
        cout << "  Cost "  << apart[n].cost << endl;  
     }  
     return 0;  
  }








8.3.structure parameter
8.3.1.Pass structure to a function
8.3.2.Pass structure using a structure reference
8.3.3.Pass structure to a function as a pointer
8.3.4.structure variables as array elements