C++ Class Definition model Employee object
#include <iostream> #include <string> using namespace std; class Employee//from w w w .j a v a2s . c o m { private: string name; long number; public: void getdata() //get data from user { cout << "\nEnter name: "; cin >> name; cout << "Enter number: "; cin >> number; } void putdata() //display data { cout << "\n Name: " << name; cout << "\n Number: " << number; } }; int main() { Employee emparr[100]; //an array of Employees int n = 0; //how many Employees char ch; //user response do { //get data from user cout << "\nEnter data for Employee number " << n+1; emparr[n++].getdata(); cout << "Enter another (y/n)? "; cin >> ch; } while( ch != 'n' ); for(int j=0; j<n; j++) //display data in array { cout << "\nEmployee number " << j+1; emparr[j].putdata(); } cout << endl; return 0; }