Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions Multilevelinheritance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

#include<iostream>
using namespace std;
class person
{
private:
char name[15], address[15];
public:
void getdata()
{
cout<<"\nEnter Name: ";
cin>>name;
cout<<"\nEnter address: ";
cin>>address;
}
void showdata()
{
cout<<endl<<"Name: "<<name;
cout<<endl<<"Address: "<<address;
}
};

// derived class from parent class Person
class employee:public person
{
private:
int empID;
public:
void getdata()
{
person::getdata();
cout<<"\nEnter employee ID ";
cin>>empID;
}
void showdata()
{
person::showdata();
cout<<endl<<"Employee ID: "<<empID;
}
};

// derived class from parent class person
class manager: public employee
{
private:
char qual[10];
public:
void getdata()
{
employee::getdata();
cout<<"\nEnter qualification: ";
cin>>qual;
}
void showdata()
{
employee::showdata();
cout<<"\nQualification: "<<qual;
}
};

// driver program
int main()
{
manager obj;
obj.getdata();
obj.showdata();
return 0;
}





80 changes: 80 additions & 0 deletions Virtual.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@


#include <iostream>

using namespace std;



class base {

public:

virtual void print()

{

cout << "print base class" << endl;

}



void show()

{

cout << "show base class" << endl;

}
};



class derived : public base {

public:

void print()

{

cout << "print derived class" << endl;

}



void show()

{

cout << "show derived class" << endl;

}
};



int main()
{

base* bptr;

derived d;

bptr = &d;



// virtual function, binded at runtime

bptr->print();



// Non-virtual function, binded at compile time

bptr->show();
}