In this, we are going to see a Basic program for Full Name using Single 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 the First Name: ";
cin >> FirstName;
}
};
class Name : public GetFirstName
{
public:
string LastName, FullName;
void getLN()
{
cout << "Enter the Last Name: ";
cin >> LastName;
}
void Print()
{
FullName = FirstName + " " + LastName;
cout << "Full name: " << FullName;
}
};
void main()
{
clrscr();
Name obj1;
obj1.getFN();
obj1.getLN();
obj1.Print();
getch();
}
//...........Coded by Shreya Idate
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 the First Name: ";
cin >> FirstName;
}
};
class Name : public GetFirstName
{
public:
string LastName, FullName;
void getLN()
{
cout << "Enter the Last Name: ";
cin >> LastName;
}
void Print()
{
FullName = FirstName + " " + LastName;
cout << "Full name: " << FullName;
}
};
int main()
{
Name obj1;
obj1.getFN();
obj1.getLN();
obj1.Print();
return 0;
}
//...........Coded by Shreya Idate
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP