Write a C++ program to create a database of the following items of the derived class. 

Name of the patient, sex, age, ward number, bed number, nature of the illness, date of admission. 
Design a base class consisting of data members: name of the patient, sex and age; and another base class consisting of the data members: bed number and nature of the illness. The derived class consists of the data member, date of admission.
(i) Add a new entry.
(ii) List the complete record.

Program Code:
#include<iostream>
using namespace std;
// declaration of base class A with data members and member functions
class A
{
protected:
char name[20];
char sex[10];
int age;
void get_data()
{
cout<<"Enter the name :";
cin>>name;
cout<<endl;
cout<<"Enter the age :";
cin>>age;
cout<<endl;
cout<<"enter the sex :";
cin>>sex;
cout<<endl;
}
void disp_data()
{
cout<<"Name :";
cout<<name;
cout<<endl;
cout<<"Age :";
cout<<age;
cout<<endl;
cout<<"Sex:";
cout<<sex;
}
};
// declaration of second base class b with data members and member functions
class B
{
protected:
int bed_number;
char nature_illness[40];
public:
void get_data()
{
cout<<"Enter the bed_number:";
cin>>bed_number;
cout<<endl;
cout<<"Enter the nature_illness:";
cin>>nature_illness;
cout<<endl;
}
void disp_data()
{
cout<<"bed_number : ";
cout<<bed_number;
cout<<endl;
cout<<"nature_illness : ";
cout<<nature_illness;
cout<<endl;
}
};


// declaration of derived class C which is derived from two base class A and B
class C : public A, public B
{
int date_admission;
public:
void get_data()
{
A :: get_data();// function of base class A call
B :: get_data();// function of base class B call
cout<<"Enter Data of Admission : ";
cin>>date_admission;
}
void disp_data()
{
A :: disp_data();// function of base class A call
B :: disp_data();// function of base class B call
cout<<"Date of Admission : ";
cout<<date_admission;
}
};
// declaration of main function 
int main()
{
C c1; // object of class C declaration
cout<<"Adding a new record to database : ";
c1.get_data();// function of derived class C call


cout<<endl;
cout<<"Displaying the added record to database : ";
c1.disp_data();// function of derived class C call
cout<<endl;
return 0;
}


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: