fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. // Class declaration
  6. class Student {
  7. private:
  8. int empCode;
  9. string name;
  10. string dept;
  11. string designation;
  12. int age;
  13. float salary;
  14.  
  15. public:
  16. // Constructor to initialize the object
  17. Student(int code, string empName, string empDept, string empDesignation, int empAge, float empSalary) {
  18. empCode = code;
  19. name = empName;
  20. dept = empDept;
  21. designation = empDesignation;
  22. age = empAge;
  23. salary = empSalary;
  24. }
  25.  
  26. // Function to display Emp Code and Name if Salary > 50,000
  27. void display() {
  28. if (salary > 50000) {
  29. cout << "Emp Code: " << empCode << ", Name: " << name << endl;
  30. }
  31. }
  32. };
  33.  
  34. int main() {
  35. // Creating 3 objects of Student class
  36. Student emp1(101, "Alice", "IT", "Manager", 30, 60000);
  37. Student emp2(102, "Bob", "HR", "Executive", 28, 45000);
  38. Student emp3(103, "Charlie", "Finance", "Analyst", 35, 70000);
  39.  
  40. cout << "Employees with salary more than ₹50,000:" << endl;
  41. emp1.display();
  42. emp2.display();
  43. emp3.display();
  44.  
  45. return 0;
  46. }
  47.  
Success #stdin #stdout 0s 5280KB
stdin
 
stdout
Employees with salary more than ₹50,000:
Emp Code: 101, Name: Alice
Emp Code: 103, Name: Charlie