Answer to Question #266513 in C++ for areeffrhn

Question #266513

You can write any program based on the title assigned.

Title: Sports Activity


The program must fulfil ALL the requirements below. The requirements listed below are the

MINIMUM requirement.


a) Create at least one (1) base class.

b) Create at least two (2) derived classes that inherit from the base class created in 2(a).

c) Create at least one (1) object for each class and one (1) array of objects for one of the classes.

d) Create at least one (1) default constructor for all the classes.

f) Apply dynamic memory allocation using keyword new and delete for any object or array

of objects.

g) Create at least one (1) virtual function.

h) Write sufficient comments to explain your program.


1
Expert's answer
2021-11-15T17:22:11-0500
#include<iostream>
using namespace std;
class Sports
{
    protected:
        char name[20], game[20];
    public:
virtual void get_data() = 0;
        virtual void show_data() = 0;
};
class vallyball : public Sports
{
    public:
        void get_data()
        {
            cout<<"Enter the information of sports man ";
            cout<<"\nEnter Name: ";
            cin>>name;
            cout<<"Enter game: ";
            cin>>game;
        }
        void show_data()
        {
            cout<<"\nThe information of sportsman is ";
            cout<<"\nName: "<<name;
            cout<<"\n field: "<<game;
        }
};
class rugby: public Sports
{
    public:
        void get_data()
        {
            cout<<"\nEnter information of sportsman: ";
            cout<<"\nEnter name: ";
            cin>>name;
            cout<<"\nEnter game: ";
            cin>>game;
        }
        void show_data()
        {
            cout<<"The information of sportsman is ";
            cout<<"\nName: "<<name;
            cout<<"\ngame: "<<game;
        }
};
int main()
{
    Sports *spt[2];
    spt[0] = new vallyball;
    spt[1] = new rugby;
    for(int i = 0; i<2; i++)
    {
        spt[i]->get_data();
    }
    for(int i = 0; i< 2; i++)
    {
        //virtual function
        spt[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