Write a C++ Program for Enter Patient details using Inheritance. Here’s a Simple C++ Program for Enter Patient details using Inheritance in C++ Programming Language.
Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and fast implementation time.
When creating a class, instead of writing completely new data members and member functions, the programmer can designate that the new class should inherit the members of an existing class. This existing class is called the base class, and the new class is referred to as the derived class.
The idea of inheritance implements the is a relationship. For example, mammal IS-A animal, dog IS-A mammal hence dog IS-A animal as well and so on.
Types of Inheritance : :
There are different types of inheritance : :
Single Inheritance
Multiple Inheritance
Multilevel Inheritance
Hierarchical Inheritance
Hybrid (Virtual) Inheritance
Below is the source code for C++ Program for Enter Patient details using Inheritance which is successfully compiled and run on Windows System to produce desired output as shown below :
SOURCE CODE : :
/* C++ Program for Enter Patient details using Inheritance */
#include <iostream>
using namespace std;
const int LEN = 80;
class doctor
{
private:
char name[LEN];
char degree[LEN];
public:
void getedu()
{
cout<<"Enter the Doctor Name : ";
cin>> name;
cout<<"Enter Doctorate Degree : ";
cin>>degree;
}
void showedu()
{
cout<<"\nDoctor Name : "<<name;
cout<<"\nDoctorate Degree : "<<degree;
}
};
class patient
{
private:
char name[LEN];
char number [LEN];
public:
void getdata()
{
cout<<"\nEnter Patient Name : ";
cin>>name;
cout<<"\nEnter Bed Number : ";
cin>>number;
}
void showdata()
{
cout<<"\nPatient Name : "<<name;
cout<<"\nBed Number : "<<number;
}
};
class department
{
private:
char ward [LEN] ;
public:
void getdata()
{
cout<<"\nEnter Ward Name : ";
cin>>ward;
}
void showdata()
{
cout<<"\nWard Name : "<<ward;
}
};
class amount
{
private:
int dues;
patient pat;
doctor doc;
department dept;
public:
void getdata()
{
pat.getdata();
dept.getdata();
doc.getedu();
cout<<"Enter Dues of Patient : ";
cin>>dues;
}
void showdata()
{
pat.showdata();
dept.showdata();
doc.showedu();
cout<<"\nTotal Dues of Patient : "<<dues;
}
};
int main()
{
amount a1;
cout<<"\nEnter Data ";
a1.getdata();
cout<<"\nInserted Data is : \n";
a1.showdata();
return 0;
}
OUTPUT : :
/* C++ Program for Enter Patient details using Inheritance */
Enter Data
Enter Patient Name : CodezClub
Enter Bed Number : 123
Enter Ward Name : 321
Enter the Doctor Name : John
Enter Doctorate Degree : MBBS
Enter Dues of Patient : 2500
Inserted Data is :
Patient Name : CodezClub
Bed Number : 123
Ward Name : 321
Doctor Name : John
Doctorate Degree : MBBS
Total Dues of Patient : 2500
Process returned 0
Above is the source code and output for C++ Program for Enter Patient details using Inheritance which is successfully compiled and run on Windows System to produce desired output.
Types of Inheritance : :
There are different types of inheritance : :
Below is the source code for C++ Program for Enter Patient details using Inheritance which is successfully compiled and run on Windows System to produce desired output as shown below :
SOURCE CODE : :
OUTPUT : :
Above is the source code and output for C++ Program for Enter Patient details using Inheritance which is successfully compiled and run on Windows System to produce desired output.
need an explanation for this answer? contact us directly to get an explanation for this answer