Question

20.6 Lab: Contacts You will be building a linked list. Make sure to keep track of both the head and tail nodes (1) Create thrEx. of PrintContactNode0 output: Name: Roxanne Hughes Phone number: 443-555-2864 (3) In main0, prompt the user for three cont

20.6 Lab: Contacts 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 declaration ContactNode.cpp- Class definition main.cpp-main0 function (2) Build the ContactNode class per the following specifications Parameterized constructor. Parameters are name followed by phone number Public member functions InsertAfter0 (2 pts) GetName0 -Accessor(1 pt) GetPhoneNumber- Accessor (1 pt) GetNext0-Accessor (1 pt) PrintContactNode Private data members string contactName string contactPhoneNum ContactNode* nextNodePtr
Ex. of PrintContactNode0 output: Name: Roxanne Hughes Phone number: 443-555-2864 (3) In main0, prompt the user for three contacts and output the user's input. Create three ContactNodes and use the nodes to build a linked list. (2 pts) 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
0 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

--------------------------------------------------------------------------------------------------------------
Contacts.h

#ifndef Contact_H

#define Contact_H

#include<string>

using namespace std;

class ContactNode{

public:

ContactNode();

ContactNode(string name, string phone);

void InsertAfter(ContactNode*);

string GetName();

string GetPhoneNumber();

ContactNode* GetNext();

void PrintContactNode();

private:

string contactName;

string contactPhoneNum;

ContactNode* nextNodePtr;

};

#endif

--------------------------------------------------------------------------------------------------------------------------------------------​​​​​​​

Contacts.cpp

#include <iostream>

#include "Contacts.h"

using namespace std;


ContactNode::ContactNode(){

nextNodePtr=NULL;

}


ContactNode::ContactNode(string name, string phoneNum){

contactName=name;

contactPhoneNum=phoneNum;

nextNodePtr=NULL;

}

void ContactNode::InsertAfter(ContactNode *nextNode){

ContactNode *temp;

if(nextNodePtr==NULL)

nextNodePtr=nextNode;

else{

temp=nextNodePtr;

while(temp->nextNodePtr!=NULL){

temp=temp->GetNext();

}

temp->nextNodePtr=nextNode;

}

}

string ContactNode::GetName(){

return contactName;

}

string ContactNode::GetPhoneNumber(){

return contactPhoneNum;

}

ContactNode* ContactNode::GetNext(){

return nextNodePtr;

}

void ContactNode::PrintContactNode(){

ContactNode *temp;

if(nextNodePtr!=NULL) {

cout<<"Contact Name: "<<nextNodePtr->GetName()<<endl;

cout<<"Phone number: "<<nextNodePtr->GetPhoneNumber()<<endl<<endl;


GetNext()->PrintContactNode();

}

}











--------------------------------------------------------------------------------------------​​​​​​​
main.cpp

#include <iostream>

#include "Contacts.h"

using namespace std;

int main()

{

ContactNode *List,*head;

string Name;

string PhoneNum;

List=new ContactNode;

for(int i=0;i<3;i++){

cout<<"\nPerson " <<i+1<<endl;

cout<<"Enter name: "<<endl ;

// cin>>Name;

getline(cin, Name);

cout<<"Enter phone number: "<<endl ;

// cin>>PhoneNum ;

getline(cin, PhoneNum);

cout<<"You entered: "<<Name<<", "<< PhoneNum<<endl ;

List->InsertAfter(new ContactNode(Name,PhoneNum));

}

cout<<endl<<endl<<"CONTACT LIST"<<endl<<endl;

List->PrintContactNode();

system("pause");

return 0;

}





--------------------------------------------------------------------------------------------
SEE OUTPUT
main.cpp 日 っsaved https://SwelteringGeneralTitles.rahulkumar29.repl.run イ Files 1 #include«iostream» Enter phone number 443-5

Thanks, PLEASE UPVOTE

Add a comment
Know the answer?
Add Answer to:
20.6 Lab: Contacts 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 declaration ContactNode.cpp- Class...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • (In C) 8.12 LAB: Warm up: Contacts You will be building a linked list. Make sure...

    (In C) 8.12 LAB: Warm up: Contacts 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 - Struct definition, including the data members and related function declarations ContactNode.c - Related function definitions main.c - main() function (2) Build the ContactNode struct per the following specifications: Data members char contactName[50] char contactPhoneNum[50] struct ContactNode* nextNodePtr Related functions CreateContactNode() (2 pt) InsertContactAfter() (2 pts) Insert...

  • Hello I need some help with my CC+ project. My current project erasing the first two...

    Hello I need some help with my CC+ project. My current project erasing the first two phone numbers and only printing the 3rd phone number out in the list. Any idea on how to correct. Here is the error. Contacts.h #ifndef Contact_H #define Contact_H #include<string> using namespace std; class ContactNode{ public: ContactNode(); ContactNode(string name, string phone); void InsertAfter(ContactNode*); string GetName(); string GetPhoneNumber(); ContactNode* GetNext(); void PrintContactNode(); private: string contactName; string contactPhoneNum; ContactNode* nextNodePtr; }; #endif Contacts.cpp #include <iostream> #include "Contacts.h"...

  • Declare and define TtuStudentNode in TtuStudentNode.h and TtuStudentNode.cpp file. TtuStudentNode has its unique string variable "studentEmail" which contains email address. TtuStudentNode ha...

    Declare and define TtuStudentNode in TtuStudentNode.h and TtuStudentNode.cpp file. TtuStudentNode has its unique string variable "studentEmail" which contains email address. TtuStudentNode has its unique function member GetEmail() which returns the string variable "studentEmail". TtuStudentNode has its overriding "PrintContactNode()" which has the following definition. void TtuStudentNode::PrintContactNode() { cout << "Name: " << this->contactName << endl; cout << "Phone number: " << this->contactPhoneNum << endl; cout << "Email : " << this->studentEmail << endl; return; } ContactNode.h needs to have the function...

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

    Ch 8 Program: Playlist (Java)You will be building a linked list. Make sure to keep track of both the head and tail nodes.(1) Create two files to submit.SongEntry.java - Class declarationPlaylist.java - Contains main() methodBuild the SongEntry class per the following specifications. Note: Some methods can initially be method stubs (empty methods), to be completed in later steps.Private fieldsString uniqueID - Initialized to "none" in default constructorstring songName - Initialized to "none" in default constructorstring artistName - Initialized to "none"...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT