// Demo: correct way to update
//     : the student using the member function enter()
#include 
#include 
#include 
using namespace std;
class Student {
  private:
    string id,name,class_no;
  public:
    Student(){ id="id00";
               name="none";
               class_no="00";
               }
    void show() {
     cout << left << setw(5) << id <<
             setw(15) << name << class_no << endl;
    }
    void enter(); // enter id,name,class_no
};
void Student::enter() {  // updates name, but not id and class_no
   // Note: NO VARIABLES ARE DECLARED HERE
   // THE id,name,class_no HAS ALREADY BEEN DEFINED IN clsss Student
   // as this is a MEMBER FUNCTION of Student.
   // However you may declared other variables (local)
   // e.g. int i;  // to use for looping within the function
   //                 if there is a need for it.
   cout << "enter id " ; getline(cin,id);
   cout << "enter name ";   getline(cin,name);
   cout << "enter class no "; getline (cin,class_no);
}
void main() {
 Student x,y; // create 2 students x and y
 y.show();  // display student y "id00  none  00"
 y.enter();  // enter the id="A000",name="AHMAD",class_no="44"
 y.show();   //  display "A000 AHMAD 44" for student y
 x.show();   // display student x "id00 none 00"
}
/* output when program is runned
id00 none           00
enter id A000
enter name AHMAD
enter class 44
A0000 AHMAD 44
id00 BENG           00
*/

    Source: geocities.com/tpjc_sg