Question
Write the code for a C + + class called Vehicle that can store 4 pieces of information: 1 . A string no longer than
Write the code for a C class called "Vehicle" that can store pieces
of information:
A string no longer than characters that holds the Vehicle's type
eg "car", "truck", "plane", "motorcycle", etc.
A whole number that stores how many wheels the vehicle contains.
A precision value that stores the Vehicle's maximum speed.
A precision value that stores the Vehicle's weight.
The Vehicle class MUST contain the following public member functions:
When a Vehicle object is created, it may be passed a char array string
representing the Vehicle's type, a whole number for wheels, and precision
values representing the speed and weight accordingly and sets the object's
data members accordingly.
A default Vehicle sets its type to "Car", wheels to speed to
and weight to
A postincrement operator that increases the Vehicle's speed by
A preincrement operator that increases the Vehicle's weight by
A function named "motion" that accepts no data and returns no data, but
displays the following information:
T has N wheels, weighs W and travels at S
where Ttype, Nwheels, Wweight, and Sspeed NOTE: weight and speed are
displayed accurate to decimal places.
For example, if the Vehicle's type was Bicycle, had wheels, weighed
and had a speed of then the "motion" function would display:
Bicycle has wheels, weighs and travels at
Create a new class named Car that is derived from Vehicle that contains
all the members of a Vehicle, but adds to more fields:
A string no longer than characters that holds the Car's make, and
A string no longer than characters that holds the Car's model.
When a Car object is created, it MUST be passed pieces of information:
type, wheels, speed, and weight these MUST be sent to the base class
make, and model.
A Car object also contains a function "motion" that displays all of the
pieces of information stored in a car as:
This Ma Mo is a T and has N wheels, weighs W and travels at S
where Mamake, Momodel, Ttype, Nwheels, Wweight, and Sspeed
For example, if the Car's make was Honda, the model was Civic, type was car, had
wheels, weighed and has a speed of then the "motion" function
would display:
This Honda Civic is a Car and has wheels, weighs and travels at
The Vehicle and Car classes and all member functions MUST be created by you.
MAIN PROGRAM:
Your solution may ONLY use functions from the following
included C and C library header files.
NOTE: For this lab you WILL INCLUDE the CLASSES both declarations AND definitions AND the main BELOW!
#include
using namespace std;
#include
Vehicle CLASS DECLARATION
your code here...
Vehicle CLASS MEMBER FUNCTIONS
your code here...
Car CLASS DECLARATION
your code here...
Car CLASS MEMBER FUNCTIONS
your code here...
int main
Vehicle v vPlane;
v;
v;
v;
vmotion;
vmotion;
Car cBMWM "Car", ;
c;
cmotion;
return ;
The output of the above program should be EXACTLY as displayed below
Car has wheels, weighs and travels at
Plane has wheels, weighs and travels at
This BMW M is a Car and has wheels, weighs and travels at
CODE TO PLACE IN YOUR SOURCE FILE FOR SUBMISSION STARTS BELOW
You may add your own helper functions or symbolic constants here.
The member functions below must ALL be correctly coded
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Heres the implementation for the Vehicle and Car classes include include include class Vehicle priva...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