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

/* INSTRUCTIONS: 1) Create a class called Car that inherits from the Vehicle cla

ID: 3660460 • Letter: #

Question

/* INSTRUCTIONS: 1) Create a class called Car that inherits from the Vehicle class. 2) In the main() function, create a single instance of the Car class. 3) Create a loop that asks the user the enter in values for the horizontal and vertical distance travelled, as in the example below. The loop should repeat three (3) times as shown. The total horizontal and vertical distances moved should be updated with each entry by the user. Note that distances can be positive or negative (think 2 D x-y grid with the car starting at the center (0,0)) 4) Call the print_location function to print final location of the car EXAMPLE PRINTOUT: Please enter a horizontal distance: 10 Please enter a vertical distance: 10 Please enter a horizontal distance: 12 Please enter a vertical distance: -5 Please enter a horizontal distance: 5 Please enter a vertical distance: 7 Final Location: horizontal = 27 vertical = 12 distance from origin = 29.55 BONUS (10 points maximum to total final grade): Use vectors to keep track of all the horizontal and vertical moves. To simplify the code, this code can be in the main() function rather than in the class. Add the following lines to the bottom of the printout above that shows all the moves made and their averages: Horizontal moves: 10 12 5 Average horizontal move: 9.00 Vertical moves: 10 -5 7 Average vertical move: 4.00 */ #include #include #include using namespace std; class Vehicle { // protected means that it is not visible to the outside // but IS available to subclasses protected: int vertical_location_; int horizontal_location_; public: virtual void move_vertically(int distance) = 0; virtual void move_horizontally(int distance) = 0; virtual void print_location() = 0; Vehicle(){ vertical_location_ = 0; horizontal_location_ = 0; } }; int main() { return 0; }

Explanation / Answer

#include #include using namespace std; string getMake(); int getYear(); void setSpeed(int); void setYear(int); void setMake(string); class Car { private: int year,speed; string make; public: Car(int newYear, string newMake) { year=newYear; void setYear(); make=newMake; speed=0; }; int getSpeed() //get speed function {return speed;} void Car::setYear(int newYear) //function to set year to 2012 if it receives a value inbewteen 1900 and 2030 { if(newYear2030) year=2012; else year = newYear; } void setSpeed(int speed) //function to set the speed to 0 if it recives a negitive value { if(speed=5) speed-=5; else speed=0; } int getYear() { return year; } string getMake() { return make; } int main() { Car objectCar(2010,"Mazda"); cout