Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ assignment language and us a cout because I don\'t want my teacher to konw I

ID: 3828419 • Letter: C

Question

C++ assignment language and us a cout because I don't want my teacher to konw I used internet and we just use cout and cin but not print

and please very improtant Put the files names which one is Node.h and which is Node.cpp and which is main.cpp

https://www.chegg.com/homework-help/questions-and-answers/c-help-code-please-interested-going-offer-extra-credit-assignment-assignment-involve-creat-q21189147

this is example by the teacher:

#include
using namespace std;

class IntNode {
public:
   IntNode(int dataInit = 0, IntNode* nextLoc = 0);
   void InsertAfter(IntNode* nodePtr);
   IntNode* GetNext();
   void PrintNodeData();
private:
   int dataVal;
   IntNode* nextNodePtr;
};

// Constructor
IntNode::IntNode(int dataInit, IntNode* nextLoc) {
   this->dataVal = dataInit;
   this->nextNodePtr = nextLoc;
   return;
}

/* Insert node after this node.
* Before: this -- next
* After: this -- node -- next
*/
void IntNode::InsertAfter(IntNode* nodeLoc) {
   IntNode* tmpNext = 0;
  
   tmpNext = this->nextNodePtr;    // Remember next
   this->nextNodePtr = nodeLoc;    // this -- node -- ?
   nodeLoc->nextNodePtr = tmpNext; // this -- node -- next
   return;
}

// Print dataVal
void IntNode::PrintNodeData() {
   cout << this->dataVal << endl;
   return;
}

// Grab location pointed by nextNodePtr
IntNode* IntNode::GetNext() {
   return this->nextNodePtr;
}

int main() {
   IntNode* headObj = 0; // Create intNode objects
   IntNode* nodeObj1 = 0;
   IntNode* nodeObj2 = 0;
   IntNode* nodeObj3 = 0;
   IntNode* currObj = 0;
  
   // Front of nodes list
   headObj = new IntNode(-1);
  
   // Insert nodes
   nodeObj1 = new IntNode(555);
   headObj->InsertAfter(nodeObj1);
  
   nodeObj2 = new IntNode(999);
   nodeObj1->InsertAfter(nodeObj2);
  
   nodeObj3 = new IntNode(777);
   nodeObj1->InsertAfter(nodeObj3);
  
   // Print linked list
   currObj = headObj;
   while (currObj != 0) {
      currObj->PrintNodeData();
      currObj = currObj->GetNext();
   }
  
   return 0;
}

Explanation / Answer

Header file IntNode.h


#ifndef IntNode
#define IntNode

class IntNode {
public:
   IntNode(int dataInit = 0, IntNode* nextLoc = 0);
   void InsertAfter(IntNode* nodePtr);
   IntNode* GetNext();
   void displayNode();
private:
   int dataVal;
   IntNode* nextNodePtr;
};


#endif

----------------------------------------------------------------------------------------

//IntNode.cpp

#include<iostream>
#include"IntNode.h"
IntNode::IntNode(int dataInit, IntNode* nextLoc) {
   this->dataVal = dataInit;
   this->nextNodePtr = nextLoc;
   return;
}

/* Insert node after this node.
* Before: this -- next
* After: this -- node -- next
*/
void IntNode::InsertAfter(IntNode* nodeLoc) {
   IntNode* tmpNext = 0;

   tmpNext = this->nextNodePtr;    // Remember next
   this->nextNodePtr = nodeLoc;    // this -- node -- ?
   nodeLoc->nextNodePtr = tmpNext; // this -- node -- next
   return;
}

// Print dataVal
void IntNode::displayNode() {
   cout << this->dataVal << " ";
   return;
}

// Grab location pointed by nextNodePtr
IntNode* IntNode::GetNext() {
   return this->nextNodePtr;
}

--------------------------------------------------------

//main.cpp

#include<iostream>
#include"IntNode.h"
int main() {
   IntNode* headObj = 0; // Create intNode objects
   IntNode* nodeObj1 = 0;
   IntNode* nodeObj2 = 0;
   IntNode* nodeObj3 = 0;
   IntNode* currObj = 0;

   // Front of nodes list
   headObj = new IntNode(-1);

   // Insert nodes
   nodeObj1 = new IntNode(555);
   headObj->InsertAfter(nodeObj1);

   nodeObj2 = new IntNode(999);
   nodeObj1->InsertAfter(nodeObj2);

   nodeObj3 = new IntNode(777);
   nodeObj1->InsertAfter(nodeObj3);

   // Print linked list
   currObj = headObj;
   while (currObj != 0) {
      currObj->displayNode();
      currObj = currObj->GetNext();
   }

   return 0;
}

----------------------------------------------

Run Below Code in a Single File.. Without header one.

-----------------------------------
#include <iostream>

class IntNode {
public:
   IntNode(int dataInit = 0, IntNode* nextLoc = 0);
   void InsertAfter(IntNode* nodePtr);
   IntNode* GetNext();
   void displayNode();
private:
   int dataVal;
   IntNode* nextNodePtr;
};

IntNode::IntNode(int dataInit, IntNode* nextLoc) {
   this->dataVal = dataInit;
   this->nextNodePtr = nextLoc;
   return;
}

/* Insert node after this node.
* Before: this -- next
* After: this -- node -- next
*/
void IntNode::InsertAfter(IntNode* nodeLoc) {
   IntNode* tmpNext = 0;

   tmpNext = this->nextNodePtr;    // Remember next
   this->nextNodePtr = nodeLoc;    // this -- node -- ?
   nodeLoc->nextNodePtr = tmpNext; // this -- node -- next
   return;
}

// Print dataVal
void IntNode::displayNode() {
   cout << this->dataVal << " ";
   return;
}

// Grab location pointed by nextNodePtr
IntNode* IntNode::GetNext() {
   return this->nextNodePtr;
}

//main.cpp

//#include<iostream>
//#include"IntNode.h"

int main() {
   IntNode* headObj = 0; // Create intNode objects
   IntNode* nodeObj1 = 0;
   IntNode* nodeObj2 = 0;
   IntNode* nodeObj3 = 0;
   IntNode* currObj = 0;

   // Front of nodes list
   headObj = new IntNode(-1);

   // Insert nodes
   nodeObj1 = new IntNode(555);
   headObj->InsertAfter(nodeObj1);

   nodeObj2 = new IntNode(999);
   nodeObj1->InsertAfter(nodeObj2);

   nodeObj3 = new IntNode(777);
   nodeObj1->InsertAfter(nodeObj3);

   // Print linked list
   currObj = headObj;
   while (currObj != 0) {
      currObj->displayNode();
      currObj = currObj->GetNext();
   }

   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote