// arrayemp.cpp // models an employee // uses array of employees #include #include // for getche() class employee { private: char name[20]; // name (20 chars max) int n; // length of name int serial_number; public: void input() // get data from user { char ch; n = 0; cout << " Enter name: "; do { ch = getche(); // get one char at a time name[n++] = ch; // store in “name” array } while(ch != '\r'); // quit if “Enter” key cout << "\n Enter serial number: "; cin >> serial_number; } void output() // display employee data { cout << " Name = "; for (int j = 0; j < n; ++j) // display one character cout << name[j]; // at a time cout << "\n Serial number = " << serial_number; } }; // class employee void main() { employee emps[100]; // array of employee objects int n = 0; // number of objects in array char choice; do { cout << "Enter employee " << n << " data" << endl; emps[n++].input(); // get data cout << "Do another (y/n)? "; cin >> choice; } while(choice != 'n'); for (int j = 0; j < n; j++) { cout << "\nData for employee " << j << endl; emps[j].output(); // display data } // stop the flow on the monitor getch(); } //end main