Question: To solve this you must include three separate files for this program, Vehicle.h ( header file ) , Vehicle.cpp ( class implementation file ) ,
To solve this you must include three separate files for this program, Vehicle.hheader file Vehicle.cpp class implementation file and VehicleDriver.cpp driver file I need a really good answer. Please I need this within a day or latest two days. Also, take your time to make sure it is accurate, don't answer it too fast. :
C PRogramMING: DYNAMIC MEMORY ASSIGNMENT INSTRUCTIONS
OVERVIEW
The objective of this lab is to demonstrate dynamic allocation and deallocation of memory. This program leverages functionality that is useful in realworld applications where information is not always available at design time, and structures must be created at run time. This program also highlights the need for effective memory management to prevent issues with memory leaks, security, and overall program performance.
REMINDER
Do not put each class code into a single file.
INSTRUCTIONS
You will be creating a class named Vehicle that will be used to help show how to work with dynamic allocation and deallocation of memory using an array of pointers to pointers of Vehicle objects.
Class:
Name: Vehicle
Purpose: To accept and store the information about the specific Vehicle. Functions are provided to manipulate the data.
Constructor:
Zeroargument constructor that initializes the data members.
Must output message "Creating new Vehicle"
Destructor:
Default destructor.
Must output message In Vehicle destructor"
Data Members:
manufactureName string
Cannot be blank.
modelName string
Cannot be blank.
vehicleColor string
Cannot be blank.
numberOfTailLights int
This is the number of tail lights per side of the vehicle.
A random number between and inclusive
Note: Setters and Getters are required even if they are not used.
Functions:
setManufactureName and getManufactureName
setModelName and getModelName
setVehicleColor, and getVehicleColor,
setNumberOfTailLights and getNumberOfTailLights
In main prompt the user to enter the number of vehicles that he or she has owned in his or her life. The prompt must indicate that the number of vehicles is between and inclusive. Error check the number of vehicles. Dynamically create a builtin array based on this number not a vector or object of the array class to hold pointers to Vehicle objects.
Program Flow:
Request the number of vehicles owned.
Remember to errorcheck the input.
Dynamically create the array of pointers to pointers and use the entered number of vehicles owned as the array dimension.
Start a loop that will continue until the correct number of vehicles has been entered and stored.
Tip: This Lab can use a for loop to walk through the array. Remember that arrays in are based.
Dynamically generate a new Vehicle object.
This requires the use of the new keyword to create the pointer to the Vehicle object.
Request the information from the user for each of the three string data members and validate that a blank was not entered.
Using the rand function, generate a random number between and inclusive.
Required: Use the seed value of in the srand function that initializes the random numbers.
Using the setters, load the Vehicle object data members with the values entered or generated.
Add the Vehicle object to the array location pointed to by the for loop.
End of the processing loop
Start a loop to display the information about each Vehicle the array points to
See the output example below.
End of the processing loop
Start a loop that will dynamically deallocate each Vehicle object pointed to by the array.
Delete the Vehicle object pointed to by the current array element.
End of the processing loop
Deallocate the array.
End of the processing loop
End of program
Because the program uses dynamic memory to store the array and the objects in the array, be sure to deallocate all the memory before exiting. Do not use the older malloc and free functions; instead, use the C commands of new and delete
For this project, you will need an array of pointers to pointers. That means you will use the to define the array instead of the Look this information over, or search for C array of pointers to objects.
Because you are creating a pointer to a Vehicle object and then storing that pointer in the array of pointers, deallocating memory is a step process.
In the first step, you use a loop to walk through the array of pointers and delete the object being pointed to In the second step, you delete the array of pointers. Here is one example.The array of pointers named objects was defined as an array of pointers to pointers using the definition. Then, new objects of type object a class the code created are created, filled with data, and the pointer to the object is stored in the next array element.Here is some information on deallocating a memory array.
A sample of the program running is shown below:Use the setw function to defined the two column widths and use right and left to justify each column correctly.Example:
Note: The number parameter for the setw is the width
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
