Question: Need help with this C++ program file: Instructions: FifthElementTesting.cpp file: #include #include #include #include FifthElement.h using namespace std; void testGetFifthElement(); void testInsertNewFifthElement(); void testDeleteFifthElement(); void

Need help with this C++ program file:

Instructions:

Need help with this C++ program file: Instructions: FifthElementTesting.cpp file: #include #include

FifthElementTesting.cpp file:

#include #include #include #include "FifthElement.h"

using namespace std;

void testGetFifthElement(); void testInsertNewFifthElement(); void testDeleteFifthElement(); void testSwapFourthAndFifthElement();

bool checkTest(string testName, string whatItShouldBe, string whatItIs); bool checkTest(string testName, int whatItShouldBe, int whatItIs); bool checkTestMemory(string testName, int whatItShouldBe, int whatItIs);

int main() { testGetFifthElement(); testInsertNewFifthElement(); testDeleteFifthElement(); testSwapFourthAndFifthElement();

return 0; }

//This helps with testing, do not modify. bool checkTest(string testName, string whatItShouldBe, string whatItIs) {

if (whatItShouldBe == whatItIs) { cout

//This helps with testing, do not modify. bool checkTest(string testName, int whatItShouldBe, int whatItIs) {

if (whatItShouldBe == whatItIs) { cout

//This helps with testing, do not modify. bool checkTestMemory(string testName, int whatItShouldBe, int whatItIs) {

if (whatItShouldBe == whatItIs) { cout

//This helps with testing, do not modify. void testGetFifthElement() {

auto si = make_shared>(); for (int i = 10; i insert(i); }

stringstream sstream; sstream

//Test retrieving item. int item = si->getFifthElement(); checkTest("test #2: checking 5th element", 14, item); si.reset();

si = make_shared>(); for (int i = 10; i insert(i); }

sstream.str(""); sstream

//Test just to make sure the data went in the list. checkTest("test #3: adding only 5 elements", "10 11 12 13 14", sstream.str());

//Test retrieving item. item = si->getFifthElement(); checkTest("test #4: checking 5th at end", 14, item); si.reset();

si = make_shared>(); for (int i = 10; i insert(i); } sstream.str(""); sstream

//Try to access out of bounds. string caughtError = ""; try { item = si->getFifthElement(); } catch (exception &e) { caughtError = "caught"; } checkTest("test #6: testing exception ", "caught", caughtError); si.reset();

auto ss = make_shared >(); ss->insert("Multi Pass"); ss->insert("Lelu Dallas"); ss->insert("BIG BADA BOOM"); ss->insert("Bruce Willis"); ss->insert("Fried Chicken"); ss->insert("EEEAAAAAAAeeeaaaaaEEeeAAAEEaaaaAA"); checkTest("test #7: testing strings", "Fried Chicken", ss->getFifthElement()); ss.reset();

}

//This helps with testing, do not modify. void testInsertNewFifthElement() {

auto si = make_shared>(); for (int i = 10; i insert(i); } stringstream sstream; sstream.str(""); sstream

//Test inserting an item si->insertNewFifthElement(97);

sstream.str(""); sstream

checkTest("add test #2: adding 5th in middle", "10 11 12 13 97 14 15 16 17 18 19", sstream.str());

si = make_shared>(); for (int i = 10; i insert(i); }

sstream.str(""); sstream

//Test inserting an item si->insertNewFifthElement(97);

sstream.str(""); sstream

si = make_shared>(); for (int i = 10; i insert(i); } sstream.str(""); sstream

//Test just to make sure the data went in the list. checkTest("add test #5: adding only 4 values", "10 11 12 13", sstream.str());

//Test inserting an item si->insertNewFifthElement(97); sstream.str(""); sstream

checkTest("add test #6: adding to end", "10 11 12 13 97", sstream.str());

}

//This helps with testing, do not modify. void testDeleteFifthElement() { // Note from the instructor: Please do not delete the actual movie. It's very good and shouldn't be removed.

auto si = make_shared>(); for (int i = 10; i insert(i); } stringstream sstream; sstream

//Test deleting an item si->deleteFifthElement(); sstream.str(""); sstream

checkTest("delete test #2: delete 5th value", "10 11 12 13 15 16 17 18 19", sstream.str());

si = make_shared>(); for (int i = 10; i insert(i); } //Test just to make sure the data went in the list. sstream.str(""); sstream

//Test deleting an item si->deleteFifthElement(); sstream.str(""); sstream

si = make_shared>(); for (int i = 10; i insert(i); } //Test just to make sure the data went in the list. sstream.str(""); sstream

//Test deleting an item si->deleteFifthElement(); sstream.str(""); sstream

}

//This helps with testing, do not modify. void testSwapFourthAndFifthElement() { // Note from the instructor: Please do not delete the actual movie. It's very good and shouldn't be removed.

auto si = make_shared>(); for (int i = 10; i insert(i); } stringstream sstream; sstream.str(""); sstream

//Test swapping an item

si->swapFourthAndFifthElement(); sstream.str(""); sstream

}

Learning Outcomes: This assignment will help you review class relationships and linked lists. Description Create a class named FifthElement that inherits the LinkedList class. This class will help you search for the Fifth Element in the list. The Fifth Element class will contain the following four methods T getFifth Element(); This method returns the data at the fifth node (not index) of the linked list. It will throw a runtime_error. (just like in peek() if there is no fifth element in the list void insertNewFifthElement(const T&value); This method inserts a node containing value between the existing 4 and 5 nodes so that the original 5th node becomes the 6 node in the list. If there are only 4 nodes in the list, the new node will become the last node in the list. void deleteFifthElement();This method deletes the 5th node. If there was a 6th node, the 4th node now points to the 6th node. If there was no 6th node, the 4th node becomes the new back node. void swapFourthAndFifthElement();This method rearranges the 4th and 5th nodes. It cannot swap the data in the nodes, it instead must rearrange pointers. You will write your own header file. You may check to see if it passes all the test cases by using the following as your main. FifthElementTesting.cpp

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!