C++ Please help in designing constructors This assignment will involve implement
ID: 3667134 • Letter: C
Question
C++
Please help in designing constructors
This assignment will involve implementing polymorphism and inheritance. You will work with your assigned group. You must create a hierarchy of classes. Following is a diagram of that hierarchy with class member diagrams. You are not allowed to change any member declarations or locations ParkRide Class private static int numOfParkRides; string rideName; public: ParkRide) ParkRide (string); static int getNumOfParkRides ; string getRideName) const; virtual void restrictions() const = 0; virutal void show! nfo() const = 0; private private static int numofChildrenRides; int maxAge; static int numofTeenageRides; int minHeight; public: public: ChildrenRide); ChildrenRide (string, int); static int getNumOfChildrenRides; int getMaxAge() const; virtual void restrictions () const; virtual void show!nfo() const = 0; TeenageRide TeenageRide(string, int); static int getNumOfTeenageRides int getMinHeight) const; virtual void restrictions() const; virtual void show!nfo( ) const = 0; iking Clas public public: Carousel(); Carousel(string, int); virtual void showInfo) const; Viking); Viking (string, int); virtual void showInfo) const; Train Class public: Rolle public: Train) Train(string, int); virtual void showInfo) const; RollerCoaster(): RollerCoaster(string, int); virtual void showInfo) const;Explanation / Answer
ParkRide,h
#include<string>
using namespace std;
class ParkRide
{
public:
ParkRide();
ParkRide(string);
virtual ~ParkRide();
static int getNumOfParkRides(){ return numOfParkRides; }
string getRideName()const{ return rideName; }
virtual void restrictions()const = 0;
virtual void showInfo()const = 0;
private:
static int numOfParkRides;
string rideName;
};
int ParkRide::numOfParkRides = 0;
ParkRide::ParkRide(string name)
{
numOfParkRides++;
rideName = name;
}
ParkRide::ParkRide()
{
rideName = "uninitialized";
numOfParkRides++;
}
ChildrenRide.h
#include "ParkRide.h"
#include<iostream>
using namespace std;
class ChildrenRide :
public ParkRide
{
public:
ChildrenRide();
ChildrenRide(string, int);
virtual ~ChildrenRide();
static int getNumOfChildrenRides(){ return numOfChildrenRides; }
int getMaxAge()const;
virtual void restrictions()const;
virtual void showInfo()const = 0;
private:
static int numOfChildrenRides;
int maxAge;
};
int ChildrenRide::numOfChildrenRides = 0;
ChildrenRide::ChildrenRide() :ParkRide("uninitialized")
{
numOfChildrenRides++;
maxAge = -1;
}
ChildrenRide::ChildrenRide(string name, int age) :ParkRide(name)
{
numOfChildrenRides++;
maxAge = age;
}
int ChildrenRide::getMaxAge()const
{
return maxAge;
}
void ChildrenRide::restrictions()const
{
cout << " Rule: maximum age: " << maxAge << endl;
}
TeenageRide.h
#include "ParkRide.h"
#include<iostream>
using namespace std;
class TeenageRide :
public ParkRide
{
public:
TeenageRide();
~TeenageRide();
TeenageRide(string, int);
static int getNumOfTeenageRides();
int getMinHeight()const;
virtual void restrictions()const;
virtual void showInfo()const = 0;
private:
static int numOfTeenageRides;
int minHeight;
};
int TeenageRide::numOfTeenageRides = 0;
TeenageRide::TeenageRide() :ParkRide("uninitialized")
{
numOfTeenageRides++;
minHeight = -1;
}
TeenageRide::TeenageRide(string name, int height) :ParkRide(name)
{
numOfTeenageRides++;
minHeight = height;
}
int TeenageRide::getNumOfTeenageRides()
{
return numOfTeenageRides;
}
int TeenageRide::getMinHeight()const
{
return minHeight;
}
void TeenageRide::restrictions()const
{
cout << " Rule: minimum height: " << minHeight << endl;
}
Carousel.h
#include "ChildrenRide.h"
class Carousel :
public ChildrenRide
{
public:
Carousel();
Carousel(string, int);
virtual void showInfo()const;
};
Carousel::Carousel() :ChildrenRide("unitialized",-1)
{
}
Carousel::Carousel(string name, int age) : ChildrenRide(name, age)
{
}
void Carousel::showInfo()const
{
cout << "Carousel Ride Type" << endl;
cout << " Name: " << this->getRideName() << endl;
cout << " Info: " << "5 minutes on play horses" << endl;
restrictions();
}
Train.h
#include "ChildrenRide.h"
class Train :
public ChildrenRide
{
public:
Train();
Train(string, int);
virtual void showInfo()const;
};
Train::Train() :ChildrenRide("unitialized", -1)
{
}
Train::Train(string name, int age) : ChildrenRide(name, age)
{
}
void Train::showInfo()const
{
cout << "Train Ride Type" << endl;
cout << " Name: " << this->getRideName() << endl;
cout << " Info: " << "5 min train ride" << endl;
restrictions();
}
Viking.h
#include "TeenageRide.h"
class Viking :
public TeenageRide
{
public:
Viking();
~Viking();
Viking(string, int);
virtual void showInfo()const;
};
Viking::Viking() :TeenageRide("unitialized", -1)
{
}
Viking::Viking(string name, int height) : TeenageRide(name, height)
{
}
void Viking::showInfo()const
{
cout << "Viking Ride Type" << endl;
cout << " Name: " << this->getRideName() << endl;
cout << " Info: " << "10 minutes of swaying thrill" << endl;
restrictions();
}
RollerCoaster.h
#include "TeenageRide.h"
class RollerCoaster :
public TeenageRide
{
public:
RollerCoaster();
~RollerCoaster();
RollerCoaster(string, int);
virtual void showInfo()const;
};
RollerCoaster::RollerCoaster() :TeenageRide("unitialized", -1)
{
}
RollerCoaster::RollerCoaster(string name, int height) : TeenageRide(name, height)
{
}
void RollerCoaster::showInfo()const
{
cout << "Rollercoaster Ride Type" << endl;
cout << " Name: " << this->getRideName() << endl;
cout << " Info: " << "10 minutes of twists,turns and drops" << endl;
restrictions();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.