SlideShare a Scribd company logo
In C++ please, do not alter node.h
Step 1: Inspect the Node.h file
Inspect the class declaration for a doubly-linked list node in Node.h. The Node class has three
member variables:
a double data value,
a pointer to the next node, and
a pointer to the previous node.
Each member variable is protected. So code outside of the class must use the provided getter and
setter member functions to get or set a member variable.
Node.h is read only, since no changes are required.
Step 2: Implement the Insert() member function
A class for a sorted, doubly-linked list is declared in SortedNumberList.h. Implement the
SortedNumberList class's Insert() member function. The function must create a new node with
the parameter value, then insert the node into the proper sorted position in the linked list. Ex:
Suppose a SortedNumberList's current list is 23 47.25 86, then Insert(33.5) is called. A new
node with data value 33.5 is created and inserted between 23 and 47.25, thus preserving the list's
sorted order and yielding: 23 35.5 47.25 86
Step 3: Test in develop mode
Code in main() takes a space-separated list of numbers and inserts each into a SortedNumberList.
The list is displayed after each insertion. Ex: If input is
77 15 -42 63.5
then output is:
List after inserting 77:
77 List after inserting 15:
15 77
List after inserting -42:
-42 15 77
List after inserting 63.5:
-42 15 63.5 77
Try various program inputs, ensuring that each outputs a sorted list.
Step 4: Implement the Remove() member function
Implement the SortedNumberList class's Remove() member function. The function takes a
parameter for the number to be removed from the list. If the number does not exist in the list, the
list is not changed and false is returned. Otherwise, the first instance of the number is removed
from the list and true is returned.
Uncomment the commented-out part in main() that reads a second input line and removes
numbers from the list. Test in develop mode to ensure that insertion and removal both work
properly, then submit code for grading. Ex: If input is
84 72 19 61 19 84
then output is:
List after inserting 84:
84
List after inserting 72:
72 84
List after inserting 19:
19 72 84
List after inserting 61:
19 61 72 84
List after removing 19:
61 72 84
List after removing 84:
61 72
Code below:
main.cpp
#include
#include
#include
#include "Node.h"
#include "SortedNumberList.h"
using namespace std;
void PrintList(SortedNumberList& list);
vector SpaceSplit(string source);
int main(int argc, char *argv[]) {
// Read the line of input numbers
string inputLine;
getline(cin, inputLine);
// Split on space character
vector terms = SpaceSplit(inputLine);
// Insert each value and show the sorted list's contents after each insertion
SortedNumberList list;
for (auto term : terms) {
double number = stod(term);
cout << "List after inserting " << number << ": " << endl;
list.Insert(number);
PrintList(list);
}
/*
// Read the input line with numbers to remove
getline(cin, inputLine);
terms = SpaceSplit(inputLine);
// Remove each value
for (auto term : terms) {
double number = stod(term);
cout << "List after removing " << number << ": " << endl;
list.Remove(number);
PrintList(list);
}
*/
return 0;
}
// Prints the SortedNumberList's contents, in order from head to tail
void PrintList(SortedNumberList& list) {
Node* node = list.head;
while (node) {
cout << node->GetData() << " ";
node = node->GetNext();
}
cout << endl;
}
// Splits a string at each space character, adding each substring to the vector
vector SpaceSplit(string source) {
vector result;
size_t start = 0;
for (size_t i = 0; i < source.length(); i++) {
if (' ' == source[i]) {
result.push_back(source.substr(start, i - start));
start = i + 1;
}
}
result.push_back(source.substr(start));
return result;
}
Node.h (no change)
#ifndef NODE_H
#define NODE_H
class Node {
protected:
double data;
Node* next;
Node* previous;
public:
// Constructs this node with the specified numerical data value. The next
// and previous pointers are each assigned nullptr.
Node(double initialData) {
data = initialData;
next = nullptr;
previous = nullptr;
}
// Constructs this node with the specified numerical data value, next
// pointer, and previous pointer.
Node(double initialData, Node* nextNode, Node* previousNode) {
data = initialData;
next = nextNode;
previous = previousNode;
}
virtual ~Node() {
}
// Returns this node's data.
virtual double GetData() {
return data;
}
// Sets this node's data.
virtual void SetData(double newData) {
data = newData;
}
// Gets this node's next pointer.
virtual Node* GetNext() {
return next;
}
// Sets this node's next pointer.
virtual void SetNext(Node* newNext) {
next = newNext;
}
// Gets this node's previous pointer.
virtual Node* GetPrevious() {
return previous;
}
// Sets this node's previous pointer.
virtual void SetPrevious(Node* newPrevious) {
previous = newPrevious;
}
};
#endif
SortedNumberList.h
#ifndef SORTEDNUMBERLIST_H
#define SORTEDNUMBERLIST_H
#include "Node.h"
class SortedNumberList {
private:
// Optional: Add any desired private functions here
public:
Node* head;
Node* tail;
SortedNumberList() {
head = nullptr;
tail = nullptr;
}
// Inserts the number into the list in the correct position such that the
// list remains sorted in ascending order.
void Insert(double number) {
// Your code here
}
// Removes the node with the specified number value from the list. Returns
// true if the node is found and removed, false otherwise.
bool Remove(double number) {
// Your code here (remove placeholder line below)
return false;
}
};
#endif

More Related Content

Similar to In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf

This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
EricvtJFraserr
 
C Exam Help
C Exam Help C Exam Help
C Exam Help
Programming Exam Help
 
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfAssignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
formicreation
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
Himadri Sen Gupta
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
fortmdu
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
Programming Homework Help
 
In the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdfIn the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdf
arjunstores123
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
Tareq Hasan
 
C++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdfC++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdf
aashisha5
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
BAINIDA
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
Mohammed Khan
 
Ch17
Ch17Ch17
Ch17
Abbott
 
#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx
ajoy21
 
C++ Background Circular Linked List A circular linked list.pdf
C++ Background Circular Linked List A circular linked list.pdfC++ Background Circular Linked List A circular linked list.pdf
C++ Background Circular Linked List A circular linked list.pdf
saradashata
 
C++ code, please help! Troubleshooting and cannot for the life of me.pdf
C++ code, please help! Troubleshooting and cannot for the life of me.pdfC++ code, please help! Troubleshooting and cannot for the life of me.pdf
C++ code, please help! Troubleshooting and cannot for the life of me.pdf
rahulfancycorner21
 
Chapter 5 ds
Chapter 5 dsChapter 5 ds
Chapter 5 ds
Hanif Durad
 
Background Circular Linked List A circular linked list is .pdf
Background Circular Linked List A circular linked list is .pdfBackground Circular Linked List A circular linked list is .pdf
Background Circular Linked List A circular linked list is .pdf
aaseletronics2013
 
Write a C++ function that delete nodes in a doubly linkedlist- It shou.docx
Write a C++ function that delete nodes in a doubly linkedlist- It shou.docxWrite a C++ function that delete nodes in a doubly linkedlist- It shou.docx
Write a C++ function that delete nodes in a doubly linkedlist- It shou.docx
noreendchesterton753
 

Similar to In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf (20)

This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
C Exam Help
C Exam Help C Exam Help
C Exam Help
 
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfAssignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
 
In the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdfIn the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdf
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
 
Arrays
ArraysArrays
Arrays
 
C++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdfC++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdf
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
Ch17
Ch17Ch17
Ch17
 
#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx
 
C++ Background Circular Linked List A circular linked list.pdf
C++ Background Circular Linked List A circular linked list.pdfC++ Background Circular Linked List A circular linked list.pdf
C++ Background Circular Linked List A circular linked list.pdf
 
C++ code, please help! Troubleshooting and cannot for the life of me.pdf
C++ code, please help! Troubleshooting and cannot for the life of me.pdfC++ code, please help! Troubleshooting and cannot for the life of me.pdf
C++ code, please help! Troubleshooting and cannot for the life of me.pdf
 
Chapter 5 ds
Chapter 5 dsChapter 5 ds
Chapter 5 ds
 
Background Circular Linked List A circular linked list is .pdf
Background Circular Linked List A circular linked list is .pdfBackground Circular Linked List A circular linked list is .pdf
Background Circular Linked List A circular linked list is .pdf
 
Write a C++ function that delete nodes in a doubly linkedlist- It shou.docx
Write a C++ function that delete nodes in a doubly linkedlist- It shou.docxWrite a C++ function that delete nodes in a doubly linkedlist- It shou.docx
Write a C++ function that delete nodes in a doubly linkedlist- It shou.docx
 
Java execise
Java execiseJava execise
Java execise
 

More from stopgolook

Jordano Food Products Supply Chain Profile Jordano Foods Tracie Shan.pdf
Jordano Food Products Supply Chain Profile Jordano Foods Tracie Shan.pdfJordano Food Products Supply Chain Profile Jordano Foods Tracie Shan.pdf
Jordano Food Products Supply Chain Profile Jordano Foods Tracie Shan.pdf
stopgolook
 
Java Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdfJava Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdf
stopgolook
 
Javai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdfJavai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdf
stopgolook
 
J.M. Baker worked as a traditional land use researcher and consultan.pdf
J.M. Baker worked as a traditional land use researcher and consultan.pdfJ.M. Baker worked as a traditional land use researcher and consultan.pdf
J.M. Baker worked as a traditional land use researcher and consultan.pdf
stopgolook
 
IT Project Management homework Identify any project of your choice.pdf
IT Project Management homework Identify any project of your choice.pdfIT Project Management homework Identify any project of your choice.pdf
IT Project Management homework Identify any project of your choice.pdf
stopgolook
 
INSTRUCTIONSDevelop, and present a plan and business case for an a.pdf
INSTRUCTIONSDevelop, and present a plan and business case for an a.pdfINSTRUCTIONSDevelop, and present a plan and business case for an a.pdf
INSTRUCTIONSDevelop, and present a plan and business case for an a.pdf
stopgolook
 
In the realm of professional dynamics, understanding and appreciating .pdf
In the realm of professional dynamics, understanding and appreciating .pdfIn the realm of professional dynamics, understanding and appreciating .pdf
In the realm of professional dynamics, understanding and appreciating .pdf
stopgolook
 
import React, { useEffect } from react;import { BrowserRouter as.pdf
import React, { useEffect } from react;import { BrowserRouter as.pdfimport React, { useEffect } from react;import { BrowserRouter as.pdf
import React, { useEffect } from react;import { BrowserRouter as.pdf
stopgolook
 
Im trying to define a class in java but I seem to be having a bit o.pdf
Im trying to define a class in java but I seem to be having a bit o.pdfIm trying to define a class in java but I seem to be having a bit o.pdf
Im trying to define a class in java but I seem to be having a bit o.pdf
stopgolook
 
in c languageTo determine the maximum string length, we need to .pdf
in c languageTo determine the maximum string length, we need to .pdfin c languageTo determine the maximum string length, we need to .pdf
in c languageTo determine the maximum string length, we need to .pdf
stopgolook
 
In 2011, the head of the Presidential Protection Force (for purposes.pdf
In 2011, the head of the Presidential Protection Force (for purposes.pdfIn 2011, the head of the Presidential Protection Force (for purposes.pdf
In 2011, the head of the Presidential Protection Force (for purposes.pdf
stopgolook
 
import java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdfimport java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdf
stopgolook
 
If a taxpayer has investment income that exceeds a certain threshold.pdf
If a taxpayer has investment income that exceeds a certain threshold.pdfIf a taxpayer has investment income that exceeds a certain threshold.pdf
If a taxpayer has investment income that exceeds a certain threshold.pdf
stopgolook
 
Im having an issue with the simulateOPT() methodthis is the p.pdf
Im having an issue with the simulateOPT() methodthis is the p.pdfIm having an issue with the simulateOPT() methodthis is the p.pdf
Im having an issue with the simulateOPT() methodthis is the p.pdf
stopgolook
 
I. Naive Robot Navigation ProblemDesign a program that uses the B.pdf
I. Naive Robot Navigation ProblemDesign a program that uses the B.pdfI. Naive Robot Navigation ProblemDesign a program that uses the B.pdf
I. Naive Robot Navigation ProblemDesign a program that uses the B.pdf
stopgolook
 

More from stopgolook (15)

Jordano Food Products Supply Chain Profile Jordano Foods Tracie Shan.pdf
Jordano Food Products Supply Chain Profile Jordano Foods Tracie Shan.pdfJordano Food Products Supply Chain Profile Jordano Foods Tracie Shan.pdf
Jordano Food Products Supply Chain Profile Jordano Foods Tracie Shan.pdf
 
Java Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdfJava Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdf
 
Javai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdfJavai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdf
 
J.M. Baker worked as a traditional land use researcher and consultan.pdf
J.M. Baker worked as a traditional land use researcher and consultan.pdfJ.M. Baker worked as a traditional land use researcher and consultan.pdf
J.M. Baker worked as a traditional land use researcher and consultan.pdf
 
IT Project Management homework Identify any project of your choice.pdf
IT Project Management homework Identify any project of your choice.pdfIT Project Management homework Identify any project of your choice.pdf
IT Project Management homework Identify any project of your choice.pdf
 
INSTRUCTIONSDevelop, and present a plan and business case for an a.pdf
INSTRUCTIONSDevelop, and present a plan and business case for an a.pdfINSTRUCTIONSDevelop, and present a plan and business case for an a.pdf
INSTRUCTIONSDevelop, and present a plan and business case for an a.pdf
 
In the realm of professional dynamics, understanding and appreciating .pdf
In the realm of professional dynamics, understanding and appreciating .pdfIn the realm of professional dynamics, understanding and appreciating .pdf
In the realm of professional dynamics, understanding and appreciating .pdf
 
import React, { useEffect } from react;import { BrowserRouter as.pdf
import React, { useEffect } from react;import { BrowserRouter as.pdfimport React, { useEffect } from react;import { BrowserRouter as.pdf
import React, { useEffect } from react;import { BrowserRouter as.pdf
 
Im trying to define a class in java but I seem to be having a bit o.pdf
Im trying to define a class in java but I seem to be having a bit o.pdfIm trying to define a class in java but I seem to be having a bit o.pdf
Im trying to define a class in java but I seem to be having a bit o.pdf
 
in c languageTo determine the maximum string length, we need to .pdf
in c languageTo determine the maximum string length, we need to .pdfin c languageTo determine the maximum string length, we need to .pdf
in c languageTo determine the maximum string length, we need to .pdf
 
In 2011, the head of the Presidential Protection Force (for purposes.pdf
In 2011, the head of the Presidential Protection Force (for purposes.pdfIn 2011, the head of the Presidential Protection Force (for purposes.pdf
In 2011, the head of the Presidential Protection Force (for purposes.pdf
 
import java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdfimport java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdf
 
If a taxpayer has investment income that exceeds a certain threshold.pdf
If a taxpayer has investment income that exceeds a certain threshold.pdfIf a taxpayer has investment income that exceeds a certain threshold.pdf
If a taxpayer has investment income that exceeds a certain threshold.pdf
 
Im having an issue with the simulateOPT() methodthis is the p.pdf
Im having an issue with the simulateOPT() methodthis is the p.pdfIm having an issue with the simulateOPT() methodthis is the p.pdf
Im having an issue with the simulateOPT() methodthis is the p.pdf
 
I. Naive Robot Navigation ProblemDesign a program that uses the B.pdf
I. Naive Robot Navigation ProblemDesign a program that uses the B.pdfI. Naive Robot Navigation ProblemDesign a program that uses the B.pdf
I. Naive Robot Navigation ProblemDesign a program that uses the B.pdf
 

Recently uploaded

Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 

Recently uploaded (20)

Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 

In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf

  • 1. In C++ please, do not alter node.h Step 1: Inspect the Node.h file Inspect the class declaration for a doubly-linked list node in Node.h. The Node class has three member variables: a double data value, a pointer to the next node, and a pointer to the previous node. Each member variable is protected. So code outside of the class must use the provided getter and setter member functions to get or set a member variable. Node.h is read only, since no changes are required. Step 2: Implement the Insert() member function A class for a sorted, doubly-linked list is declared in SortedNumberList.h. Implement the SortedNumberList class's Insert() member function. The function must create a new node with the parameter value, then insert the node into the proper sorted position in the linked list. Ex: Suppose a SortedNumberList's current list is 23 47.25 86, then Insert(33.5) is called. A new node with data value 33.5 is created and inserted between 23 and 47.25, thus preserving the list's sorted order and yielding: 23 35.5 47.25 86 Step 3: Test in develop mode Code in main() takes a space-separated list of numbers and inserts each into a SortedNumberList. The list is displayed after each insertion. Ex: If input is 77 15 -42 63.5 then output is: List after inserting 77: 77 List after inserting 15: 15 77 List after inserting -42: -42 15 77 List after inserting 63.5: -42 15 63.5 77 Try various program inputs, ensuring that each outputs a sorted list. Step 4: Implement the Remove() member function Implement the SortedNumberList class's Remove() member function. The function takes a parameter for the number to be removed from the list. If the number does not exist in the list, the list is not changed and false is returned. Otherwise, the first instance of the number is removed from the list and true is returned.
  • 2. Uncomment the commented-out part in main() that reads a second input line and removes numbers from the list. Test in develop mode to ensure that insertion and removal both work properly, then submit code for grading. Ex: If input is 84 72 19 61 19 84 then output is: List after inserting 84: 84 List after inserting 72: 72 84 List after inserting 19: 19 72 84 List after inserting 61: 19 61 72 84 List after removing 19: 61 72 84 List after removing 84: 61 72 Code below: main.cpp #include #include #include #include "Node.h" #include "SortedNumberList.h" using namespace std; void PrintList(SortedNumberList& list); vector SpaceSplit(string source); int main(int argc, char *argv[]) { // Read the line of input numbers string inputLine; getline(cin, inputLine); // Split on space character vector terms = SpaceSplit(inputLine); // Insert each value and show the sorted list's contents after each insertion SortedNumberList list;
  • 3. for (auto term : terms) { double number = stod(term); cout << "List after inserting " << number << ": " << endl; list.Insert(number); PrintList(list); } /* // Read the input line with numbers to remove getline(cin, inputLine); terms = SpaceSplit(inputLine); // Remove each value for (auto term : terms) { double number = stod(term); cout << "List after removing " << number << ": " << endl; list.Remove(number); PrintList(list); } */ return 0; } // Prints the SortedNumberList's contents, in order from head to tail void PrintList(SortedNumberList& list) { Node* node = list.head; while (node) { cout << node->GetData() << " "; node = node->GetNext(); } cout << endl; } // Splits a string at each space character, adding each substring to the vector vector SpaceSplit(string source) { vector result; size_t start = 0; for (size_t i = 0; i < source.length(); i++) { if (' ' == source[i]) { result.push_back(source.substr(start, i - start));
  • 4. start = i + 1; } } result.push_back(source.substr(start)); return result; } Node.h (no change) #ifndef NODE_H #define NODE_H class Node { protected: double data; Node* next; Node* previous; public: // Constructs this node with the specified numerical data value. The next // and previous pointers are each assigned nullptr. Node(double initialData) { data = initialData; next = nullptr; previous = nullptr; } // Constructs this node with the specified numerical data value, next // pointer, and previous pointer. Node(double initialData, Node* nextNode, Node* previousNode) { data = initialData; next = nextNode; previous = previousNode; } virtual ~Node() { } // Returns this node's data. virtual double GetData() { return data; }
  • 5. // Sets this node's data. virtual void SetData(double newData) { data = newData; } // Gets this node's next pointer. virtual Node* GetNext() { return next; } // Sets this node's next pointer. virtual void SetNext(Node* newNext) { next = newNext; } // Gets this node's previous pointer. virtual Node* GetPrevious() { return previous; } // Sets this node's previous pointer. virtual void SetPrevious(Node* newPrevious) { previous = newPrevious; } }; #endif SortedNumberList.h #ifndef SORTEDNUMBERLIST_H #define SORTEDNUMBERLIST_H #include "Node.h" class SortedNumberList { private: // Optional: Add any desired private functions here public: Node* head; Node* tail; SortedNumberList() { head = nullptr; tail = nullptr;
  • 6. } // Inserts the number into the list in the correct position such that the // list remains sorted in ascending order. void Insert(double number) { // Your code here } // Removes the node with the specified number value from the list. Returns // true if the node is found and removed, false otherwise. bool Remove(double number) { // Your code here (remove placeholder line below) return false; } }; #endif