You are on page 1of 2

/*Inheritance is the process of creating new classes from an existing class.

The
existing class is known as "BASE CLASS"
and the newly created class is called the "DERIVED CLASS".The derived class
inherits all capabilities
of the base class.It can be classified into sevaral other types.*/
/*Single inheritance-> It is the process of creating a new class from an
existing class*/

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class basic_info
{
private:
char name[20];
int roll_no;
char sex;

public:
void getdata();
void display();
};

class physical_info:public basic_info


{
private:
float height;
float weight;

public:
void getdata();
void display();
};

void basic_info::getdata()
{
cout<<"Enter your name:";
cin>>name;
cout<<"Enter roll no:";
cin>>roll_no;
cout<<"Enter your sex:";
cin>>sex;
}
void basic_info::display()
{
cout<<name<<" ";
cout<<roll_no<<" ";
cout<<sex<<" ";
}
void physical_info::getdata()
{
basic_info::getdata();
cout<<"Enter your height:\n";
cin>>height;
cout<<"Enter your weight:\n";
cin>>weight;
}
void physical_info::display()
{
basic_info::display();
cout<<setprecision(2); /*setprecision() is used to
control the number of digits */
cout<<height<<" "; /* of an output stream display of
a floating point value. */
cout<<weight<<" "; /* The setprecision() manipulator
prototype is defined in */
} /* the header file <iomanip.h>.The
default precision is 6.*/
void main()
{
physical_info a;
clrscr();
cout<<"Enter the following information:\n";
a.getdata();
cout<<"------------------------------------\n";
cout<<"Name Rollno Sex Height Weight\n";
cout<<"----------------------------------\n";
a.display();
cout<<endl;
cout<<"-----------------------------------\n";
}

You might also like