Given the MileageTrackerNode class, complete main() to insert nodes into a linked list (using the InsertAfter() function). The first user-input value is the number of nodes in the linked list. Use the PrintNodeData() function to print the entire linked list. DO NOT print the dummy head node. Ex. If the input is: 3 2.2 7/2/18 3.2 7/7/18 4.5 7/16/18 the output is: 2.2, 7/2/18 3.2, 7/7/18 4.5, 7/16/18 #include "MileageTrackerNode.h" #include #include using namespace std; int main (int argc, char* argv[]) { // References for MileageTrackerNode objects MileageTrackerNode* headNode; MileageTrackerNode* currNode; MileageTrackerNode* lastNode; double miles; string date; int i; // Front of nodes list headNode = new MileageTrackerNode(); lastNode = headNode; // TODO: Read in the number of nodes // TODO: For the read in number of nodes, read // in data and insert into the linked list // TODO: Call the PrintNodeData() method // to print the entire linked list // MileageTrackerNode Destructor deletes all // following nodes delete headNode; } #ifndef MILEAGETRACKERNODEH #define MILEAGETRACKERNODEH #include using namespace std; class MileageTrackerNode { public: // Constructor MileageTrackerNode(); // Destructor ~MileageTrackerNode(); // Constructor MileageTrackerNode(double milesInit, string dateInit); // Constructor MileageTrackerNode(double milesInit, string dateInit, MileageTrackerNode* nextLoc); /* Insert node after this node. Before: this -- next After: this -- node -- next */ void InsertAfter(MileageTrackerNode* nodeLoc); // Get location pointed by nextNodeRef MileageTrackerNode* GetNext(); void PrintNodeData(); private: double miles; // Node data string date; // Node data MileageTrackerNode* nextNodeRef; // Reference to the next node }; #endif   #include "MileageTrackerNode.h" #include // Constructor MileageTrackerNode::MileageTrackerNode() { miles = 0.0; date = ""; nextNodeRef = nullptr; } // Destructor MileageTrackerNode::~MileageTrackerNode() { if(nextNodeRef != nullptr) { delete nextNodeRef; } } // Constructor MileageTrackerNode::MileageTrackerNode(double milesInit, string dateInit) { miles = milesInit; date = dateInit; nextNodeRef = nullptr; } // Constructor MileageTrackerNode::MileageTrackerNode(double milesInit, string dateInit, MileageTrackerNode* nextLoc) { miles = milesInit; date = dateInit; nextNodeRef = nextLoc; } /* Insert node after this node. Before: this -- next After: this -- node -- next */ void MileageTrackerNode::InsertAfter(MileageTrackerNode* nodeLoc) { MileageTrackerNode* tmpNext; tmpNext = nextNodeRef; nextNodeRef = nodeLoc; nodeLoc->nextNodeRef = tmpNext; } // Get location pointed by nextNodeRef MileageTrackerNode* MileageTrackerNode::GetNext() { return nextNodeRef; } void MileageTrackerNode::PrintNodeData(){ cout << miles << ", " << date << endl

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Given the MileageTrackerNode class, complete main() to insert nodes into a linked list (using the InsertAfter() function). The first user-input value is the number of nodes in the linked list. Use the PrintNodeData() function to print the entire linked list. DO NOT print the dummy head node.

Ex. If the input is:

3 2.2 7/2/18 3.2 7/7/18 4.5 7/16/18

the output is:

2.2, 7/2/18 3.2, 7/7/18 4.5, 7/16/18

#include "MileageTrackerNode.h"
#include <string>
#include <iostream>
using namespace std;

int main (int argc, char* argv[]) {
// References for MileageTrackerNode objects
MileageTrackerNode* headNode;
MileageTrackerNode* currNode;
MileageTrackerNode* lastNode;

double miles;
string date;
int i;

// Front of nodes list
headNode = new MileageTrackerNode();
lastNode = headNode;

// TODO: Read in the number of nodes

// TODO: For the read in number of nodes, read
// in data and insert into the linked list

// TODO: Call the PrintNodeData() method
// to print the entire linked list

// MileageTrackerNode Destructor deletes all
// following nodes
delete headNode;
}

#ifndef MILEAGETRACKERNODEH
#define MILEAGETRACKERNODEH

#include <string>
using namespace std;

class MileageTrackerNode {
public:
// Constructor
MileageTrackerNode();

// Destructor
~MileageTrackerNode();

// Constructor
MileageTrackerNode(double milesInit, string dateInit);

// Constructor
MileageTrackerNode(double milesInit, string dateInit, MileageTrackerNode* nextLoc);

/* Insert node after this node.
Before: this -- next
After: this -- node -- next
*/
void InsertAfter(MileageTrackerNode* nodeLoc);

// Get location pointed by nextNodeRef
MileageTrackerNode* GetNext();

void PrintNodeData();

private:
double miles; // Node data
string date; // Node data
MileageTrackerNode* nextNodeRef; // Reference to the next node
};

#endif

 

#include "MileageTrackerNode.h"
#include <iostream>

// Constructor
MileageTrackerNode::MileageTrackerNode() {
miles = 0.0;
date = "";
nextNodeRef = nullptr;
}

// Destructor
MileageTrackerNode::~MileageTrackerNode() {
if(nextNodeRef != nullptr) {
delete nextNodeRef;
}
}

// Constructor
MileageTrackerNode::MileageTrackerNode(double milesInit, string dateInit) {
miles = milesInit;
date = dateInit;
nextNodeRef = nullptr;
}

// Constructor
MileageTrackerNode::MileageTrackerNode(double milesInit, string dateInit, MileageTrackerNode* nextLoc) {
miles = milesInit;
date = dateInit;
nextNodeRef = nextLoc;
}

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

tmpNext = nextNodeRef;
nextNodeRef = nodeLoc;
nodeLoc->nextNodeRef = tmpNext;
}

// Get location pointed by nextNodeRef
MileageTrackerNode* MileageTrackerNode::GetNext() {
return nextNodeRef;
}

void MileageTrackerNode::PrintNodeData(){
cout << miles << ", " << date << endl;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question
main.cpp: In function ‘int main()’: main.cpp:32:25: error: expected type-specifier before ‘MilageTrackerNode’ 32 | lastNode = new MilageTrackerNode(miles, date); | ^~~~~~~~~~~~~~~~~ main.cpp:37:23: error: expected type-specifier before ‘MilageTrackerNode’ 37 | currNode=new MilageTrackerNode(miles, date); | ^~~~~~~~~~~~~~~~~
I am getting this erro for these two lines of codes and I am not sure why
Solution
Bartleby Expert
SEE SOLUTION
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY