//accessing member functions and constructor of base class
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class person
{
protected:
int id;
char name[20],address[50];
public:
person()
{
id=0;
name[0]='\0';
address[0]='\0';
}
void getinfo()
{
cout<<"enter id ";
cin>>id;
cout<<"enter name ";
gets(name);
cout<<"enter address ";
gets(address);
}
void showinfo()
{
cout<<"your personal info: \n\n";
cout<<"id: "<<id<<endl;
cout<<"name: "<<name<<endl;
cout<<"address: "<<address<<endl;
}
};
class student:public person
{
private:
int roll,marks;
public:
student()
{
person::person();
roll=marks=0;
}
void getedu()
{
cout<<"enter roll no ";
cin>>roll;
cout<<"enter marks ";
cin>>marks;
}
void showedu()
{
cout<<"\n\n\nyour educational info\n\n";
cout<<"roll no "<<roll<<endl;
cout<<"marks "<<marks<<endl;
}
};
void main()
{
student s;
s.getinfo();
s.getedu();
s.showinfo();
s.showedu();
getch();
}
0 comments:
Post a Comment