Wednesday, October 1, 2014

WAP with student as abstract class and create derived classes Engineering Medicine and Science from base class student. Create objects of the derived classes and process them and access them using array of pointers of type base class student.

Code:

#include
#include
class student
{
    protected:
    char name[20],dept[20];
    public:
    virtual void get()=0;
    virtual void show()=0;
};
class engineering:public student
{
    public:
    void get()
    {
            cout<<"\n***Engineering Student***";
            cout<<"\n\nEnter name of the student:";
            cin>>name;
            cout<<"\nEnter department:";
            cin>>dept;
    }
            void show()
            {
                cout<<"\n\nDATA";
                cout<<"\nName:"<
                cout<<"\nDepartment:"<
            }
};
class medicine:public student
{
    public:
            void get()
            {
                cout<<"\n***Medicine Student***";
                cout<<"\n\nEnter name of the student:";
                cin>>name;
                cout<<"\nEnter department:";
                cin>>dept;
            }
            void show()
            {
                cout<<"\n\nDATA";
                cout<<"\nName:"<
                cout<<"\nDepartment:"<
            }
};
class science:public student
{
    public:
            void get()
            {
                cout<<"\n***Science Student***";
                cout<<"\n\nEnter name of the student:";
                cin>>name;
                cout<<"\nEnter department:";
                cin>>dept;
            }
            void show()
            {
                cout<<"\n\nDATA";
                cout<<"\nName:"<
                cout<<"\nDepartment:"<
            }
};
void main()
{
            clrscr();
            int i;
            student *s[3];
            s[0]=new engineering;
            s[1]=new medicine;
            s[2]=new science;
            for(i=0;i<3 i="" o:p="">
            {
                        s[i]->get();
            }
            for(i=0;i<3 i="" o:p="">
            {
                        s[i]->show();
            }
            getch();
}

No comments:

Post a Comment