Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 4 pieces

of information:

1. A string no longer than 40 characters that holds the Vehicle's type

 (eg. "car", "truck", "plane", "motorcycle", etc.)

2. A whole number that stores how many wheels the vehicle contains.

3. A precision value that stores the Vehicle's maximum speed.

4. A precision value that stores the Vehicle's weight.

The Vehicle class MUST contain the following public member functions:

1). 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 2 precision

 values representing the speed and weight accordingly and sets the object's

 data members accordingly.

2). A default Vehicle sets its type to "Car", wheels to 4, speed to

 225.5 and weight to 3251.8.

3). A post-increment operator++ that increases the Vehicle's speed by 1.1.

4). A pre-increment operator++ that increases the Vehicle's weight by 10.5.

5). 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 T=type, N=wheels, W=weight, and S=speed) NOTE: weight and speed are

 displayed accurate to 2 decimal places.

 For example, if the Vehicle's type was Bicycle, had 2 wheels, weighed 23.87,

 and had a speed of 38.93, then the "motion" function would display:

 Bicycle has 2 wheels, weighs 23.87, and travels at 38.93

6). Create a new class named Car that is derived from Vehicle that contains

 all the members of a Vehicle, but adds to more fields:

 1. A string no longer than 40 characters that holds the Car's make, and

 2. A string no longer than 40 characters that holds the Car's model.

7). When a Car object is created, it MUST be passed 6 pieces of information:

 1. type, 2. wheels, 3. speed, and 4. weight (these MUST be sent to the base class),

 5. make, and 6. model.

8). 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 Ma=make, Mo=model, T=type, N=wheels, W=weight, and S=speed)

 For example, if the Car's make was Honda, the model was Civic, type was car, had

 4 wheels, weighed 2897.32, and has a speed of 178.55, then the "motion" function

 would display:

 This Honda Civic is a Car and has 4 wheels, weighs 2897.32, and travels at 178.55

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 6, 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 v1, v2("Plane", 16, 532.71, 98722.83);

 v1++;

 ++v1;

 v2++;

 v1.motion( );

 v2.motion( );

 Car c1("BMW", "M3", "Car", 4, 288.33, 3122.89);

 c1++;

 c1.motion( );

 return 0;

}

// The output of the above program should be EXACTLY as displayed below

Car has 4 wheels, weighs 3262.30, and travels at 226.60

Plane has 16 wheels, weighs 98722.83, and travels at 533.81

This BMW M3 is a Car and has 4 wheels, weighs 3122.89, and travels at 289.43

/* ========== 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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microeconomics An Intuitive Approach with Calculus

Authors: Thomas Nechyba

1st edition

538453257, 978-0538453257

More Books

Students also viewed these Programming questions