create a class PERSON with name, age data members, Inherit class Boy from it and add some extra info in it like gender, phone #. Inherit this class by another STUDENT class with some educational information. At the end show all data from the super-child class in C++
#include<iostream>
#include<string>
using namespace std;
class PERSON
{
public:
string name;
int age;
};
class Boy : public PERSON
{
public:
string gender,phone_no;
};
class STUDENT : public Boy
{
public:
int rollno;
string standard,section;
void display()
{
cout<<"\nName : "<<name;
cout<<"\nAge : "<<age;
cout<<"\nGender : "<<gender;
cout<<"\nPhone number : "<<phone_no;
cout<<"\nRoll Number : "<<rollno;
cout<<"\nStandard : "<<standard;
cout<<"\nSection : "<<section;
}
};
int main()
{
STUDENT s1;
cout<<"Enter Name : ";
getline(cin,s1.name);
cout<<"Enter age : ";
cin>>s1.age;
cout<<"Enter gender : ";
cin>>s1.gender;
cout<<"Enter phone number : ";
cin>>s1.phone_no;
cout<<"Enter roll number : ";
cin>>s1.rollno;
cout<<"Enter standard : ";
cin>>s1.standard;
cout<<"Enter section : ";
cin>>s1.section;
s1.display();
}
Comments
Nice work. I concern with you when I have any c++ problem which I don't solve. Thanks.
Leave a comment