Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will be building a linked list. Make sure to keep track of both the head and tail nodes. (1) Create three files to submit.

You will be building a linked list. Make sure to keep track of both the head and tail nodes.

(1) Create three files to submit.

  • ContactNode.h - class ContactNode definition
  • ContactNode.cpp - class member functions
  • main.cpp - main() function

(2) Build the ContactNode class per the following specifications:

  • Data members
    • string name
    • string phone
    • ContactNode* next
  • Member functions
    • constructor ContactNode(string& name, string& phone, ContactNode* next = nullptr)
    • void InsertAfter(ContactNode* node)
      • Insert a new node after this node
    • ContactNode* GetNext()
      • Return location pointed by next
    • void PrintNode()

Ex. of PrintNode() output:

Name: Roxanne Hughes

Phone number: 443-555-2864

(3) In main(), prompt the user for three contacts and output the user's input. Create three ContactNodes and use the nodes to build a linked list. (4) Output the linked list. Ex:

Person 1

Enter name:

Roxanne Hughes

Enter phone number:

443-555-2864

You entered: Roxanne Hughes, 443-555-2864

Person 2

Enter name:

Juan Alberto Jr.

Enter phone number:

410-555-9385

You entered: Juan Alberto Jr., 410-555-9385

Person 3

Enter name:

Rachel Phillips

Enter phone number:

310-555-6610

You entered: Rachel Phillips, 310-555-6610

CONTACT LIST

Name: Roxanne Hughes

Phone number: 443-555-2864

Name: Juan Alberto Jr.

Phone number: 410-555-9385

Name: Rachel Phillips

Phone number: 310-555-6610

Ex. Input Box:

Roxanne Hughes

443-555-2864

Juan Alberto Jr.

410-555-9385

Rachel Phillips

310-555-6610

Here are the code:

Main.cpp

#include #include #include "ContactNode.h" using namespace std;

int main() { string fullName; string phoneNum; ContactNode* headContact = nullptr; // 1st person ContactNode* nextContact1 = nullptr; // 2nd person ContactNode* nextContact2 = nullptr; // 3rd person ContactNode* currContact = nullptr; // Get contact information for person 1 cout cout getline(cin, fullName); cout getline(cin, phoneNum); cout //First contact node (head of list) headContact = new ContactNode(fullName, phoneNum, nullptr); // TODO: Get contact information for person 2 // (info for person 2 goes into nextContact1) // (s0 repeat last block of code, substitute nextContact1 for headContact)

// insert nextContract1 after headContact headContact->InsertAfter(nextContact1); // TODO: Get contact information for person 3 // (info for person 3 goes into nextContact2)

// TODO: insert nextContract2 after nextContact1 cout // TODO: Print contact list // initialize currContact to headContact // traverse nodes with currContact until == NULL // use PrintNode to print out each node return 0; }

ContactNode.cpp

#include #include "ContactNode.h"

ContactNode::ContactNode(string name, string num) { contactName = name; contactPhoneNum = num; }

void ContactNode::InsertAfter(ContactNode* newNodePtr) { nextNodePtr = newNodePtr; }

string ContactNode::GetName() { return contactName; }

string ContactNode::GetPhoneNumber() { return contactPhoneNum; }

ContactNode* ContactNode::GetNext() { return nextNodePtr; }

void ContactNode::PrintContactNode() { cout }

ContactNode.h

#include

#include

using namespace std;

class ContactNode {

public:

ContactNode(string name, string num);

void InsertAfter(ContactNode* newNodePtr);

string GetName();

string GetPhoneNumber();

ContactNode* GetNext();

void PrintContactNode();

private:

string contactName;

string contactPhoneNum;

ContactNode* nextNodePtr;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Combinatorial Testing In Cloud Computing

Authors: Wei-Tek Tsai ,Guanqiu Qi

1st Edition

9811044805, 978-9811044809

More Books

Students also viewed these Programming questions