// structvalref.cpp - Passing a structure by reference and by value

#include <iostream>

struct student {
  int  mid;
  int final;
  int hmws;
};

// Increasing fields of a student being passed by value: 
// it has no effect on the actual parameter
void upval(student who){
   who.mid   = int(0.9*who.mid + 10);
   who.final = int(0.9*who.final + 10);
   who.hmws  = int(0.9*who.hmws + 10);
}

// Increasing fields of a student being passed by reference
void upref(student& who){
   who.mid   = int(0.9*who.mid + 10);
   who.final = int(0.9*who.final + 10);
   who.hmws  = int(0.9*who.hmws + 10);
}

void main(void){
   student sam = {85, 90, 88};

   cout << "Initially:   " << sam.mid << " " << sam.final 
        << "  " << sam.hmws << endl;
   upval(sam); // This call leaves sam unchanged
   cout << "After upval: " << sam.mid << " " << sam.final 
        << "  " << sam.hmws << endl;
   upref(sam); // This call changes value of sam
   cout << "After upref: " << sam.mid << " " << sam.final 
        << "  " << sam.hmws << endl;
}
