Pages

Tuesday, October 11, 2011

2.Inheritance

WAP USING INHERITANCE TO DISPLAY STAFF DETAILS


#include<iostream.h>
#include<conio.h>
class staff
{
int staff_id;
char name[30];
public:
staff()
{
cout<<"Enter staff_id & name::";
cin>>staff_id>>name;
}
void disp()
{
cout<<"\nStaff_id::"<<staff_id;
cout<<"\nName of staff::"<<name;
}
};

class lecturer:public staff
{
char subject[20],dept[20];
public:
lecturer()
{
cout<<"Enter dept & subject::";
cin>>dept>>subject;
}
void disp1()
{
cout<<"\nDepartment::"<<dept;
cout<<"\nSubject::"<<subject;
}
};

class admin_staff:public staff
{
char post[20],dept[20];
public:
admin_staff()
{
cout<<"Enter your post & department::";
cin>>post>>dept;
}
void disp2()
{
cout<<"\nPost::"<<post;
cout<<"\nDepartment::"<<dept;
}
};

class librarian:public staff
{
char shift[20];
public:
librarian()
{
cout<<"\nEnter your shift::";
cin>>shift;
}
void disp3()
{
cout<<"\nShift::"<<shift;
}
};
void main()
{
clrscr();
lecturer l;
admin_staff as;
librarian l1;
cout<<"\n\nLecturer details::\n";
l.disp();
l.disp1();
cout<<"\n\nAdmin details::\n";
as.disp();
as.disp2();
cout<<"\n\nLibrarian details::\n";
l1.disp();
l1.disp3();
getch();
}

No comments: