Answer to Question #201091 in C++ for Kawish Ali

Question #201091

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++


1
Expert's answer
2021-05-31T07:34:22-0400
#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();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Kawish Ali
31.05.21, 15:13

Nice work. I concern with you when I have any c++ problem which I don't solve. Thanks.

Leave a comment

LATEST TUTORIALS
New on Blog