Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with the extPerson class within the problem. I\'ve already defined t

ID: 3708430 • Letter: I

Question

I need help with the extPerson class within the problem. I've already defined the classes that this class will extend, however I have no idea how to start this problem. The problem is located below:

Using classes, design an online address book to keep track of the names, addresses, phone numbers, and birthdays of family members, close friends, and certain business associates. Your program should be able to handle a maximum of 500 entries.

     a. Define the class Address that can store a street address, city, state, and zip code. Use the appropriate methods to print and store the address. Also, use constructors to automatically initialize the data members.

     b. Define the class ExtPerson using the class Person (as defined in Example 8-8, Chapter 8), the classDate (as designed in this chapter's Programming Exercise 2), and the class Address. Add a data member to this class to classify the person as a family member, friend, or business associate. Also, add a data member to store the phone number. Add (or override) methods to print and store the appropriate information. Use constructors to automatically initialize the data members.

     c. Define the class AddressBook using previously defined classes. An object of type AddressBookshould be able to process a maximum of 500 entries.

The program should perform the following operations:

i.   Load the data into the address book from a disk, or file.

ii. Sort the address book by last name.

iii. Search for a person by last name.

iv. Print the address, phone number, and date of birth (if available) of a given person.

v. Print the names of the people whose birthdays are in a given month or between two given dates.

vi. Print the names of all the people between two last names.

Links to the classes I've built are located below:

https://pastebin.com/0yNVFnNk - person class

https://pastebin.com/M527dnWh - date class

https://pastebin.com/KT4SmYnA - address class

Any help is appreciated!!

Explanation / Answer

main.cpp

#include <iostream>
#include <string>
#include "addressBookType.h"
using namespace std;
int main()
{
   addressBookType addressBook;
   system("pause");
   return 0;
}

addressBookType.cpp

#include "addressBookType.h"

addressBookType::addressBookType()
   :arrayListType<extPersonType>(500)
{
}

addressBookType.h

#pragma once
#include "arrayListType.h"
#include "extPersonType.h"

class addressBookType :
   public arrayListType<extPersonType>
{
public:
   //constructors
   addressBookType();
   addressBookType(const string& new_fileName);

   int find(const string& lastName) const;
   void print(const extPersonType& person) const;
   void print(relationShipType relationship) const;
   void print(const dateType& oldDate, const dateType& newDate) const;
   void print(const string& highLastName, const string& lowLastName) const;
   void print() const;
};

addressType.cpp

#include "addressType.h"

addressType::addressType()
{
   setAddress("855 North Vermont Avenue", "Los Angeles", "California", "90029");
}
addressType::addressType(const string& new_streetAddress, const string& new_city, const string& new_state, const string& new_zipCode)
{
   setAddress(new_streetAddress, new_city, new_state, new_zipCode);
}

addressType.h

#pragma once
#include <string>
using namespace std;

class addressType
{
public:
   //constructors
   addressType();
   addressType(const string& new_streetAddress, const string& new_city, const string& new_state, const string& new_zipCode);

   //accessors
   void getAddress(string& new_streetAddress, string& new_city, string& new_state, string& new_zipCode) const;
   string getStreetAddress() const;
   string getCity() const;
   string getState() const;
   string getZipCode() const;

   //mutators
   void setAddress(const string& new_streetAddress, const string& new_city, const string& new_state, const string& new_zipCode);
   void setStreetAddress(const string& new_streetAddress);
   void setCity(const string& new_city);
   void setState(const string& new_state);
   void setZipCode(const string& new_zipCode);

private:
   string _streetAddress;
   string _city;
   string _state;
   string _zipCode;
};

arrayListType.h
#ifndef H_arrayListType
#define H_arrayListType


#include <iostream>
#include <cassert>

using namespace std;

template <class elemType>
class arrayListType
{
public:
    const arrayListType<elemType>& operator=(const arrayListType<elemType>&);
      //Overloads the assignment operator
    bool isEmpty() const;
    bool isFull() const;
      //Function to determine whether the list is full.
      //Postcondition: Returns true if the list is full;
      //    otherwise, returns false.
    int listSize() const;
      //Function to determine the number of elements in the list
      //Postcondition: Returns the value of length.
    int maxListSize() const;
      //Function to determine the size of the list.
      //Postcondition: Returns the value of maxSize.
    void print() const;
    bool isItemAtEqual(int location, const elemType& item) const;
   void insertAt(int location, const elemType& insertItem);
   void insertEnd(const elemType& insertItem);
      //Function to insert an item at the end of the list.
      //The parameter insertItem specifies the item to be inserted.
    void removeAt(int location);
    void retrieveAt(int location, elemType& retItem) const;
    void replaceAt(int location, const elemType& repItem);
    void clearList();
    int seqSearch(const elemType& item) const;
    void insert(const elemType& insertItem);
    void remove(const elemType& removeItem);

    arrayListType(int size = 100);
  
    arrayListType(const arrayListType<elemType>& otherList);
      //copy constructor

    ~arrayListType();

protected:
    elemType *list; //array to hold the list elements
    int length;      //to store the length of the list
    int maxSize;     //to store the maximum size of the list
};
template <class elemType>
bool arrayListType<elemType>::isEmpty() const
{
    return (length == 0);
}
template <class elemType>
bool arrayListType<elemType>::isFull() const
{
    return (length == maxSize);
}
template <class elemType>
int arrayListType<elemType>::listSize() const
{
    return length;
}
template <class elemType>
int arrayListType<elemType>::maxListSize() const
{
    return maxSize;
}
template <class elemType>
void arrayListType<elemType>::print() const
{
    for (int i = 0; i < length; i++)
        cout << list[i] << " ";

    cout << endl;
}
template <class elemType>
bool arrayListType<elemType>::isItemAtEqual(int location, const elemType& item) const
{
    return (list[location] == item);
}
template <class elemType>
void arrayListType<elemType>::insertAt(int location, const elemType& insertItem)
{
    if (location < 0 || location >= maxSize)
        cerr << "The position of the item to be inserted is out of range" << endl;
    else
        if (length >= maxSize) //list is full
            cerr << "Cannot insert in a full list" << endl;
        else
        {
            for (int i = length; i > location; i--)
                 list[i] = list[i - 1];   //move the elements down

            list[location] = insertItem; //insert the item at the
                                          //specified position

            length++;     //increment the length
    }
} //end insertAt
template <class elemType>
void arrayListType<elemType>::insertEnd(const elemType& insertItem)
{

    if (length >= maxSize) //the list is full
        cerr << "Cannot insert in a full list" << endl;
    else
    {
         list[length] = insertItem;   //insert the item at the end
         length++;   //increment the length
    }
} //end insertEnd
template <class elemType>
void arrayListType<elemType>::removeAt(int location)
{
    if (location < 0 || location >= length)
        cerr << "The location of the item to be removed is out of range" << endl;
    else
    {     
       list[location] = list[length - 1];
       length--;
    }
} //end removeAt
template <class elemType>
void arrayListType<elemType>::retrieveAt(int location, elemType& retItem) const
{
    if (location < 0 || location >= length)
        cerr << "The location of the item to be retrieved is out of range." << endl;
    else
        retItem = list[location];
} //end retrieveAt
template <class elemType>
void arrayListType<elemType>::replaceAt(int location, const elemType& repItem)
{
    if (location < 0 || location >= length)
        cerr << "The location of the item to be replaced is out of range." << endl;
    else
        list[location] = repItem;

} //end replaceAt
template <class elemType>
void arrayListType<elemType>::clearList()
{
    length = 0;
} //end clearList
template <class elemType>
int arrayListType<elemType>::seqSearch(const elemType& item) const
{
    int loc;
    bool found = false;

    for (loc = 0; loc < length; loc++)
        if (list[loc] == item)
        {
            found = true;
            break;
        }

    if (found)
        return loc;
    else
        return -1;
} //end seqSearch
template <class elemType>
void arrayListType<elemType>::insert(const elemType& insertItem)
{
    int loc;

    if (length == 0)   //list is empty
        list[length++] = insertItem;    //insert the item and
                                //increment the length
    else if (length == maxSize)
        cerr << "Cannot insert in a full list." << endl;
    else
    {
        loc = seqSearch(insertItem);

        if (loc == -1)    //the item to be inserted
                          //does not exist in the list
            list[length++] = insertItem;
        else
            cerr << "the item to be inserted is already in the list. No duplicates are allowed." << endl;
    }
} //end insert
template<class elemType>
void arrayListType<elemType>::remove(const elemType& removeItem)
{
    int loc;

    if (length == 0)
        cerr << "Cannot delete from an empty list." << endl;
    else
    {
        loc = seqSearch(removeItem);
        if (loc != -1)
            removeAt(loc);
        else
            cout << "The item to be deleted is not in the list." << endl;
    }
} //end remove
template <class elemType>
arrayListType<elemType>::arrayListType(int size)
{
    if (size < 0)
    {
        cerr << "The array size must be positive. Creating an array of size 100. " << endl;

        maxSize = 100;
    }
    else
        maxSize = size;

    length = 0;

    list = new elemType[maxSize];
    assert(list != NULL);
}
template <class elemType>
arrayListType<elemType>::~arrayListType()
{
    delete [] list;
}
template <class elemType>
arrayListType<elemType>::arrayListType(const arrayListType<elemType>& otherList)
{
    maxSize = otherList.maxSize;
    length = otherList.length;
    list = new elemType[maxSize]; //create the array
    assert(list != NULL);         //terminate if unable to allocate
                                  //memory space

    for (int j = 0; j < length; j++) //copy otherList
        list [j] = otherList.list[j];
} //end copy constructor
template <class elemType>
const arrayListType<elemType>& arrayListType<elemType>::operator=(const arrayListType<elemType>& otherList)
{
    if (this != &otherList)   //avoid self-assignment
    {
        delete [] list;
        maxSize = otherList.maxSize;
        length = otherList.length;

        list = new elemType[maxSize]; //create the array
        assert(list != NULL);   //if unable to allocate memory
                                //space, terminate the program
        for (int i = 0; i < length; i++)
            list[i] = otherList.list[i];
    }
    return *this;
}
#endif

dateType.cpp

#include "dateType.h"

int dateType::dom[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

dateType::dateType()
{
   setDate(1, 1, 1900);
}
dateType::dateType(int new_month, int new_day, int new_year)
{
   setDate(new_month, new_day, new_year);
}

dateType.h

#pragma once
class dateType
{
public:
   //constructors
   dateType();
   dateType(int new_month, int new_day, int new_year);

   //accessors
   void getDate(int& new_month, int& new_day, int& new_year) const;
   int getMonth() const;
   int getDay() const;
   int getYear() const;
  
   //mutators
   void setDate(int new_month, int new_day, int new_year);
   void setMonth(int new_month);
   void setDay(int new_day);
   void setYear(int new_year);

   //custom methods
   bool isLeapYear() const;
private:
   //data members
   int _month;
   int _day;
   int _year;
   static int dom[];
};

extPersonType.cpp

#include "extPersonType.h"

extPersonType::extPersonType()
{
}

extPersonType.h

#pragma once
#include "dateType.h"
#include "personType.h"

enum relationShipType {FAMILY, FRIEND, BUSINESS, OTHER};

class extPersonType :
   public personType
{
public:
   //constructors
   extPersonType();
   extPersonType(const string& new_firstName, const string& new_lastName, const string& new_telephoneNumber, const dateType& new_dob, relationShipType new_relationship);

   //accessors
   void getExtPerson(string& new_firstName, string& new_lastName, string& new_telephoneNumber, dateType& new_dob, relationShipType& new_relationship) const;
   string getFirstName() const;
   string getLastName() const;
   string getTelephoneNumber() const;
   dateType getDOB() const;
   relationShipType getRelationShip() const;

   //mutators
   void setExtPerson(const string& new_firstName, const string& new_lastName, const string& new_telephoneNumber, const dateType& new_dob, relationShipType new_relationship);
   void setFirstName(const string& new_firstName);
   void setLastName(const string& new_lastName) const;
   void setTelephoneNumber(const string& new_telephoneNumber);
   void setDOB(const dateType& new_dob);
   void setRelationShip(relationShipType new_relationShip) const;

   //custom method
   void print() const;

private:
   string _telephoneNumber;
   relationShipType _relationship;
   dateType dob;
};

personType.cpp


#include <iostream>
#include <string>
#include "personType.h"

using namespace std;

void personType::print() const
{
    cout << firstName << " " << lastName;
}

void personType::setName(string first, string last)
{
    firstName = first;
    lastName = last;
}

string personType::getFirstName() const
{
    return firstName;
}

string personType::getLastName() const
{
    return lastName;
}

    //Default constructor
personType::personType()
{
    firstName = "";
    lastName = "";
}

    //Constructor with parameters
personType::personType(string first, string last)
{
    firstName = first;
    lastName = last;
}

personType.h


#include <string>

using namespace std;

class personType
{
public:
    void print() const;

    void setName(string first, string last);

    string getFirstName() const;

    string getLastName() const;

    personType();

    personType(string first, string last);

private:
    string firstName; //variable to store the first name
    string lastName; //variable to store the last name
};