single level inheritance accesing public members of base class
Mon Oct 02 2023 03:44:40 GMT+0000 (Coordinated Universal Time)
Saved by
@rahulk
#include <iostream>
using namespace std;
class stu
{
int id;
char name[10];
public:
void get_data()
{
cout<<"enter student name:";
cin>>name;
cout<<"enter student id:";
cin>>id;
}
void put_data()
{
cout<<"name="<<name;
cout<<"id="<<id;
}
};
class phy:public stu
{
int w ,h;
public:
void get_phy()
{
cout<<"enter student height:";
cin>>h;
cout<<"enter student weight:";
cin>>w;
}
void put_phy()
{
cout<<"height="<<h;
cout<<"weight="<<w;
}
};
int main()
{
phy p;
p.get_data();
p.put_data();
p.get_phy();
p.put_phy();
cout<<"hello";
return 0;
}
content_copyCOPY
Comments