Question
Q2: Continue of previous question (40pt) 1. Copy the previous program to a new file. 2. Create a class named Car derived from Vehicle. a.
Q2: Continue of previous question (40pt) 1. Copy the previous program to a new file. 2. Create a class named Car derived from Vehicle. a. Private data member: weight dynamic member int b. Implement default and two argument constructors c. Redefine output function d. Mutator and accessor function for weight 3. Create a class named Boat derived from Vehicle. a. Private data member: hullLength dynamic member int b. Implement default and two argument constructors c. Redefine output function d. Mutator and accessor function for hullLength 4. Convert Vehicle to abstract class. 5. Override output function of Car and Boat class. 6. Override destructor for Car, Boat, Boat Use following main() to test your function. int main(){ // part 2 Car a,b("Honda",2000); a.output(); // Brand:TBD Weight: 0 b.output(); // Brand:Honda Weight: 2000 b.setBrand("Tesla"); b.setWeight(3000); b.output(); // Brand:Tesla Weight: 3000 // part 3 Boat c,d("Baja",100); c.output(); // Brand:TBD hullLength: 0 d.output(); // Brand:Baja hullLength: 100 d.setBrand("Bertram"); d.sethullLength(60); d.output(); // Brand:Bertram hullLength: 60 // part 4,5,6 Vehicle *e, *f; e = new Car("BMW",20000); e->output(); // Brand:Honda Weight: 2000 f = new Boat("Baja",150); f->output(); // Brand:Baja hullLength: 100
delete e; delete f; } Output from main: Brand: TBD Weight: 0 Brand: Honda Weight: 2000 Brand: Tesla Weight: 3000 Brand: TBD hullLength: 0 Brand: Baja hullLength: 100 Brand: Bertram hullLength: 60 Brand: BMW Weight: 20000 Brand: Baja hullLength: 150 ==> Car Destructor. ==> Vehicle Destructor. ==> Boats Destructor. ==> Vehicle Destructor. ==> Boats Destructor. ==> Vehicle Destructor. ==> Boats Destructor. ==> Vehicle Destructor. ==> Car Destructor. ==> Vehicle Destructor. ==> Car Destructor. ==> Vehicle Destructor. Answer:
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