Basic program for Full Name using Multilevel Inheritance
In this, we are going to see a basic program for Full Name using Multilevel Inheritance in C++ Programming Language. 
 


The Code given below can be used in TURBO C++ Compilers: -

#include <iostream.h>
#include<conio.h>

class GetFirstName
{
    public:
    string FirstName;
    void getFN()
    {
        cout << "Enter first name: ";
        cin >> FirstName;
    }
};

class Name : public GetFirstName
{
    public:
    string LastName, FullName;
    void getLN()
    {
        cout << "Enter last name: ";
        cin >> LastName;
    }
};

class Print : public Name
{
    public:
    void print()
    {
        FullName = FirstName + " " + LastName;
        cout << "Full name: " << FullName;
    }
};

void main()
{
    clrscr();
    Print obj1;
    obj1.getFN();
    obj1.getLN();
    obj1.print();
    getch();
}

//...........Coded by Sahil Shaikh


The Code given below can be used in gcc/g++ Compilers: -

#include <iostream>
using namespace std;

class GetFirstName
{
    public:
    string FirstName;
    void getFN()
    {
        cout << "Enter first name: ";
        cin >> FirstName;
    }
};

class Name : public GetFirstName
{
    public:
    string LastName, FullName;
    void getLN()
    {
        cout << "Enter last name: ";
        cin >> LastName;
    }
};

class Print : public Name
{
    public:
    void print()
    {
        FullName = FirstName + " " + LastName;
        cout << "Full name: " << FullName;
    }
};

int main()
{
    Print obj1;
    obj1.getFN();
    obj1.getLN();
    obj1.print();
    return 0;
}

//...........Coded by Sahil Shaikh


#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post