Currently, you are using composition by creating an instance of a vector / ArrayList inside your AddressBook. This works fine but if we really think about it, and AddressBook is a collection like a stack or a queue or a vector for that matter. Your task is to: C++ derive AddressBook from vector. In other words, use the vector as a base class and derive AddressBook from it. This means that you will need to remove the Vector from the private section of your class. You are going to have to make some fundamental changes to your AddressBook so that you are using the vector / ArrayList functionality to store and retrieve people. In other words, you should be accessing the ArrayList / vector using this. C++ people, don’t forget you are returning pointers in the accessors of the AddressBook class Test your AddressBook the same way you did for assignment 2. If you have coded everything properly it should work the same. Task 2 Create class called Player that is derived from Person. The Player class should hold the following information Average Slugging Percentage On Base Percentage All should be double data types Constructors Default Player(string first, string last, string address, double average, double slugging, double onBase) You should delegate the default constructor to eliminate multiple code paths. Mutators void setAverage(double avg void setSlugging(double slug) void setOBP(double OnBase) Accessors double getAverage() double getSlugging() double getOBP() print function In the Person class add a public function called print. This function will print out the person’s first, last, address. This function should be a virtual function or method. In essence all overridden methods in Java are virtual Java students don't need to do anything except override the method.  In Player override the print function so that you print out the players name, address, average, slugging %, On base %. To print the information from the Person class you should call the print function from the Player print function. Test your new class by creating a couple of Players. Make sure you test all functionality and that your print function prints everything from both Person and Player.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question

03 Inheritance / Polymorphism

Task 1

Currently, you are using composition by creating an instance of a vector / ArrayList inside your AddressBook. This works fine but if we really think about it, and AddressBook is a collection like a stack or a queue or a vector for that matter. Your task is to:

C++ derive AddressBook from vector. In other words, use the vector as a base class and derive AddressBook from it. This means that you will need to remove the Vector from the private section of your class.

You are going to have to make some fundamental changes to your AddressBook so that you are using the vector / ArrayList functionality to store and retrieve people. In other words, you should be accessing the ArrayList / vector using this. C++ people, don’t forget you are returning pointers in the accessors of the AddressBook class

Test your AddressBook the same way you did for assignment 2. If you have coded everything properly it should work the same.

Task 2

Create class called Player that is derived from Person. The Player class should hold the following information

  • Average
  • Slugging Percentage
  • On Base Percentage

All should be double data types

Constructors

  • Default
  • Player(string first, string last, string address, double average, double slugging, double onBase)

You should delegate the default constructor to eliminate multiple code paths.

Mutators

  • void setAverage(double avg
  • void setSlugging(double slug)
  • void setOBP(double OnBase)

Accessors

  • double getAverage()
  • double getSlugging()
  • double getOBP()

print function

In the Person class add a public function called print. This function will print out the person’s first, last, address. This function should be a virtual function or method. In essence all overridden methods in Java are virtual Java students don't need to do anything except override the method. 

In Player override the print function so that you print out the players name, address, average, slugging %, On base %.

To print the information from the Person class you should call the print function from the Player print function.

Test your new class by creating a couple of Players. Make sure you test all functionality and that your print function prints everything from both Person and Player.

Can you help me solve this problem in C++ forms using the  Inheritance / Polymorphism

If you decide to create in Java then as least please transform the Java into C++ and explain to me in C++ form because I never took Java. 

 

 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Types of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education