Two strings, code1 and code2, are read from input as two states' codes. headObj has the default value of "code". Create a new node firstState with string code1 and insert firstState after headObj. Then, create a second node secondState with string code2 and insert secondState after firstState. Ex: If the input is MA IA, then the output is: code MA IA #include using namespace std; class StateNode { public: StateNode(string codeInit = "", StateNode* nextLoc = nullptr); void InsertAfter(StateNode* nodeLoc); StateNode* GetNext(); void PrintNodeData(); private: string codeVal; StateNode* nextNodePtr; }; StateNode::StateNode(string codeInit, StateNode* nextLoc) { this->codeVal = codeInit; this->nextNodePtr = nextLoc; } void StateNode::InsertAfter(StateNode* nodeLoc) { StateNode* tmpNext = nullptr; tmpNext = this->nextNodePtr; this->nextNodePtr = nodeLoc; nodeLoc->nextNodePtr = tmpNext; } StateNode* StateNode::GetNext() { return this->nextNodePtr; } void StateNode::PrintNodeData() { cout << this->codeVal << endl; } int main() { StateNode* headObj = nullptr; StateNode* firstState = nullptr; StateNode* secondState = nullptr; StateNode* currState = nullptr; string code1; string code2; cin >> code1; cin >> code2; headObj = new StateNode("code"); /* THE NEEDED CODE GOES HERE. THE REST OF THE CODE IS FINE. */ currState = headObj; while (currState != nullptr) { currState->PrintNodeData(); currState = currState->GetNext(); } return 0;

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question

C++ CODING PROBLEM WHERE I NEED CODE TO CREATE A LINKED LIST

(I also put a screen shot of the problem below. 

Two strings, code1 and code2, are read from input as two states' codes.

headObj has the default value of "code".

Create a new node firstState with string code1 and insert firstState after headObj.

Then, create a second node secondState with string code2 and insert secondState after firstState.

Ex: If the input is MA IA, then the output is:

code

MA

IA

#include <iostream>
using namespace std;

class StateNode {
   public:
      StateNode(string codeInit = "", StateNode* nextLoc = nullptr);
      void InsertAfter(StateNode* nodeLoc);
      StateNode* GetNext();
      void PrintNodeData();
   private:
      string codeVal;
      StateNode* nextNodePtr;
};

StateNode::StateNode(string codeInit, StateNode* nextLoc) {
   this->codeVal = codeInit;
   this->nextNodePtr = nextLoc;
}

void StateNode::InsertAfter(StateNode* nodeLoc) {
   StateNode* tmpNext = nullptr;

   tmpNext = this->nextNodePtr;
   this->nextNodePtr = nodeLoc;
   nodeLoc->nextNodePtr = tmpNext;
}

StateNode* StateNode::GetNext() {
   return this->nextNodePtr;
}

void StateNode::PrintNodeData() {
   cout << this->codeVal << endl;
}

int main() {
   StateNode* headObj = nullptr;
   StateNode* firstState = nullptr;
   StateNode* secondState = nullptr;
   StateNode* currState = nullptr;
   string code1;
   string code2;

   cin >> code1;
   cin >> code2;

   headObj = new StateNode("code");
   
   /* THE NEEDED CODE GOES HERE. THE REST OF THE CODE IS FINE.  */

   currState = headObj;
   while (currState != nullptr) {
      currState->PrintNodeData();
      currState = currState->GetNext();
   }

   return 0;

 

CHALLENGE 9.1.3: A first linked list.
ACTIVITY
434056.2330114.qx3zqy7
Start
Two strings, code1 and code2, are read from input as two states' codes. headObj has the default value of "code". Create a new
node firstState with string code1 and insert firstState after headObj. Then, create a second node secondState with string code
and insert secondState after firstState.
Ex: If the input is MA IA, then the output is:
code
MA
IA
L23456THEN
1 #include <iostream>
2 using namespace std;
4 class
StateNode {
public:
2118
StateNode (string codeInit = StateNode* nextLoc= nullptr);
void InsertAfter (StateNode* nodeLoc);
StateNode GetNext();
void PrintNodeData();
10
11
12
13
14
15
16
17
};
private:
string codeVal;
StateNode nextNodePtr;
StateNode::StateNode (string code Init, StateNode* nextLoc) {
this->codeVal = codeInit;
this->nextNodePtr = nextLoc;
Transcribed Image Text:CHALLENGE 9.1.3: A first linked list. ACTIVITY 434056.2330114.qx3zqy7 Start Two strings, code1 and code2, are read from input as two states' codes. headObj has the default value of "code". Create a new node firstState with string code1 and insert firstState after headObj. Then, create a second node secondState with string code and insert secondState after firstState. Ex: If the input is MA IA, then the output is: code MA IA L23456THEN 1 #include <iostream> 2 using namespace std; 4 class StateNode { public: 2118 StateNode (string codeInit = StateNode* nextLoc= nullptr); void InsertAfter (StateNode* nodeLoc); StateNode GetNext(); void PrintNodeData(); 10 11 12 13 14 15 16 17 }; private: string codeVal; StateNode nextNodePtr; StateNode::StateNode (string code Init, StateNode* nextLoc) { this->codeVal = codeInit; this->nextNodePtr = nextLoc;
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Types of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education