Question
Write a C++ class called Taxicab that has three int fields (data members) to store its current x- and y-coordinates and the total distance it
Write a C++ class called Taxicab that has three int fields (data members) to store its current x- and y-coordinates and the total distance it has driven so far. The class should have a constructor that takes two parameters and uses them to initialize the coordinates, and also initializes the odometer to zero. The class should have a default constructor that sets all three fields to zero. The data members of this class do not need to be set after they are initialized, so this class doesn't need any set methods - therefore the constructors will directly assign values to the data members instead of calling set methods to do it. The class should have a get method for each data member. It should have a method called moveX that takes an int parameter that tells how far the Taxicab should shift left or right. It should have a method called moveY that takes an int parameter that tells how far the Taxicab should shift up or down. For example, the Taxicab class might be used as follows:
Taxicab cab1; Taxicab cab2(5, -8); cab1.moveX(3); cab1.moveY(-4); cab1.moveX(-1); cout << cab1.getDistanceTraveled() << endl; cab2.moveY(7); cout << cab2.getY() << endl;
Your functions should have the following names:
getX
getY
getDistanceTraveled
moveX
moveY
The files must be named: Taxicab.hpp and Taxicab.cpp
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started