fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Employee {
  6. int age;
  7. long salary;
  8. string name, desig, dept;
  9.  
  10. public:
  11. void getdata() {
  12. cout << "\nEnter name: ";
  13. cin >> name;
  14. cout << "Enter age: ";
  15. cin >> age;
  16. cout << "Enter designation: ";
  17. cin >> desig;
  18. cout << "Enter department: ";
  19. cin >> dept;
  20. cout << "Enter salary: ";
  21. cin >> salary;
  22. }
  23.  
  24. void putdata() {
  25. cout << "\nName: " << name;
  26. cout << "\nAge: " << age;
  27. cout << "\nDesignation: " << desig;
  28. cout << "\nDepartment: " << dept;
  29. cout << "\nSalary: " << salary;
  30. }
  31. };
  32.  
  33. int main() {
  34. Employee e[5]; // 5 employees
  35.  
  36. for (int i = 0; i < 5; i++) {
  37. cout << "\n\n--- Enter details for Employee " << i + 1 << " ---";
  38. e[i].getdata();
  39. }
  40.  
  41. for (int i = 0; i < 5; i++) {
  42. cout << "\n\n*** Details of Employee " << i + 1 << " ***";
  43. e[i].putdata();
  44. }
  45.  
  46. return 0;
  47. }
Success #stdin #stdout 0s 5328KB
stdin
Standard input is empty
stdout

--- Enter details for Employee 1 ---
Enter name: Enter age: Enter designation: Enter department: Enter salary: 

--- Enter details for Employee 2 ---
Enter name: Enter age: Enter designation: Enter department: Enter salary: 

--- Enter details for Employee 3 ---
Enter name: Enter age: Enter designation: Enter department: Enter salary: 

--- Enter details for Employee 4 ---
Enter name: Enter age: Enter designation: Enter department: Enter salary: 

--- Enter details for Employee 5 ---
Enter name: Enter age: Enter designation: Enter department: Enter salary: 

*** Details of Employee 1 ***
Name: 
Age: 0
Designation: 
Department: 
Salary: 0

*** Details of Employee 2 ***
Name: 
Age: 0
Designation: 
Department: 
Salary: 0

*** Details of Employee 3 ***
Name: 
Age: 0
Designation: 
Department: 
Salary: 0

*** Details of Employee 4 ***
Name: 
Age: 6
Designation: 
Department: 
Salary: -1034099498498222336

*** Details of Employee 5 ***
Name: 
Age: -68137184
Designation: 
Department: 
Salary: 22642999447040