// public_private_ex3.cpp // Purpose: to demonstrate how to build program // using derived data types with private // and public members... using a better version of set() // member function. This demonstrates the advantage of // object oriented programming. Functions that relate // to objects can be modified (improved) without affecting // other objects or segments of the program... // NOTE: Ignore compile warnings, it will still compile... #include using namespace std; struct Student { // Define derived data type private: int no; char grade[14]; public: void display() const; void set(int n, char* g); }; main() { Student harry; harry.set(-1, "AZC"); // Note: Z is not a valid grade nor is std# -1 harry.display(); // run program to see what happens... } // end of main() program void Student::display() const { cout << no << ' ' << grade << endl; } // end of display() public member function void Student::set(int n, char* g){ int i; if (n > 0) no = n; // accept n if positive else no = 0; // store 0 otherwise // validate grades received for (i = 0; g[i] != '\0' && i < 13; i++) { if (g[i] >= 'A' && g[i] <= 'F' && g[i] != 'E') grade[i] = g[i]; // store A, B, C, D, or F else grade[i] = '?'; // otherwise, store ? } grade[i] = '\0'; // make sure the last byte is null } // end of "improved" set() member function...