oops
oops
Practical No.10
Aim: Make a class Employee with a name and salary. make a class Manager inherit from
Employee. Add an instance variable named department, of type string. Supply a method to to
string that prints the manager’s name, department and salary. Make a class or Executive inherits
from Manager. Supply method to string that prints the string “Executive” followed by the
information stored in the Manager superclass object . supply a test program that tests these
classes and methods.
- Declare two private instance variables: name of type std::string and salary of type double.
- Create a constructor Employee(std::string name, double salary) to initialize the instance
variables.
- Provide getter methods getName() and getSalary() to access the instance variables.
Create a new C++ class called Employee.
- Declare two private instance variables: name of type std::string and salary of type double.
- Create a constructor Employee(std::string name, double salary) to initialize the instance
variables.
- Provide getter methods getName() and getSalary() to access the instance variables.
Create a new C++ class called Executive that inherits from the Manager class.
- Override the print() method to print the prefix "Executive: " followed by the information stored
in the Manager superclass object.
Create a new C++ program with a main() function.
- Create objects of the Employee, Manager, and Executive classes Use the print() methods to
print the information stored in each object.
Source Code:
SOURCE CODE:
#include <iostream>
#include <string>
using namespace std;
class Employee {
public:
string name;
double salary;
Employee(string n, double s) {
name = n;
salary = s;
}
};
void print() {
cout << "Executive:" << endl;
Manager::print();
}
};
int main() {
Executive e("sunil", 50000, "Sales");
e.print();
return 0;
}
OUTPUT:
Executive:
Name: sunil
Salary: 50000
Department: Sales