// Demo: update name // name is entered in the main program // and updated using a put_name(), a member function of Student #include #include #include using namespace std; class Student { private: string id,name,class_no; public: Student(){ id="id00"; name="noname"; class_no="00"; } // initial values given for very student void show() { cout << left << setw(5) << id << setw(15) << name << class_no << endl; } void put_name(string xname); // enter name only }; void Student::put_name(string xname) { // updates name name = xname; } void main() { Student x,y; // create 2 students x and y string nm; x.show(); // display student x"id00 noname 00" cout << "enter name "; getline(cin,nm); // enter "JOHN" x.put_name(nm); // update name with nm; x.show(); // display "id00 JOHN 00" for student x, // name changed to JOHN x.put_name("MUTHU"); // update name with MUTHU x.show(); // display "idoo MUTHU 00" } /* Output id00 noname 00 enter name JOHN id00 JOHN 00 id00 MUTHU 00 */