Sunday, March 17, 2013

Public Inheritance

#include "iostream"
using namespace std;
class institute
{
    char name[20];
    int telno;
    public:
    void getdata();
    void showdata();
};
class student:public institute//public inheritence
{
    int rollno;
    char sname[25];
    public:
    void readdata();
    void displaydata();
};
void institute::getdata()
{
    cin>>name;
    cin>>telno;
}
void student::readdata()
{
    cin>>sname;
    cin>>rollno;
}
void institute::showdata()
{
    cout<<name;
    cout<<telno;
}
void student::displaydata()
{
    cout<<sname;
    cout<<rollno;
}
int main()
{
    student s;
    s.getdata();
    s.readdata();
    s.showdata();
    s.displaydata();
    return 0;
}

0 comments:

Post a Comment