Question

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.

Person 1 Enter name: Enter phone number You entered: Roxanne Hughes Person 2 Enter name: Enter phone number You entered: Juan Alberto Jr Your output starts with Person 3 Enter name: Enter phone number You entered: Rachel Phillips 310- CONTACT LIST Contact Name: Person 1 Enter name: Enter phone number: You entered: Roxanne Hughes 443-555-2864 Person 2 Enter name: Expected output starts with Enter phone number You entered: Juan Alberto Jr., 410-555-9385

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<<"Person " <<i+1<<endl;

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

getline(cin, Name);

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

cin>>PhoneNum ;
getline(cin, PhoneNum);

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

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

}

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

List->PrintContactNode();

system("pause");

return 0;

}

Here is the full assignment details if there is any futher questions

This program needs to be completed in C++.

(1) Create three files to submit.

Contacts.h - Class declaration

Contacts.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-661
0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++:

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<<"Person " <<i+1<<endl;
cout<<"Enter name: "<<endl ;
getline(cin, Name);
cout<<"Enter phone number: "<<endl ;
getline(cin, PhoneNum);
cout<<"You entered: "<<Name<<", "<< PhoneNum<<endl<<endl ;
List->InsertAfter(new ContactNode(Name,PhoneNum));
}
cout<<endl<<endl<<"CONTACT LIST"<<endl<<endl;
List->PrintContactNode();
return 0;
}

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();
}
}

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

OUTPUT:

sh-4.2$ main Person 1 Enter name: Roxanne Hughes Enter phone number: 443-555-2864 You entered: Roxanne Hughes, 443-555-2864 P

Add a comment
Know the answer?
Add Answer to:
Hello I need some help with my CC+ project. My current project erasing the first two...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 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...

    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....

  • 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...

  • (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...

  • I need to get this two last parts of my project done by tonight. If you...

    I need to get this two last parts of my project done by tonight. If you see something wrong with the current code feel free to fix it. Thank you! Project 3 Description In this project, use project 1 and 2 as a starting point and complete the following tasks. Create a C++ project for a daycare. In this project, create a class called child which is defined as follows: private members: string First name string Last name integer Child...

  • Hello, I have some errors in my C++ code when I try to debug it. I...

    Hello, I have some errors in my C++ code when I try to debug it. I tried to follow the requirements stated below: Code: // Linked.h #ifndef INTLINKEDQUEUE #define INTLINKEDQUEUE #include <iostream> usingnamespace std; class IntLinkedQueue { private: struct Node { int data; Node *next; }; Node *front; // -> first item Node *rear; // -> last item Node *p; // traversal position Node *pp ; // previous position int size; // number of elements in the queue public: IntLinkedQueue();...

  • I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7:...

    I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7: Customer Accounts Write a program that uses a structure to store the following data about a customer account:      Customer name      Customer address      City      State      ZIP code      Telephone      Account balance      Date of last payment The program should use an array of at least 20 structures. It should let the user enter data into the array, change the contents of any element, and display all the...

  • Hello, I need help with my code. The code needs to display random number from 1...

    Hello, I need help with my code. The code needs to display random number from 1 to 50 every time the program runs but the program displays the same random numbers every time. Thanks #include #include using namespace std; void dynAlloc(int size, int *&arr); void displayArray(int *arr, int n); void insertionSort(int *arr, int n, int *temp); void linear_search(int *arr, int n, int key); void binary_search(int *arr, int n, int key); int main() {   const int n = 50; int *arr,...

  • c++, I am having trouble getting my program to compile, any help would be appreciated. #include...

    c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...

  • I need help with this assignment, can someone HELP ? This is the assignment: Online shopping...

    I need help with this assignment, can someone HELP ? This is the assignment: Online shopping cart (continued) (C++) This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class per the following specifications: Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt) Public member functions SetDescription() mutator & GetDescription() accessor (2 pts) PrintItemCost() - Outputs the item name followed by...

  • //Need help ASAP in c++ please. Appreciate it! Thank you!! //This is the current code I have. #include <iostream> #include <sstream> #include <iomanip> using namespace std; cl...

    //Need help ASAP in c++ please. Appreciate it! Thank you!! //This is the current code I have. #include <iostream> #include <sstream> #include <iomanip> using namespace std; class googlePlayApp { private: string name; double rating; int numInstalls; int numReviews; double price;    public: googlePlayApp(string, double, int, int, double); ~ googlePlayApp(); googlePlayApp();    string getName(); double getRating(); int getNumInstalls(); int getNumReviews(); string getPrice();    void setName(string); void setRating(double); void setNumInstalls(int); void setNumReviews(int); void setPrice(double); }; googlePlayApp::googlePlayApp(string n, double r, int ni, int nr, double pr)...

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
ADVERTISEMENT