Question: C++ task There are two tasks to this assignment. Task 1 Currently you are using composition by creating an instance of a vector / ArrayList
C++ task There are two tasks to this assignment. 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, an 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, dont 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 persons 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.
examples of from previous programing to help you to understand the problem as this assignment relate to last two assigment.
/// /// File: Person.h /// Author: Freddie Taylor /// Student id: 0568771 /// Description: Assignment 1. /// Date: 1/23/2020 /// #ifndef PERSON #define PERSON #includeusing std::string; class Person { private: string mFirstName; string mLastName; string mAddress; public: // constructors Person(); Person(string first, string last); Person(string first, string last, string address); //mutators /*******************************************************//** @par Name setFirstName @par Purpose Sets the member attribute mFirstName @param [in] first Contains person's first name @param [out] None @return None @par References None @par Notes None **********************************************************/ void setFirstName(string first); /*******************************************************//** @par Name setLastName @par Purpose Sets the member attribute mLastName @param [in] last Contains person's last name @param [out] None @return None @par References None @par Notes None **********************************************************/ void setLastName(string last); /*******************************************************//** @par Name setAddress @par Purpose Sets the member attribute mAddress @param [in] address Contains person's address @param [out] None @return None @par References None @par Notes None **********************************************************/ void setAddress(string address); // accessors /*******************************************************//** @par Name getFirstName @par Purpose Gets the member attribute mFirstName @param [in] None @param [out] None @return The person's first name @par References None @par Notes None **********************************************************/ string getFirstName()const; /*******************************************************//** @par Name getLastName @par Purpose Gets the member attribute mLastName @param [in] None @param [out] None @return The person's last name @par References None @par Notes None **********************************************************/ string getLastName() const; /*******************************************************//** @par Name getAddress @par Purpose Gets the member attribute mAddress @param [in] None @param [out] None @return The person's address @par References None @par Notes None **********************************************************/ string getAddress() const; }; #endif
/// /// File: Person.cpp /// Author: Freddie Taylor /// Student id: 0568771 /// Description: Assignment 1. /// Date: 1/23/2020 /// #include#include "Person.h" using std::string; Person::Person() : Person("","","") { } Person::Person(string first, string last) : Person(first, last, "") { } Person::Person(string first, string last, string address) { this->setFirstName(first); this->setLastName(last); this->setAddress(address); } void Person::setFirstName(string first) { this->mFirstName = first; } void Person::setLastName(string last) { this->mLastName = last; } void Person::setAddress(string address) { this->mAddress = address; } string Person::getFirstName()const { return this->mFirstName; } string Person::getLastName() const { return this->mLastName; } string Person::getAddress() const { return this->mAddress; }
/// /// File: Main.cpp /// Author: Freddie Taylor /// Student id: 0568771 /// Description: Assignment 1. /// Date: 1/23/2020 /// #include#include #include "Person.h" using namespace std; void getPeople(Person fillArray[], const int size); void printPeople(Person printArray[], const int size); int main() { const unsigned int size = 5; Person people[size]; getPeople(people, size); system("CLS"); printPeople(people, size); return 0; } /*******************************************************//** @par Name getPeople @par Purpose Fill the array with people @param [in] fillArray Is the array to be filled @param [in] size Is the number of people to fill the array @param [out] None @return None @par References None @par Notes None **********************************************************/ void getPeople(Person fillArray[], const int size) { string input; cout << "You will be prompted to enter " << size << " names." << endl << endl; for (int i = 0; i < size; i++) { cout << "Enter the person's first name" << endl; getline (cin, input); fillArray[i].setFirstName(input); cout << "Enter the person's last name" << endl; getline(cin, input); fillArray[i].setLastName(input); cout << "Enter the person's address" << endl; getline(cin, input); fillArray[i].setAddress(input); cout << endl; } } /*******************************************************//** @par Name printPeople @par Purpose Print the people from the array @param [in] printArray Is the array to be printed @param [in] size Is the number of people in the array @param [out] None @return None @par References None @par Notes None **********************************************************/ void printPeople(Person printArray[], const int size) { cout << "The " << size << " people in the array are (first name, last name, and address):" << endl << endl; for (int i = 0; i < size; i++) { cout << printArray[i].getFirstName() << "\t" << printArray[i].getLastName() << "\t" << printArray[i].getAddress(); cout << endl; } }
this is assignment 2
//#################################################
//File:Addressbook.cpp
//Author:: Matthew Mai
//Description: assigment 3
//Date: Jaunary 29, 2021
//#################################################
#include "Person.h"
#include "Addressbook.h"
#include
using namespace std;
//Implementing constructors
Addressbook::Addressbook()
{
//Set to default values
firstName = "";
lastName = "";
address = "";
}
Addressbook::Addressbook(std::string first, std::string last)
{
//Assigning values
firstName = first;
lastName = last;
address = "";
}
Addressbook::Addressbook(std::string first, std::string last, std::string address)
{
//Assigning values
firstName = first;
lastName = last;
address = address;
}
//Mutator Methods
void Addressbook::setPerson(std::string first)
{
firstName = first;
}
void Addressbook::getPerson(std::string last)
{
lastName = last;
}
void Addressbook::findPerson(std::string add)
{
address = add;
}
//Accessor Methods
std::string Addressbook::setPerson()
{
return firstName;
}
std::string Addressbook::getPerson()
{
return lastName;
}
std::string Addressbook::findPerson()
{
return address;
}
this is a vector c++ programing.
I post assignment 2 to help you good a ideas which help you to understand assignment 3
This small project is geared to get you started on writing Object Oriented program using either Java or C++.
The AddressBook Class
Create a class called AddressBook that uses either
- C++ - Vector
in the data section of the class. Since this is a template / generic type you need to make sure that you specify that ArrayList or vector will hold a Person. You should use the Person class you created in Assignment 1. Essentially, we are creating a collection class. In other words, the AddressBook class will be a collection of Person classes.
Constructors
- AddressBook(); - default constructor. Should have no functionality.
- AddressBook(string first, string last); - Adds a Person class to the collection and sets address field to an empty string
- AddressBook(string first, string last, string address); - Adds a Person class to the collection.
Mutators
setPerson(string first, string last, string address); - Adds a Person to the collection
Accessors
C++ All accessors will return a pointer to a Person
- Person *getPerson(); - Returns the next Person in the collection. Each time this function is called it will return the next Person in the list or NULL if the AddressBook is empty. Once you get to the end of the list you should start from element 0 and return the first person.
- Person *findPerson(string last); - returns the found Person or NULL if Person is not in the AddressBook
- Person *findPerson(string first, string last); - returns the found Person or NULL of Person is not in the AddressBook
- void print();- Prints out the entire AddressBook
Note:
You need to use one code path whenever possible. This means you must have delegating constructors. The working constructor can call a function if you wish. In other words, if you have a function that performs a task, you should call it instead of writing duplicate code.
Main
Create functions in main.cpp that will test each of the functions you created. I will leave it up to you as to how to test them but please make sure that I cannot easily force your functions to crash.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
