// Program to accept and display employees' information. // Assignment-18 // empinf.cpp, Author - Krishna Kumar Khatri. // Uncomment ONLY the following line if you are using Turbo/Borland compiler. // #define TC #ifdef TC #include #include #else #include #include using namespace std; #endif #include // For getch. const int MAXNMLEN = 25; const int MAXENRNG = 9999; class Employee { char empname[MAXNMLEN]; int empno; public: Employee() { } Employee(const char* nm, const int& en) { strcpy(empname, nm); empno = en; } void get_data(); void put_data(); }; void Employee::get_data() { cout << "Employee name: "; cout << flush; // Emptying buffer. cin.getline(empname, MAXNMLEN, '~'); do { cout << "Employee number: "; cin >> empno; } while (empno < 1 || empno > MAXENRNG); cout << endl; } void Employee::put_data() { empno < 10 ? cout << "000" << empno : (empno < 100 ? cout << "00" << empno : (empno < 1000 ? cout << "0" << empno : cout << empno)); cout << " " << empname << endl; } int main() { #ifdef TC clrscr(); #endif Employee emp1, emp2; cout << "Use tilde '~' character for string termination." << endl << endl; emp1.get_data(); emp2.get_data(); cout << endl << "Processed data," << endl; cout << endl << "EMPID EMPNAME\n"; cout << "----- -------\n"; emp1.put_data(); emp2.put_data(); cout << endl << endl << "Program over. Press any key to exit..."; getch(); return 0; // Successful termination. }