Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create a class called Carprocon.which helps you decide between two cars The class should have a class - wide ( member attribute ) variable called
Create a class called Carprocon.which helps you decide between two cars
The class should have a classwide member attribute variable called budget and set it to
The class should have the following instance variables:
price a double
model a string containing make and model
pros a vector of strings
cons a vector of strings
propoints a vector of integers
conpoints a vector of integers
The class should have the following methods
A constructor which takes the budget as argument, For C only, make a second overloaded constructor that can also take the make and model a string and the price double and use the second constructor for the second instance so you dont have to call setcar for the second instance.
setcar takes as input the make and model a string and the price double
setpro takes as input a pro for example Great gas mileage as well as an integer which ie: being high priority. It adds the pro to the pros list and adds the points to the propoints
setcon takes as input a pro for example No warranty as well as an integer which ie: being high priority. It adds the con to the cons list and adds the points to the conpoints
A printit method that prints out the budget, price, model, pros, cons, propoints, conpoints out nicely.
A sum method that takes as argument an arraylistor Python list of integers and returns the sum of them
A Compare method takes as input another car instance c and compares it to the data in this instance and decides what car you should buy. It does this by:
ctotal cpropoints cconpoints and thistotal thispropoints thisconpoints
Is the best formula, This way the cons are deducted and whichever car is left with the higher amount of pros would win
Let the user know the totals, and the largest takes priority for c lets call it ctotal Add up the pro points of this, and add up the con points of this. Let the user know the totals, the largest takes priority for this lets call it thistotal Use your sum function to add up
The larger of total and thistotal becomes the winner and the car you they should be Make sure to print out total, thistotal, ie:explain your final conclusion of what car makemodel they should buy.
points
In your main create two car instances, for example car and car Populate the data in each in the interest of time you do not have to make a user interface. You can hard code the data into your method calls in main. For each instance you will call setcar, and setpro add five pros with priority and setcons add five cons with priority
Call the printit method for the first car
Call the printit method for the second car
Now Call the compare method of the car and send in as an argument the first cars instance handle. The cars compare method will compare car with its own data and decide which car is better for you to buy. Using C
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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