Question: IN C + + , 1 5 . 2 7 LAB: Mileage tracker for a runner Given the MileageTrackerNode class containing the number of miles

IN C++,15.27 LAB: Mileage tracker for a runner
Given the MileageTrackerNode class containing the number of miles a runner runs on a certain date, complete main() to perform the following tasks:
1. Read the number of nodes in the linked list from user input, followed by the number of miles and date of each node.
2. Use the MileageTrackerNode's InsertAfter() function to insert each node according to the input sequence (i.e. insert each node after the last node).
3. Print the entire linked list using the MileageTrackerNode's PrintNodeData() function. DO NOT print the head node that does not contain user-input values. Hint: PrintNodeData() only outputs values in one node; therefore, iterate through the linked list.
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
Here is the main cpp file #include "MileageTrackerNode.h"
#include "MileageTrackerNode.h"
#include
#include
using namespace std;
int main (){
// References for MileageTrackerNode objects
MileageTrackerNode* headNode;
MileageTrackerNode* currNode;
MileageTrackerNode* lastNode;
double miles;
string date;
int i;
// Front of nodes list
headNode = new MileageTrackerNode();
// End of nodes list
lastNode = headNode;
// TODO: Read in the number of nodes
// TODO: For the input number of nodes, read the number of miles and date
// from user input. Insert each node into the end of the linked list (after the last node)
// TODO: Print the entire linked list with PrintNodeData() function calls
// MileageTrackerNode Destructor deletes all following nodes
delete headNode;
return 0;
}
Here is MileageTrackerNode.h (File is marked as read only)
#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
Here is MileageTrackerNode.cpp (File is marked as read only)
#include "MileageTrackerNode.h"
#include
// Constructor
MileageTrackerNode::MileageTrackerNode(){
miles =-1;
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;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!