Question
Using C++, use a linked list to create an alphabetical Contact Book to store the names, addresses, and phone numbers of our contacts. The data
Using C++, use a linked list to create an alphabetical Contact Book to store the names, addresses, and phone numbers of our contacts. The data structure used contain contacts should be a linked list and each time a new contact is added the contact will be inserted into the correct alphabetical location by last name. Assume there are no contacts that have the same last name. There will be two classes. One named LinkedList and the other named PersonNode. I have attached the LinkedList classes and the PersonNode.h. I need the PersonNode.cpp and main class to get the program running. Please follow the instructions provided.
The LinkedList class will be used to create a single LinkedList object.
- The class will have two PersonNode pointer fields
*headPtr that will maintain the head of the linked list
*tailPtr that will maintain the tail of the linked list
- The class will have the following functions::
*a constructor that initialized the headPtr and tailPtr to NULL
*addLink that will take a PersonNode reference or pointer and add the node to the linked list
*findInsertSpot that will return a PersonNode pointer that points to the location where a PersonNode is to be inserted into the linked list
*getHeadPtr that will return the headPtr
The PersonNode class will be used to create the nodes that are part of the linked list
- The class will have the following fields:
*fName - string contains the contacts first name
*lName - string contains the contact last name
*address - string contains the contacts address
*phone - string contains the contacts phone number
*next - PersonNode pointer that points to the next contact
- The class will contain all of the getters and setters for the above named fields (see class diagram below) in addition to
*getFullName - returns the string of lName, fName
*a constructor that takes no arguments and sets next to NULL
*a constructor that takes arguments to set fName, lName, address, and phone and sets next to NULL
- Finally, create the ability to search for a PersonNode entry from the Contact Book and remove a PersonNode entry from the Contact Book.
LinkedList.h
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include "PersonNode.h"
class LinkedList {
private:
PersonNode* headPtr;
PersonNode* tailPtr;
public:
LinkedList();
void addLink(PersonNode& newPerson);
PersonNode* findInsertSpot(PersonNode& newPerson);
PersonNode* getHeadPtr();
void removeLink(PersonNode& targetPerson);
PersonNode* findLink(std::string lastName);
};
#endif
LinkedList.cpp
#include "LinkedList.h"
#include
LinkedList::LinkedList() {
headPtr = nullptr;
tailPtr = nullptr;
}
void LinkedList::addLink(PersonNode& newPerson) {
PersonNode* insertSpot = findInsertSpot(newPerson);
if (insertSpot == nullptr) {
headPtr = &newPerson;
}
else {
newPerson.setNext(insertSpot->getNext());
insertSpot->setNext(&newPerson);
}
if (newPerson.getNext() == nullptr) {
tailPtr = &newPerson;
}
}
PersonNode* LinkedList::findInsertSpot(PersonNode& newPerson) {
PersonNode* currentPerson = headPtr;
PersonNode* previousPerson = nullptr;
while (currentPerson != nullptr && currentPerson->getFullName() < newPerson.getFullName()) {
previousPerson = currentPerson;
currentPerson = currentPerson->getNext();
}
return previousPerson;
}
PersonNode* LinkedList::getHeadPtr() {
return headPtr;
}
void LinkedList::removeLink(PersonNode& targetPerson) {
PersonNode* currentPerson = headPtr;
PersonNode* previousPerson = nullptr;
while (currentPerson != nullptr && currentPerson != &targetPerson) {
previousPerson = currentPerson;
currentPerson = currentPerson->getNext();
}
if (currentPerson == nullptr) {
std::cout << "Error: " << targetPerson.getFullName() << " not found." << std::endl;
}
else {
if (currentPerson == headPtr) {
headPtr = currentPerson->getNext();
}
else {
previousPerson->setNext(currentPerson->getNext());
}
if (currentPerson == tailPtr) {
tailPtr = previousPerson;
}
}
}
PersonNode* LinkedList::findLink(std::string lastName) {
PersonNode* currentPerson = headPtr;
while (currentPerson != nullptr) {
if (currentPerson->getLastName() == lastName) {
return currentPerson;
}
currentPerson = currentPerson->getNext();
}
std::cout << "Error: " << lastName << " not found." << std::endl;
return nullptr;
}
PersonNode.h
#ifndef PERSONNODE_H
#define PERSONNODE_H
#include
class PersonNode {
private:
std::string fName;
std::string lName;
std::string address;
std::string phone;
PersonNode* next;
public:
PersonNode();
PersonNode(std::string fName, std::string lName, std::string address, std::string phone);
std::string getFullName();
std::string getFirstName();
std::string getLastName();
std::string getAddress();
std::string getPhone();
PersonNode* getNext();
void setFirstName(std::string newFName);
void setLastName(std::string newLName);
void setAddress(std::string newAddress
); void setPhone(std::string newPhone); void setNext(PersonNode* newNext);
};
#endif
Aspen Ski Resorts has 150 employees, each working 40 hours per week and earning $15 an hour. Although the company does not pay any health or retirement benefits, one of the perks of working at Aspen is that employees are allowed free skiing on their days off. Federal income taxes are withheld at 15% and state income taxes at 5%. FICA taxes are 7.65% of the first $142,800 earned per employee and 1.45% thereafter. Unemployment taxes are 6.2% of the first $7,000 earned per employee. Required: 1. Compute the total salary expense, the total withholdings from employee salaries, and the actual direct deposit of payroll for the first week of January. 2. Compute the total payroll tax expense Aspen Ski Resorts will pay for the first week of January in addition to the total salary expense and employee withholdings calculated in Part 1. 3. How should Aspen Ski Resorts account for the free skiing given to employees on their days off? Complete this question by entering your answers in the tabs below. Required 1 Required 2 Required 3 Compute the total salary expense, the total withholdings from employee salaries, and the actual direct deposit of payroll for the first week of January. Total salary expense Total withholdings Actual direct deposit
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