Skip to content

Instantly share code, notes, and snippets.

@krvajal
Created January 9, 2018 20:25
Show Gist options
  • Save krvajal/4f88f650d3cfdb45d34318afbb9ac10b to your computer and use it in GitHub Desktop.
Save krvajal/4f88f650d3cfdb45d34318afbb9ac10b to your computer and use it in GitHub Desktop.
//Your task is as follows (note that class/function names are CaSE-SenSItiVe)
#include <string>
// 1. Create a class called Vehicle.
class Vehicle
{
public:
virtual const std::string GetType() const = 0;
virtual unsigned int GetMaxSpeed(bool isMPH) = 0;
virtual ~Vehicle() = default;
};
// 2. Vehicle should have two PURE-Virtual member functions:
// a) "GetType() const" which returns a "const std::string&"
// b) "GetMaxSpeed(bool isMPH)" which returns an unsigned int.
// 3. Create a class called Car that is derived from Vehicle.
class Car : public Vehicle
{
public:
const std::string GetType() const
{
return "car";
}
unsigned int GetMaxSpeed(bool isMPH)
{
return (isMPH) ? 155 : 249;
}
};
// 4. Car should return "car" when GetType() is called on it.
// You should store the string on the class since GetType() returns a reference.
// 5. Car should return 155 when GetMaxSpeed(true) is called on it.
// 6. Car should return 249 when GetMaxSpeed(false) is called on it.
// 7. Create a class called Bus that is also derived from Vehicle.
class Bus : public Vehicle
{
public:
const std::string GetType() const
{
return "bus";
}
unsigned int GetMaxSpeed(bool isMPH)
{
return (isMPH) ? 50 : 80;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment