8.16 LAB: Mileage tracker for a runner C++   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   Main.cpp   #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; }   MileageTrackerNode.h   #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   MileageTracker.cpp   #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; }

Question

8.16 LAB: Mileage tracker for a runner C++

 

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
 
Main.cpp
 

#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;
}

 

MileageTrackerNode.h

 

#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

 

MileageTracker.cpp

 

#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 Answer

Want to see the step-by-step answer?

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.
Tagged in
Engineering
Computer Science

Programing Language

Related Computer Science Q&A

Find answers to questions asked by students like you.

Q: . Draw the graph of the NRZ-L, NRZ-I, Manchester scheme, differential Manchester scheme using eachof...

A: Actually, the answer has given below:

Q: Need help with Html canvas/ Javascript

A: Create a canvas in HTML using canvas tag with height and width as 300 each. Set id of the canvas as ...

Q: Write a C++ code that does the following 1) Create a link list 2)Write a function that reverses the ...

A: Objective: This program would create a linked list (single) and reverse its elements making groups o...

Q: 4.1 Using a loop structure, write function myPow(double x, int y) which calculates x. Write a python...

A: def myPow(x,y):        value=1;        if(y&gt;0):                                #if exponent is po...

Q: 1. Which of the following statements about the 51-percent attack is INCORRECT: A. 51-percent attack ...

A: statements that are incorrect are: 51-percent attack can suppress some transactions (e.g., by refusi...

Q: Which of the following is the correct syntax for mapping drive letter W to a shared folder named Acc...

A: net use W: \\Accounting\Finance: this will assign W to finance from accounting. net share W: \\Finan...

Q: Which of the following is the correct syntax for mapping drive letter W to a shared folder named Acc...

A: "There are multiple questions asked so the three parts will be answered. Please, upload another ques...

Q: Provide examples of relations that could have more than one candidate key.

A: Candidate key A candidate key is recognized as a "set of attributes" (or fields) with the ability t...

Q: Print "warm" if s is not equal to w, otherwise print "cold". Use the variables given below:s = 'summ...

A: s = 'summer'w = 'winter' if s == w:    print("cold")else:    print("warm")

Q: a) create a dictionary, rank = {1:"Freshman", 2:"Sophmore", 3:"Junior", 4:"Senior" }b) request a use...

A: rank = {1:"Freshman", 2:"Sophmore", 3:"Junior", 4:"Senior" } while True: numberOfYears = int(input(...

Q: Prove that the language L={(M, N):  M is a Turing machine and N is a DFA with L(M) =L(N)}  is undeci...

A: Turing Machine : A Turing machine is a numerical model of calculation that characterizes a theoretic...

Q: Question 2: Write a C Program A bank wants a program that determines the yearly interest earned on a...

A: #include&lt;stdio.h&gt; int main(){    //declare the variables to store amount, interest, term    fl...

Q: Name four disk-arm scheduling algorithms. Outline the basic algorithm foreach

A: Disk preparation: It is performed by operating systems to coordinate the arrival of I O requests fo...

Q: Write a postcondition, event-controlled loop (i.e., a while loop), using a flag variable, that print...

A: PROGRAM STRUCTURE: Initialize the flag variable. Declare the loop variable to print the series. Sta...

Q: Create a table with activities and realistic estimated durations and develop a PERT chartusing AOA m...

A: Critical Path Analysis and PERT are powerful tools that assist to schedule and manage complex projec...

Q: A. Complete the method named outsideIn3(). The method has one input: a String str that is at least 3...

A: Code: public String outsideIn3(String str) {  int i = str.length() / 2;    String newString="";    n...

Q: Python - Text Processing Write a function copy(x, y) that can copy a file x into another file y. Use...

A: PROGRAM: #Defining the copy(x,y) def copy(x, y):     #Try block to throw file exception   try:      ...

Q: Using Michael Porter’s framework for competitive advantages, identify and justify the strategy used ...

A: Strategy for achieving competitive advantage A firm can possess two types of competitive advantage....

Q: Write a C++ program that will ask user to enter an integer value and your program will determine whe...

A: Introduction of Program This C++ program taking number input from the user then the program checks t...

Q: Determine if the following expression will evaluate to true or false in C++ (14 &gt;= 5) &amp;&amp; ...

A: Note: Below the required program in C++. Program Approach: Defining necessary header files. Declari...

Q: Generate a RAC parity matrix for a (20, 12) coding of the data word 111001010001. Use the grid shown...

A: In coding theory, a parity-check matrix of a linear block code C is a matrix that describes the line...

Q: Discuss various jump instructions of 8051 microcontroller with the helpof diagram

A: 8051 Microcontroller is designed by Intel, it is a 8bit microcontroller.It is built with 40 pin DIP(...

Q: Update 0-1 or binary knapsack program to minimize no. of columns approximately equal or in order of ...

A: Knapsack problem : The knapsack issue is an issue in combinatorial improvement: Given a lot of thing...

Q: NOTE: For this practical you may not use the standard array notation to access elements within the a...

A: Note: for all program i have used C programming language //Part 1: To print largest,smallest and ran...

Q: When you don’t know the specific value to include in the criteria, you use a ____.   a.  lim...

A: Explanation: Parameter query is a type of query, one can update the information easily. It prompts ...

Q: Given the following specification, design a class diagram using PlantUML. To design the class diagra...

A: Answer-     To describe the operation of a class and its attributes class diagram are used.. Mainly ...

Q: how to create an interface in java that contains the following methods: boolean myPush(T element);  ...

A: An interface in the Java programming language is a theoretical kind that is utilized to indicate a c...

Q: Construct an automaton for i) Reverse of L

A: Click to see the answer

Q: [CelsiusTemperature Table] The formula for converting a temperature from Fahrenheit to Celsius is C ...

A: Function prototype A function prototype is also known as  "function declaration" that tells the argu...

Q: 2. Write a program that calculates the average of upto 100 English distances input by the user. Crea...

A: void Distance::div_dist(Distance d2, int divisor)      {      float fltfeet = d2.feet + d2.inches/12...

Q: All of the following can provide source data except_____.  a. Software to process the source data b....

A: Explanation: A scanning device at the grocery store is the source data for the departmental store. ...

Q: Using Java script solve the following problem. //problem to solve: how many students passed and //ho...

A: &lt;script&gt; var myArray = [1,2,1,1,2,1,1,2,2,2]; for (index = 0; index &lt; myArray.length; index...

Q: Run the following Java code and explain what it does.  Give the resulting image from the code   publ...

A: There are 3 classes here: Main class: which is calling the MyFrame class. MyFrame class is creating ...

Q: Write a java program called ImperialMetric that displays a conversion table for feet and inches to m...

A: PROGRAM: //Head file import java.util.*;   //Defining the class public class ImperialMetric{      //...

Q: Write unit test methods for the methods in the following code snippet. The methods that need to have...

A: JUnit is a unit testing structure for Java programming language. JUnit has been significant in the a...

Q: Using the concept of networking in java create a chatting application that allows two instances of y...

A: Actually, the code has given below:

Q: What is the output of the following code? * System.out.println( 7.0 / (int) 2.0); D3.5 DArithmeticEx...

A: The output of the expression "7.0/(int)2.0" is printed on the console using "System.out.println()" s...

Q: Design a class bookType that defines a book as a class. a. Each object of the class bookType will ho...

A: #include &lt;iostream&gt;#include &lt;cstring&gt;using namespace std; class bookType{private :    st...

Q: Hi, I need to answer this question using the C++ programming language. Thank you. Note: I have inclu...

A: Program description: The objective of the main.cpp file is to print users to enter length and width ...

Q: USING PYTHON File Encryption and Decryption USING PYTHON Write a program that uses a dictionary to a...

A: In this program we read content of file and replace with corresponding codes from dictionary. Progra...

Q: Java eclipse

A:  As per our need, we want a 3 number lock. So we have used a random module in java to create 3 rando...

Q: Show that if and only if DFS(Depth-first Search) finds no back edges, the graph being traversed is a...

A: DFS Algorithm DFS full form Depth First Search, it is an algorithm for visiting the vertices of a gr...

Q: Please help me with this problem using c++. Also how could you create the program without having to ...

A: Actually, the code has given below:

Q: Find a duplicate (20 points). Write a program FindDuplicate.java that reads n integer arguments from...

A: public class Tester{   public static void main(String[] args) {    int flag=0;    for(int i=0;i&lt;a...