Answer to Question #265824 in C++ for Amit

Question #265824

Write a program with Student as abstract class and create derive classes Arts, Science from base class Student. Create the objects of the derived classes and process them and access them using array of pointer of type base class Student.



1
Expert's answer
2021-11-14T09:21:40-0500
#include<iostream>
using namespace std;
class Student
{
    protected:
char name[20], depart[20];
    public:
virtual void get_data() = 0;
        virtual void show_data() = 0;
};
class Arts : public Student
{
    public:
        void get_data()
        {
            cout<<"Enter the information of Arts student ";
            cout<<"\nEnter Name: ";
            cin>>name;
            cout<<"Enter Department: ";
            cin>>depart;
        }
        void show_data()
        {
            cout<<"\nThe information of Arts student is ";
            cout<<"\nName: "<<name;
            cout<<"\n Department: "<<depart;
        }
};
class Science : public Student
{
    public:
        void get_data()
        {
            cout<<"\nEnter information of Science Student: \n";
            cout<<"Enter name: ";
            cin>>name;
            cout<<"Enter Department: ";
            cin>>depart;
        }
        void show_data()
        {
            cout<<"The information of Science student is: \n";
            cout<<"\nName: "<<name;
            cout<<"\nDepartment: "<<depart;
        }
};
int main()
{
    Student *stu[2];
    stu[0] = new Arts;
    stu[1] = new Science;
    for(int i = 0; i<3; i++)
    {
        stu[i]->get_data();
    }
    for(int i = 0; i< 3; i++)
    {
        stu[i]->show_data();
    }
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS