Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Take the code below and modify it so that the Sport class becomes abstract. #inc

ID: 3555116 • Letter: T

Question

Take the code below and modify it so that the Sport class becomes abstract.

#include <iostream>
#include <string>
using namespace std;
class Sport
{
public:
Sport()
{
kind = "who knows";
}
void show()
{
cout << "this is " << kind << endl;
}
private:
string kind;
};
class BallSport : public Sport
{
public:
void set(string bt)
{
balltype = bt;
}
void show()
{
cout << "this is " << balltype << "ball ";
}
private:
string balltype;
};
int main()
{

//delcare an object
Sport sp;

//member function

sp.show();

//Create instance and call BallSport members

Ballsport bp;

bp.set("Let us do!");

bp.show();

//pause system for a while

system("pause");

return 0;


}

Explanation / Answer

#include <iostream>
#include <string>
using namespace std;
class Sport
{
public:
virtual void show() = 0; // pure virtual means class is abstract.
protected:
string kind;
};
class BallSport : public Sport
{
public:
void set(string bt)
{
balltype = bt;
}
void show()
{
cout << "this is " << balltype << "ball ";
}
private:
string balltype;
};
int main()
{
//delcare an object
//Sport sp; you cant create abstract class object...
//member function
//sp.show(); so this call is invalid.
//Create instance and call BallSport members
BallSport bp;
bp.set("Let us do!");
bp.show();
//pause system for a while
system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote