---
title: "Manager derived from person and employee"
subject: "Object Oriented Programming"
chapter: 6
key: "semester_3/object_oriented_programming:manager-person-employee"
source: https://www.bctengineer.com/q/semester_3/object_oriented_programming/manager-person-employee
site: BCT Engineering
---

# Manager derived from person and employee

Object Oriented Programming · Chapter 6: Inheritance

- Asked in: 2072 Chaitra, 5 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_3/object_oriented_programming/manager-person-employee
- Whole chapter: https://www.bctengineer.com/md/semester_3/object_oriented_programming/chapter-6

## Question

Create a derived class manager from two base classes person and employee. Assume suitable data members in each class and display the information.

## Short answer

Manager inherits Person (name, age) and Employee (empId, salary) via multiple inheritance, adding department and staffCount. Input and display functions are defined to read and print all data, with no ambiguity due to distinct member names.

## Answer

Class `Manager` is derived from two base classes, `Person` and `Employee` (multiple inheritance). Assumed data: `Person` has name and age; `Employee` has employee id and salary; `Manager` adds department and number of staff managed.

```cpp
#include <iostream>
#include <string>
using namespace std;

class Person {
protected:
    string name;
    int age;
public:
    void getPerson() {
        cout << "Name: "; cin >> name;
        cout << "Age: ";  cin >> age;
    }
    void showPerson() {
        cout << "Name: " << name << ", Age: " << age << endl;
    }
};

class Employee {
protected:
    int empId;
    float salary;
public:
    void getEmployee() {
        cout << "Employee id: "; cin >> empId;
        cout << "Salary: ";      cin >> salary;
    }
    void showEmployee() {
        cout << "Id: " << empId << ", Salary: " << salary << endl;
    }
};

class Manager : public Person, public Employee {
    string department;
    int staffCount;
public:
    void getdata() {
        getPerson();
        getEmployee();
        cout << "Department: ";        cin >> department;
        cout << "Number of staff: ";   cin >> staffCount;
    }
    void display() {
        showPerson();
        showEmployee();
        cout << "Department: " << department
             << ", Staff managed: " << staffCount << endl;
    }
};

int main() {
    Manager m;
    m.getdata();
    cout << "\n--- Manager information ---" << endl;
    m.display();
    return 0;
}
```

**Sample run:**

```text
Name: Ram
Age: 40
Employee id: 101
Salary: 85000
Department: Sales
Number of staff: 12

--- Manager information ---
Name: Ram, Age: 40
Id: 101, Salary: 85000
Department: Sales, Staff managed: 12
```

`Manager` inherits all public members of both bases, so it can call `getPerson()` and `getEmployee()` directly. Since the two bases have no members with the same name, there is no ambiguity.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Manager derived from Person and Employee is which type?
   A. Multiple inheritance
   B. Multilevel
   C. Hierarchical
   D. Single
   Answer: A. A class with two base classes is multiple inheritance. (Key point: Inheritance type)

2. Why is there no ambiguity in this program?
   A. Because members are private
   B. Because Manager overrides everything
   C. Because the two bases have no members with the same name
   D. Because virtual is used
   Answer: C. Ambiguity needs same-named members; here the names differ. (Key point: Ambiguity)

3. How does Manager::getdata() get name and salary?
   A. Using the new keyword
   B. By redefining Person
   C. By friend only
   D. By calling getPerson() and getEmployee() directly
   Answer: D. Public members of both bases are inherited and can be called directly. (Key point: Calling base functions)

## Related in Object Oriented Programming

- [Access overridden members from derived class](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aaccess-overridden-members) — Object Oriented Programming, chapter 6, asked 2×
- [Student, teaching and non-teaching staff from person](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aperson-student-staff-program) — Object Oriented Programming, chapter 6
- [Time class: add two objects](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Atime-class-add-objects) — Object Oriented Programming, chapter 1
- [Effect of derivation types on class members](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aderivation-types-effect) — Object Oriented Programming, chapter 6
- [Add objects of two different classes](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Afriend-add-two-class-objects) — Object Oriented Programming, chapter 4, asked 2×
- [Need of virtual base class](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Avirtual-base-class) — Object Oriented Programming, chapter 6

## Related in other subjects

- [Create classes from design class diagrams](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Aclasses-from-design-class-diagram) — Object Oriented Analysis and Design, chapter 4, asked 2×
- [Identify conceptual classes; create domain model](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Aconceptual-classes-domain-model-steps) — Object Oriented Analysis and Design, chapter 2
- [Sort employee structures by salary](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astruct-employee-sort-salary) — Computer Programming, chapter 8, asked 2×
- [Inventory planning and ABC classes from data](https://www.bctengineer.com/question.md?key=semester_8%2Fconstruction_management%3Aabc-table-inventory-2077) — Construction Management, chapter 3
