Need help with c++ (1) Define the class ContactNode per the following specifications: Private data members string contactName string contactPhoneNumber ContactNode* nextNodePtr Constructor with parameters for name followed by phone number Public member functions GetName() - Accessor GetPhoneNumber() - Accessor InsertAfter() GetNext() - Accessor PrintContactNode() Ex: If the name is Roxanne Hughes and the phone number is 443-555-2864, PrintContactNode() outputs: Name: Roxanne Hughes Phone number: 443-555-2864 (2) Define main() to read the name and phone number for three contacts and output each contact. Create three ContactNodes and use the nodes to build a linked list. (1st attached image) (3) Output the linked list using a loop to output contacts one at a time. (2nd attached image) Provided template: #include using namespace std; class ContactNode { public: /* Declare member functions here */ private: /* Declare data members here */ }; /* Define member functions here */ int main() { /* Type your code here. */ return 0; }
Need help with c++
(1) Define the class ContactNode per the following specifications:
- Private data members
- string contactName
- string contactPhoneNumber
- ContactNode* nextNodePtr
- Constructor with parameters for name followed by phone number
- Public member functions
- GetName() - Accessor
- GetPhoneNumber() - Accessor
- InsertAfter()
- GetNext() - Accessor
- PrintContactNode()
-
Ex: If the name is Roxanne Hughes and the phone number is 443-555-2864, PrintContactNode() outputs:
- Name: Roxanne Hughes
- Phone number: 443-555-2864
-
(2) Define main() to read the name and phone number for three contacts and output each contact. Create three ContactNodes and use the nodes to build a linked list. (1st attached image)
-
(3) Output the linked list using a loop to output contacts one at a time. (2nd attached image)
- Provided template:
-
#include <iostream>
using namespace std;class ContactNode {
public:
/* Declare member functions here */
private:
/* Declare data members here */
};/* Define member functions here */
int main() {
/* Type your code here. */
return 0;
}
Algorithm steps to solve the given problem:
- Start
- Initialize pointers headPtr, currPtr, and lastPtr to null.
- Create a loop to take input from user for contact name and phone number.
- Create a new ContactNode object and assign it to currPtr.
- Check if headPtr is null.
- If headPtr is null, assign currPtr to headPtr and lastPtr.
- If headPtr is not null, call InsertAfter() method of lastPtr and assign currPtr to lastPtr.
- Print the contact list. 8. Create a loop to print the contact list using GetNext() method of currPtr.
- Output the result.
- Stop.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 5 images