Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please help me with question e Examine Listing 1 and answer the following questions. Each question is independent of the others and assumes, as a
please help me with question e
Examine Listing 1 and answer the following questions. Each question is independent of the others and assumes, as a starting point, the code that is given in Listing 1. d) Is the use of inheritance a good design decision in this situation? Explain your answer. (4 marks) e) Refactor the class hierarchy to use composition instead of inheritance. The client code, which is given in Listing 2 and uses the existing hierarchy, must be able to use the refactored code without having to be modified. (8 marks) auto b = Book:"The Great Gatsby", "F.Scott Fitzgerald", 4\}; cout b.author() endl; auto d= DVD { "Star Wars: Episode V - The Empire Strikes", 124, 3\}; cout d. runtime() endl; b. borrowItem(); d. borrowItem(); b. returnItem(); cout d.title() ": " "available copies: " d. availableCopies() endl; cout b.title() ": " "available copies: " b.availableCopies() endl; Examine Listing 1 and answer the following questions. Each question is independent of the others and assumes, as a starting point, the code that is given in Listing 1. d) Is the use of inheritance a good design decision in this situation? Explain your answer. (4 marks) e) Refactor the class hierarchy to use composition instead of inheritance. The client code, which is given in Listing 2 and uses the existing hierarchy, must be able to use the refactored code without having to be modified. (8 marks) auto b = Book:"The Great Gatsby", "F.Scott Fitzgerald", 4\}; cout b.author() endl; auto d= DVD { "Star Wars: Episode V - The Empire Strikes", 124, 3\}; cout d. runtime() endl; b. borrowItem(); d. borrowItem(); b. returnItem(); cout d.title() ": " "available copies: " d. availableCopies() endl; cout b.title() ": " "available copies: " b.availableCopies() endlStep 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