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

Please help me with this assignment in C++ Design You will need to do the follow

ID: 3739869 • Letter: P

Question

Please help me with this assignment in C++

Design You will need to do the following: 1. Create an abstract class that has at least two subclasses. 2. The subclasses must override the pure virtual method(s) in the parent class. 3. Create a vector of pointers to the abstract class 4. The vector must contain pointers to child class objects (a mixture of the 2+ subclasses). 5. You must demonstrate polymorphism by looping through the vector and calling the same method on each element (at least one method that is overridden differently in each child class). 6. You must have a global function that goes through the vector and does a calculation on all the objects. (The polymorphism requirement in the previous step may be satisfied here.)

Explanation / Answer

Solution:

code:

#include <iostream>
#include <vector>

using namespace std;

class Vehicle
{
public:
   int numberOfWheels;
   Vehicle()
   {
       numberOfWheels = 0;
   }
   Vehicle(int wheels)
   {
       numberOfWheels = wheels;
   }
   virtual void printInfo()
   {
       cout<<"This is a vehicle with "<<numberOfWheels<<" wheels ";
   }
};

class Bike: public Vehicle
{
public:
   Bike():Vehicle(){}
   Bike(int wheels):Vehicle(wheels)
   {

   }
   void printInfo()
   {
       cout<<"This is a Bike with "<<numberOfWheels<<" wheels ";
   }
};

class Car: public Vehicle
{
public:
   Car():Vehicle(){};
   Car(int wheels):Vehicle(wheels)
   {

   }
   void printInfo()
   {
       cout<<"This is a Car with "<<numberOfWheels<<" wheels ";
   }
};
int main()
{
   vector<Vehicle> vehicles;
   Vehicle vehicle(3);
   Car car(4);
   Bike bike(2);
   vehicles.push_back(vehicle);
   vehicles.push_back(bike);
   vehicles.push_back(car);
   for(int i=0; i<3; i++)
   {
       vehicles[i].printInfo();
   }
   return 0;
}


I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)

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