Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// main.cpp #include #include ContactNode.h int main() { ContactNode* contactList = new ContactNode(); ContactNode* currNode; std::string name, phoneNum; int i = 1; while (i >

// main.cpp

#include

#include "ContactNode.h"

int main() {

ContactNode* contactList = new ContactNode();

ContactNode* currNode;

std::string name, phoneNum;

int i = 1;

while (i <= 3) {

std::cout << "Person " << i++ << std::endl;

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

getline(std::cin, name);

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

std::cin >> phoneNum;

std::cin.ignore();

contactList->InsertAfter(new ContactNode(name, phoneNum));

std::cout << "You entered: " << name << ", " << phoneNum << std::endl << std::endl;

}

currNode = contactList;

std::cout << "CONTACT LIST" << std::endl;

while (currNode != nullptr) {

currNode->PrintContactNode();

currNode = currNode->GetNext();

}

delete contactList, currNode;

}

// ContactNode.cpp

#include

#include "ContactNode.h"

void ContactNode::InsertAfter(ContactNode* newNode) {

ContactNode *tmpNext = this->nextNodePtr;

this->nextNodePtr = newNode;

newNode->nextNodePtr = tmpNext;

}

ContactNode::~ContactNode() {

ContactNode* curr = nextNodePtr;

delete nextNodePtr;

while (curr != nullptr) {

curr = nextNodePtr;

delete nextNodePtr;

}

}

ContactNode& ContactNode::operator=(const ContactNode& objToCopy) {

if (this != &objToCopy) {

delete nextNodePtr;

nextNodePtr = new ContactNode();

*nextNodePtr = *(objToCopy.nextNodePtr);

}

return *this;

}

std::string ContactNode::GetName() const {

return contactName;

}

std::string ContactNode::GetPhoneNumber() const {

return contactPhoneNum;

}

ContactNode* ContactNode::GetNext() const {

return this->nextNodePtr;

}

void ContactNode::PrintContactNode() {

std::cout << "Name: " << this->contactName << " Phone Number: " << this->contactPhoneNum << std::endl;

}

// ContactNode.h

#ifndef CONTACTNODE_H

#define CONTACTNODE_H

#include

class ContactNode {

public:

ContactNode(std::string contactName = "", std::string contactPhoneNum = "") {

this->contactName = contactName;

this->contactPhoneNum = contactPhoneNum;

}

~ContactNode();

ContactNode& operator=(const ContactNode& objToCopy);

void InsertAfter(ContactNode*);

std::string GetName() const;

std::string GetPhoneNumber() const;

ContactNode *GetNext() const;

void PrintContactNode();

private:

std::string contactName;

std::string contactPhoneNum;

ContactNode* nextNodePtr = nullptr;

};

#endif

// Can you help me properly add and dispose the pionters. These are the error messages I get when I run the code

/*

to `ContactNode::InsertAfter(ContactNode*)'c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\ADMINI~1\AppData\Local\Temp\cciFRiVN.o:main.cpp:(.text+0x2e7): undefined reference to `ContactNode::PrintContactNode()'c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\ADMINI~1\AppData\Local\Temp\cciFRiVN.o:main.cpp:(.text+0x2f6): undefined reference to `ContactNode::GetNext() const'c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\ADMINI~1\AppData\Local\Temp\cciFRiVN.o:main.cpp:(.text+0x31b): undefined reference to `ContactNode::~ContactNode()'collect2.exe: error: ld returned 1 exit status

*/

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

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

Ty e2y Evaluate the integral dy

Answered: 1 week ago