// derived_data_types_ex1.cpp /* Purpose: To demonstrate use of derived data types passing the instance to a function by address which is more efficient, but can be dangerous if you don't want values changed back in previous functions (like main)... */ #include using namespace std; #include "derived_data_types_ex4.h" // include header file main() { struct Student murray = { 3457, {'A','B','A','C','B'}}; sort(&murray); // notice memory address is passed up... display(murray); } // End of main() program void sort(struct Student* murph) { int temp, i, j; for(i=0; i (*murph).grades[j]) { temp = (*murph).grades[i]; /* swap (need to use temp storage) */ (*murph).grades[i] = (*murph).grades[j]; (*murph).grades[j] = temp; } } } } // End of replace() function void display(struct Student murph){ int i; cout << endl << "Here are contents of the instance (called \"murray\") of" << endl; cout << "the object (named \"Student\"):" << endl << endl; cout << "Student number: " << murph.no << endl; cout << "Grades: " ; for (i = 0; i <= 5; i++) cout << murph.grades[i] << " "; cout << endl << endl; } // End of display() function