Question

In: Computer Science

8.13 LAB: Warm up: Contacts You will be building a linked list. Make sure to keep...

8.13 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 - Class declaration
  • ContactNode.cpp - Class definition
  • main.cpp - main() function

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

  • Parameterized constructor. Parameters are name followed by phone number.

  • Public member functions

    • InsertAfter() (2 pts)
    • GetName() - Accessor (1 pt)
    • GetPhoneNumber - Accessor (1 pt)
    • GetNext() - Accessor (1 pt)
    • PrintContactNode()
  • Private data members

    • string contactName
    • string contactPhoneNum
    • ContactNode* nextNodePtr


Ex. of PrintContactNode() 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. (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


(4) Output the linked list. (2 pts)

Ex:

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

main.cpp:

#include <iostream>
using namespace std;

int main() {

/* Type your code here. */

return 0;
}
__________________

ContactNode.cpp

/* Type code here */

_________________

ContactNode.h

/* Type code here */

Solutions

Expert Solution

CONTACT NODE .H FILE

#ifndef CONTACTNODE_H
#define CONTACTNODE_H
#include<iostream>
#include<string>
using namespace std;
class ContactNode
{
    string ContactName;
    string ContactPhoneNum;
    ContactNode*nextNodeptr;
public:
    ContactNode(string,string);
    
    ContactNode*InsertAfter(ContactNode*,string,string,ContactNode*);
    
    string GetName(ContactNode*);
    
    string GetPhone(ContactNode*);
    
    void printContactNode(ContactNode*);
};
#endif // CONTACTNODE_H

CONTACTNODE .CPP FILE

#include "ContactNode.h"
#include<iostream>
#include<string>
using namespace std;
ContactNode::ContactNode(string name,string phone)  ///Parametrized Constructor
{
    this->ContactName=name;
    this->ContactPhoneNum=phone;
    this->nextNodeptr=NULL;
}
ContactNode* ContactNode::InsertAfter(ContactNode*head,string name,string phone,ContactNode*tail)   ///Inserting Node
{
    if(head==NULL)
    {
       ContactNode*node=new ContactNode(name,phone);
       head=node;
       tail=head;
    }
    else{
        ContactNode*ptr=head;
        ContactNode*node=new ContactNode(name,phone);
        while(ptr->nextNodeptr!=NULL)
            ptr=ptr->nextNodeptr;
        ptr->nextNodeptr=node;
        tail=ptr->nextNodeptr;
    }
    return head;
}
string ContactNode::GetName(ContactNode*node)       ///Function returning name of node
{
    return node->ContactName;
}
string ContactNode::GetPhone(ContactNode*node)         ///Function returning phone of node
{
    return node->ContactPhoneNum;
}
void ContactNode::printContactNode(ContactNode*head)    ///Function Printing Complete Node
{
    ContactNode*ptr=head;
    while(ptr!=NULL)
    {
        cout<<"Name: "<<GetName(ptr)<<endl;
        cout<<"Phone Number: "<<GetPhone(ptr)<<endl<<endl;
        ptr=ptr->nextNodeptr;
    }
}
///////////////****************MAIN FUNCTION!!!*****************
int main()
{
    ContactNode obj("","");
    ContactNode *head=NULL,*tail=NULL;
    for(int i=0;i<3;i++)
    {
        string name,phone;
        cout<<"Person "<<i+1<<endl;
        cout<<"Enter Name: ";
        getline(cin,name);
        cout<<"Enter Phone number: ";
        getline(cin,phone);
        cout<<"You entered : "<<name<<", "<<phone<<endl<<endl;
        head=obj.InsertAfter(head,name,phone,tail);
    }
    cout<<"\nCONTACT LIST\n";
    obj.printContactNode(head);
}

Above is code snippet in C++ performing all the task mentioned in question.

Two different files are used. Please keep in mind they must be in same folder and should be saved with same name as mentioned in question.

OUTPUT'S SCREENSHOT


Related Solutions

C++ Only Please 10.15 LAB: Warm up: Contacts You will be building a linked list. Make...
C++ Only Please 10.15 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 - Class declaration ContactNode.cpp - Class definition main.cpp - main() function (2) Build the ContactNode class per the following specifications: Parameterized constructor. Parameters are name followed by phone number. Public member functions InsertAfter() (2 pts) GetName() - Accessor (1 pt) GetPhoneNumber - Accessor (1 pt) GetNext()...
You will be building a linked list. Make sure to keep track of both the head...
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. PlaylistNode.h - Class declaration PlaylistNode.cpp - Class definition main.cpp - main() function Build the PlaylistNode class per the following specifications. Note: Some functions can initially be function stubs (empty functions), to be completed in later steps. Default constructor (1 pt) Parameterized constructor (1 pt) Public member functions InsertAfter() - Mutator (1 pt) SetNext() - Mutator...
Use C++ please You will be building a linked list. Make sure to keep track of...
Use C++ please 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. PlaylistNode.h - Class declaration PlaylistNode.cpp - Class definition main.cpp - main() function Build the PlaylistNode class per the following specifications. Note: Some functions can initially be function stubs (empty functions), to be completed in later steps. Default constructor (1 pt) Parameterized constructor (1 pt) Public member functions InsertAfter() - Mutator (1 pt)...
The aim of this lab session is to make you familiar with implementing a linked list....
The aim of this lab session is to make you familiar with implementing a linked list. In this lab you will complete the partially implemented LinkedIntegerList. Specifically, you will implement the following methods. • public boolean remove(int value) • public int removeAt(int index) • public boolean set(int index, int value) • public int indexOf(int value) Task-1 Add a new class named Lab3Tester class to test the current implementation of the linked list. (Note: you may reuse the code from SimpleIntegerListTester...
Create a generic Linked List that does NOT use the Java library linked list. Make sure...
Create a generic Linked List that does NOT use the Java library linked list. Make sure it contains or access a subclass named Node (also Generic). And has the methods: addFirst(), addLast(), add(), removeFirst(), removeLast() and getHead(). In a separate Java class provide a main that creates an instance of your LinkedList class that creates an instance of your LinkedList that contains String types. Add the five names (you pick them) to the list and then iterate through the list...
Can you make this singular linked list to doubly linked list Create a Doubly Linked List....
Can you make this singular linked list to doubly linked list Create a Doubly Linked List. Use this to create a Sorted Linked List, Use this to create a prioritized list by use. Bring to front those links recently queried. -----link.h------ #ifndef LINK_H #define LINK_H struct Link{ int data; Link *lnkNxt; }; #endif /* LINK_H */ ----main.cpp---- //System Level Libraries #include <iostream> //I/O Library using namespace std; //Libraries compiled under std #include"Link.h" //Global Constants - Science/Math Related //Conversions, Higher Dimensions...
C++ Data Structures: Implement a Stack and a Queue using Linked list In this lab you...
C++ Data Structures: Implement a Stack and a Queue using Linked list In this lab you will implement the functionality of a stack and a queue using a linked list. Your program must use of the declaration of the Stack and Queue class in Stack.h and Queue.h You have to implement the functionalities of queue (enq, deq, displayQueue) in a file called Queue.cpp. All the functions in Queue.cpp should follow the prototypes declared in Queue.h. Your code should make use...
Insert at least three rows of data to each table. Make sure you keep the primary...
Insert at least three rows of data to each table. Make sure you keep the primary key and foreign key constraints. Tables: Cust Table: cid, -- customer id cname, --- customer name cphone, --- customer phone cemail, --- customer email Category table: ctid, --- category id ctname, --- category name parent, --- parent category id since category has a hierarchy structure, power washers, electric power washers, gas power washers. You can assume that there are only two levels. Tool: tid,...
5.23 LAB: Warm up: Text analyzer & modifier (1) Prompt the user to enter a string...
5.23 LAB: Warm up: Text analyzer & modifier (1) Prompt the user to enter a string of their choosing. Output the string. (1 pt) Ex: Enter a sentence or phrase: The only thing we have to fear is fear itself. You entered: The only thing we have to fear is fear itself. (2) Complete the getNumOfCharacters() method, which returns the number of characters in the user's string. We encourage you to use a for loop in this function. (2 pts)...
c++   In this lab you will create a program to make a list of conference sessions...
c++   In this lab you will create a program to make a list of conference sessions you want to attend. (List can be of anything...) You can hard code 10 Sessions in the beginning of your main program. For example, I have session UK1("Descaling agile",    "Gojko Adzic",       60);        session UK2("Theory of constraints", "Pawel Kaminski", 90); and then:        List l;        l.add(&UK1);        l.add(&UK2); Your Session struct should have the following member data: The Title The Speaker The session...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT