Provide the C++ implementation of the following.
The Person class has name and age as its attributes. It has an overloaded constructor to initialize the values and appropriate accessor and mutator methods. The Employee class has name of the employer and wage as its attributes with an overloaded constructor and appropriate accessor and mutator methods.
#include <iostream>
using namespace std;
class Person{
string name;
int age;
public:
Person(string _name, int _age) : name(_name), age(_age) {}
string getName() const {
return name;
}
int getAge() const {
return age;
}
void setName(string _name){
name = _name;
}
void setAge(int _age){
age = _age;
}
};
class Employee{
string name;
float wage;
public:
Employee(string _name, float _wage) : name(_name), wage(_wage) {}
string getName() const {
return name;
}
float getAge() const {
return wage;
}
void setName(string _name){
name = _name;
}
void setAge(float _wage){
wage = _wage;
}
};
Comments
Leave a comment