Multiple inheritance,friend function and multiple file in oop(object oriented programming)

 Multiple inheritance,friend function and     multiple file

Task 1

Create Class Person with variables weight,height, gender. Create another Class Employee with variables designation, HoursPerDay. Now create another class Teacher and inherit it from Person and Employee and add function display() which should show all the details related to teacher.

#include<iostream>
#include<string>
using namespace std;
class Person{
            int weight, height; string gender;
public:
            Person()
            {
                        weight = height = 0;
                        gender = "0";
                        cout << "Default person" << endl;
            }
};
class Employee{
            string designation; int hourPerRate;
public:
            Employee(){
                        designation = "0";
                        hourPerRate = 0;
                        cout << "DEfault Employee" << endl;
            }
};
class Teacher:public Person,public Employee{
public:
            void display()
            {
                        cout << "This is working:" << endl;
            }
};
int main()
{
            Teacher t1; t1.display();
            getchar();
            getchar();
            return 0;
}      

          

       
 

 

Task 2:

Create two classes named Mammals and MarineAnimals. Create another class named BlueWhale which inherits both the above classes. Now, create a function in each of these classes which prints "I am mammal", "I am a marine animal" and "I belong to both the categories: Mammals as well as Marine Animals" respectively. Now, create an object for each of the above class and try calling:
1 - function of Mammals by the object of Mammal
2 - function of MarineAnimal by the object of MarineAnimal
3 - function of BlueWhale by the object of BlueWhale
4 - function of each of its parent by the object of BlueWhale


#include<iostream>
#include<string>
using namespace std;
class Mammals{
public:
            void show()
            {
                        cout << "I am Mammals" << endl;
            }
};
class MarineAnimals{
public:
            void show2()
            {
                        cout << "I am MarineAnimal" << endl;
            }
};
class BlueWhale:public Mammals,public MarineAnimals{
public:
            void show3()
            {
                        cout << "I belong to both of the catogories" << endl;
                        cout << "Mammals and MarineAnimals" << endl;
            }
};
int main()
{
            Mammals m1; MarineAnimals a1; BlueWhale b1;
            m1.show(); a1.show2(); b1.show3(); b1.show2(); b1.show();
            getchar();
            getchar();
            return 0;
}      

          

       
 

Comments

Popular posts from this blog

Concepts of OOP (object oriented programming)

Concepts in c++........