// public_private_ex5.cpp // Purpose: to demonstrate getting example #2 to compile // if derived data type contains just public // members... // // Note: This program WILL compile // NOTE: Ignore compile warnings, it will still compile... #include using namespace std; struct Student { // Define derived data type public: int no; char grade[14]; void display() const; void set(int n, char* g); }; main() { Student harry; harry.set(975, "ABC"); // calling public member functions set and display harry.display(); cout << harry.no << endl; } // 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; no = n; // accept the Student number received // accept Student grades received for (i = 0; g[i] != '\0' && i < 13; i++) grade[i] = g[i]; grade[i] = '\0'; // set the last byte to null } // end of set() function