Question: I need the Functions.cpp file to be completed. Use these files: AnyList.h AnyList.cpp Functions.cpp To test each function use these files one at a time:

I need the Functions.cpp file to be completed.

Use these files:

  • AnyList.h
  • AnyList.cpp
  • Functions.cpp

To test each function use these files one at a time:

  • TestingCommonEnds.cpp
  • TestingPreFour.cpp

Implement the functions listed below as members of the AnyList class by writing the declaration in the AnyList.h file and the definition in the Functions.cpp file.

I need the Functions.cpp file to be completed. Use these files: AnyList.h

AnyList.cpp

#include "AnyList.h"

using namespace std;

void AnyList::insertFront(int newData) { ptrToFirst = new Node(newData, ptrToFirst); ++count; }

void AnyList::print() const { if (ptrToFirst == nullptr) // Check if the list is empty. // You can also use: if (count

while (current != nullptr) // While the current pointer is NOT a nullptr, // that is, while the current pointer has not reached // the end of the list. { // Output the data. cout getData() getPtrToNext(); } } }

// This function does not delete the // list object; it ONLY deletes the nodes. void AnyList::clearList() { Node* temp = ptrToFirst; // Pointer to delete the node, which // starts by pointing to the first node.

while (ptrToFirst != nullptr) { ptrToFirst = ptrToFirst->getPtrToNext(); delete temp; temp = ptrToFirst; }

// Update the count outside the loop. count = 0; }

AnyList::~AnyList() { clearList(); }

//

AnyList.h

#ifndef ANYLIST_H #define ANYLIST_H

#include #include

class Node { public: Node() : data(0), ptrToNext(nullptr) {} Node(int theData, Node* newPtrToNext) : data(theData), ptrToNext(newPtrToNext) {} Node* getPtrToNext() const { return ptrToNext; } int getData() const { return data; } void setData(int theData) { data = theData; } void setPtrToNext(Node* newPtrToNext) { ptrToNext = newPtrToNext; } ~Node() {} private: int data; Node* ptrToNext; // Pointer that points to next node. };

class AnyList { public: AnyList() : ptrToFirst(nullptr), count(0) {}

void insertFront(int);

void print() const;

void clearList(); ~AnyList();

/*********************************************************/

// Declaration function getMin

// Declaration function haveThree

// Declaration function preFour

//Declaration function commonEnds

private: // Pointer to point to the first node in the list. Node* ptrToFirst; // Variable to keep track of number of nodes in the list. int count; };

#endif

//

Functions.cpp

/* (name header) */

#include "AnyList.h"

using namespace std; // Definition function preFour

//Definition function commonEnds

//

TestingCommonEnds.cpp

#include "AnyList.h"

#include #include #include #include

int main() { std::cout

std::vector> vCalling = { { 1 }, { 2 }, { 6, 3 }, { 7, 5 }, { 8, 4, 2, 9, 5, 6, 7, 1 }, { 1, 2, 3 }, { 1, 2, 3, 4, 5 }, { 1, 2, 3, 4, 5, 6, 7 , 8, 9 }, { 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85 }, { 67, 45, 23, 79, 15, 62, 94, 57, 71, 29, 45, 32 }

};

std::vector> vParameter = { { 3 }, { 2 }, { 6, 4 }, { 8, 5 }, { 8, 4, 2, 9 }, { 7, 3, 3 }, { 4, 9, 2, 5 }, { 1, 23, 45, 78, 75, 25, 13, 67, 43, 25, 9 }, { 10, 25, 50, 45, 96, 60, 90, 36, 74, 93, 60, 87, 34, 14, 56, 85 }, { 67, 12, 36, 79, 97, 26, 49, 75, 71, 92, 54, 76, 34, 45, 32 } };

auto sizeV1 = vCalling.size(); auto sizeV2 = vParameter.size();

for (int i = 0; i

auto sizeInnerV1 = vCalling[i].size(); auto sizeInnerV2 = vParameter[i].size();

// Casting needed to avoid 4-8 byte overflow bug in VS. int limit1 = static_cast(sizeInnerV1 - 1); int limit2 = static_cast(sizeInnerV2 - 1); for (int j = limit1; j >= 0; --j) callingList.insertFront(vCalling[i].at(j)); for (int j = limit2; j >= 0; --j) paramList.insertFront(vParameter[i].at(j));

// Print out std::cout

std::cout

std::cout

TestingPreFour.cpp

#include "AnyList.h"

#include #include #include #include

int main() { std::cout

std::vector> vParameter = { { 1, 2, 4, 1 }, { 1, 4, 4 }, { 1, 4, 4, 2 }, { 1, 3, 4, 2, 4 }, { 4, 4 }, { 3, 3, 4 }, { 1, 2, 1, 4 }, { 3, 4, 3, 4, 3, 4, 4 }, { 2, 1, 4, 2 }, { 2, 1, 2, 1, 4, 2 }, { 3, 8, 2, 5, 7, 9, 1, 4, 6}, };

std::vector> vCalling = { { 2, 1 }, { 1 }, { 1 }, { 3, 1 }, { }, { 3, 3 }, { 1, 2, 1 }, { 3 }, { 1, 2 }, { 1, 2, 1, 2 }, { 1, 9, 7, 5, 2, 8, 3 }, };

int sizeV1 = static_cast(vParameter.size());

for (int i = 0; i (vParameter[i].size()); for (int j = sizeInnerV1 - 1; j >= 0; --j) paramList.insertFront(vParameter[i].at(j));

// Print out std::cout

// Call function preFour AnyList callingList; callingList.preFour(paramList);

// Print out std::cout

std::cout

std::cout Function prefour . Parameter: An object of the class AnyList. . Given a non-empty singly-linked list, the function copies all elements from the parameter list that come before the first 4 into the calling object in reverse order. Example: Parameter object: 1, 2, 7, 5, 4, 1 => Calling object becomes: 5, 7, 2, 1 Parameter object: 3, 1,4 Calling object becomes: 1,3 Parameter object: 1, 4, 4 => Calling object becomes: 1 Assumptions: The calling object is empty. The parameter list contains at least one 4. Function commonEnds Parameter: An object of the class AnyList. The function returns true if the calling object and the parameter object have the same first element AND the same last element. Example: Calling object: 1, 2, 3 => Parameter object: 1, 4, 3 => true Calling object: 5, 6, 1, 4 => Parameter object: 5, 3, 1, 7, 4, 3, 4 => true Calling object: 3, 4, 5 => Parameter object: 3, 5 => true Assumptions: Both lists have at least one element. . Function prefour . Parameter: An object of the class AnyList. . Given a non-empty singly-linked list, the function copies all elements from the parameter list that come before the first 4 into the calling object in reverse order. Example: Parameter object: 1, 2, 7, 5, 4, 1 => Calling object becomes: 5, 7, 2, 1 Parameter object: 3, 1,4 Calling object becomes: 1,3 Parameter object: 1, 4, 4 => Calling object becomes: 1 Assumptions: The calling object is empty. The parameter list contains at least one 4. Function commonEnds Parameter: An object of the class AnyList. The function returns true if the calling object and the parameter object have the same first element AND the same last element. Example: Calling object: 1, 2, 3 => Parameter object: 1, 4, 3 => true Calling object: 5, 6, 1, 4 => Parameter object: 5, 3, 1, 7, 4, 3, 4 => true Calling object: 3, 4, 5 => Parameter object: 3, 5 => true Assumptions: Both lists have at least one element

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!