CS Electrical And Electronics
@cselectricalandelectronics

Write a Cpp code for public derivation of single inheritance?

All QuestionsCategory: Cpp LanguageWrite a Cpp code for public derivation of single inheritance?
CS Electrical And Electronics Staff asked 4 years ago

I need code.

1 Answers
CS Electrical And Electronics Staff answered 4 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