0% found this document useful (0 votes)
6 views

oops

Uploaded by

Dipanshu Xi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

oops

Uploaded by

Dipanshu Xi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

2323030

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.

Software Used: Code Block


Procedure:
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 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;
}
};

class Manager : public Employee {


public:
string department;

Manager(string n, double s, string d) : Employee(n, s)


{
department = d;
}
void print() {
cout << "Name: " << name << endl;
cout << "Salary: " << salary << endl;
cout << "Department: " << department << endl;
}
};
class Executive : public Manager {
public:
Executive(string n, double s, string d) : Manager(n, s, d) {}

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

You might also like