0% found this document useful (0 votes)
5 views3 pages

Experiment No 4 Oop

Uploaded by

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

Experiment No 4 Oop

Uploaded by

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

Experiment No.

4
Code :-
#include <iostream>

#include <string>

using namespace std;

class Person {

protected:

string name;

int age;

public:

void setPersonDetails(string pname, int page) {

name = pname;

age = page;

void displayPersonDetails() {

cout << "Name: " << name << endl;

cout << "Age: " << age << endl;

};

class Employee : public Person {

protected:

int empID;

public:

void setEmployeeDetails(int id) {

empID = id;
}

void displayEmployeeDetails() {

displayPersonDetails(); // Calling base class method

cout << "Employee ID: " << empID << endl;

};

class Manager : public Employee {

private:

string department;

public:

void setManagerDetails(string dept) {

department = dept;

void displayManagerDetails() {

displayEmployeeDetails(); // Calling derived class method

cout << "Department: " << department << endl;

};

int main() {

Manager mgr;

mgr.setPersonDetails("Alice Johnson", 35); // Setting person details

mgr.setEmployeeDetails(1023); // Setting employee details

mgr.setManagerDetails("Sales"); // Setting manager details

cout << "Manager Information:" << endl;

mgr.displayManagerDetails();

return 0;

}
Output :-

You might also like