CIS247C Project Week 3 of 7 – Vehicle Class – Fully commented code with screenshots – Perfect Solution – Instant Delivery
Project Week 3 of 7: Overloaded Methods and Static Methods / Variables
SUMMARY
The project objective this week is to enhance last week’s Vehicle class by making the following changes:
• Create a static variable called numVehicles that holds an int and initialize it to zero. This will allow us to count all the Vehicle objects created in the main class.
• Add the copy constructor.
• Increment numVehicles in all of the constructors
• Decrement numVehicle in destructor
• Add overloaded versions of setYear and setMpg that accept strings. This way, we will have two “set” methods; one that accepts a string, and one that accepts its default data type.
Download the instructions and grading rubric in files section or clicking here.
Required Software
Connect to the Lab here.Links to an external site.
STEP 1: Understand the UML Diagram
• The following attribute has been added:
– static numVehicles: int = 0
• The following behaviors have been added:
• + static getNumVehicles( ) : int
+ Vechicle(vh: Vehicle)
• + setYear(string year) : void
• + setMpg(string mpg) : void
STEP 2: Create the Project
You will want to use the Week 2 project as the starting point.
STEP 3: Modify the Vehicle Class
1. Create a static numVehicles variable and initialize it to zero.
2. Create a copy constructor.
3. Update the destructor to decrement numVehicles by one.
4. Increment numVehicles by one in each of the constructors.
5. Create an overloaded setYear method and this time make the parameter a string.
6. Create an overloaded setMpg method and this time make the parameter a string.
**Remember that you will have to convert the string in the above two “set” methods to the data type of the attribute.**
7. Make the getNumVehicles a static method. This way, you can call it with the class name instead of an object name.
Be sure you follow proper commenting and programming styles (indentation, line spacing, etc.).
STEP 4: Modify the Main Method
In the Main class, create code statements that perform the following operations. Be sure you follow proper commenting and programming styles (header, indentation, line spacing, etc.). Note that several of the steps below were accomplished in last week’s assignment. New steps are in bold.
1. Using your code from Week 1, display a divider that contains the string “Start Program”.
2. Update and call the DisplayApplicationInformation function.
3. Create an Vehicle object using the default constructor.
4. Prompt for and then set year and mpg using the new overloaded setters. Consider using your getInput method from Week 1 to obtain data from the user for this step as well as Step 3.
5. Using your code from Week 1, display a divider that contains the string “Vehicle 1 Information”.
6. Display the Vehicle Information.
7. Create a second Vehicle object using the multi-arg constructor, setting each of the attributes with the following values: “Cadillac”, 2017, 26.5
8. Create a third object by copying the second object.
9. Delete the third object by calling the destructor method.
10. Display the number of vehicles created using getNumVehicles. Remember to access getNumVehicles using the class name, not the Vehicle object.
11. Update and call the TerminateApplication function.
STEP 5: Compile and Test
When done, compile and run your code.
Then, debug any errors until your code is error-free.
Check your output to ensure that you have the desired output, modify your code as necessary, and rebuild.
STEP 6: Screenshots
• Capture a screenshot of your working code and paste into a Word document.
• Capture a screenshot of your group meeting/discussion and paste in the same Word document.
STEP 7: Submit Deliverables
• Put all of the Visual Studio Project files into a zip file.
• Upload the zip file and screenshots (Word document).
• Please include the names of all participating team members in word document.
• Only one submission is required for the entire group.
CIS247C Week 3 Project Overview
The objective of this week is to enhance last week’s Vehicle class by making the following changes:
• Create a static variable called numVehicles that holds an int and initialize it to zero. This will allow us to count all the Vehicle objects created in the main class.
• Add the copy constructor
• Increment numVehicles in all of the constructors
• Decrement numVehicle in destructor
• Add overloaded versions of setYear and setMpg that accept strings. This way, we will have two “set” methods; one that accepts a string, and one that accepts its default data type.
In the Vehicle class complete the following steps:
1. Create a static numVehicles variable and initialize it to zero.
2. Create a copy constructor.
3. Update the destructor to decrement numVehicles by one.
4. Increment numVehicles by one in each of the constructors.
5. Create an overloaded setYear method and this time make the parameter a string.
6. Create an overloaded setMpg method and this time make the parameter a string.
**Remember that you will have to convert the string in the above two “set” methods to the data type of the attribute.**
7. Make the getNumVehicles a static method. This way, you can call it with the class name instead of an object name.
In the main program create code statements that perform the following operations Note that several of the steps below were accomplished in last week’s assignment. New steps are in bold.
1. Using your code from Week 1, display a divider that contains the string “Start Program”.
2. Update and call the DisplayApplicationInformation function.
3. Create a Vehicle object using the default constructor.
4. Prompt for and then set year and mpg using the new overloaded setters. Consider using your getInput method from Week 1 to obtain data from the user for this step as well as Step 3.
5. Using your code from Week 1, display a divider that contains the string “Vehicle 1 Information”.
6. Display the Vehicle Information.
7. Create a second Vehicle object using the multi-arg constructor, setting each of the attributes with the following values: “Cadillac”, 2017, 26.5
8. Create a third object by copying the second object.
9. Delete the third object by calling the destructor method.
10. Display the number of vehicles created using getNumVehicles. Remember to access getNumVehicles using the class name, not the Vehicle object.
11. Update and call the TerminateApplication function.
Grading Rubric
Compiles correctly 10
Copy constructor 5
Static variable created and incremented in all constructors 5
getNumVehicles() function 5
Overloaded setters 10
main() with correct function calls and three objects instantiated 5
Correctly formatted output 5
Screenshot 5
TOTAL 50
Steps
1. Review instructions and UML diagram.
2. Compile and test the program to ensure there are no errors.
3. Capture screenshot of working code and paste into word document.
4. Submit zipped visual studio project and screenshot.
Refer to the following UML class diagram. No pseudocode is provided.
Vehicle
– make: string
– year: int
– mpg: double
– numVehicles: static int
+Vehicle()
+Vehicle(string make, integer year, double mpg)
+Vehicle(Vehicle &)
+~Vehicle()
+getMake(): string
+getYear(): int
+getMileage(): double
+setMake(string): void
+setYear(int): void
+setYear(string): void
+setMileage(double): void
+setMileage(string): void
+displayVehicle(): void
+getNumVehicles(): static int