Write a Cpp code for public derivation of single inheritance?

All QuestionsCategory: Cpp LanguageWrite a Cpp code for public derivation of single inheritance?
Chetan Shidling Staff asked 5 years ago

I need code.

1 Answers
Chetan Shidling Staff answered 5 years ago

Code:

#include <iostream>
using namespace std;
class stud
{
private:
int id;
char name[20];
public:
void getstud()
{
cout<<“Enter the student id and student name:\n”;
cin>>id>>name;
}
void putstud()
{
cout<<“Id :”<<id<<endl;
cout<<“Name :”<<name<<endl;
}
};
class physical : public stud //public derivation
{
float ht, wt;
public:
void getph()
{
cout<<“Enter the student height and weight: \n”;
cin>>ht>>wt;
}
void putph()
{
cout<<“Height :”<<ht<<endl;
cout<<“Weight :”<<wt<<endl;
}
};
int main()
{
physical ph;
ph.getstud();
ph.getph();
ph.putstud();
ph.putph();
return 0;
}

Output:

Enter the student id and student name:
420
ChetanShidling
Enter the student height and weight:
7
80
Id:420
Name: ChetanShidling
Height:7
Weight:80