#include <iostream>
#include <string>
class Employee {
private:
std::string name;
int age;
double salary;
public:
Employee(const std::string& n, int a, double s)
: name(n), age(a), salary(s) {}
// Getter methods
std::string getName() const { return name; }
int getAge() const { return age; }
double getSalary() const { return salary; }
// Setter methods
void setName(const std::string& n) { name = n; }
void setAge(int a) {
if (a > 0 && a < 120) age = a;
else std::cout << "Invalid age" << std::endl;
}
void setSalary(double s) {
if (s >= 0) salary = s;
else std::cout << "Invalid salary" << std::endl;
}
void displayInfo() const {
std::cout << "Name: " << name << ", Age: " << age
<< ", Salary: $" << salary << std::endl;
}
};
int main() {
Employee emp("Alice", 30, 50000);
emp.displayInfo();
emp.setAge(31);
emp.setSalary(55000);
emp.displayInfo();
emp.setAge(-5); // This will print an error message
return 0;
}