Question: Complete the Functions.cpp file. Use these files: AnyList.h AnyList.cpp Functions.cpp To test each function use these files one at a time: TestingGetMin.cpp TestingHaveThree.cpp // AnyList.cpp
Complete the Functions.cpp file.
Use these files:
- AnyList.h
- AnyList.cpp
- Functions.cpp
To test each function use these files one at a time:
- TestingGetMin.cpp
- TestingHaveThree.cpp

//
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(); }
// Given files
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 getMin // Definition function haveThree
//
//
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 getMin
// Definition function haveThree
// Definition function preFour
//Definition function commonEnds
//
TestingHaveThree.cpp
#include "AnyList.h"
#include
int main() { std::cout
std::vector> v1 = { { 3, 1, 3, 1, 3, 4, 3, 1, 3, 2 }, { 3, 1, 3, 3 }, { 3, 4, 3, 3, 4 }, { 1, 3, 1, 3, 1, 2 }, { 1, 3, 1, 3, 1, 3 }, { 1, 3, 3, 1, 3 }, { 1, 3, 1, 3, 1, 3, 4, 3 }, { 3, 4, 3, 4, 3, 4, 4 }, { 3, 3, 3 }, { 1, 3 }, { 3 }, { 1 }, };
std::vector<:string> vResults = { "False", "False", "False", "False", "True", "False", "False", "True", "False", "False", "False", "False" };
int sizeV1 = static_cast
for (int i = 0; i (v1[i].size()); for (int j = sizeInnerV1 - 1; j >= 0; --j) list1.insertFront(v1[i].at(j));
//
TestingGetMin.cpp
#include "AnyList.h"
#include
int main() { std::cout
std::vector> v1 = { { 1 }, { 5, 6, 2, 9, 3 }, { 3, 9 }, { 5, 7 }, { 2, 6, 9 }, { 9, 7, 5 }, { 6, 8, 3 }, { 2, 5, 3, 7, 9, 4, 1 }, { 2, 5, 7, 3, 4, 8, 6, 9 } };
int sizeV1 = static_cast
for (int i = 0; i (v1[i].size()); for (int j = sizeInnerV1 - 1; j >= 0; --j) list1.insertFront(v1[i].at(j));
// Print out std::cout
// Get minimum value std::cout
std::cout
std::cout
// Print out std::cout
// Get results std::cout
std::cout
std::cout
. 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. Function getMin The function traverses the list and returns the minimum (smallest) value found. Assumptions: Lst has at least one element. All values are greater than zero. Function haveThree The function returns true if the value 3 appears in the calling list exactly 3 times and no 3's are next to each other. After implementing and testing your function, analyze your code and make sure it is efficient. Example: 3, 1, 3, 1, 3 => true 3, 1, 3,3 => false 3, 4, 3, 3, 4 => false o Assumptions: List has at least one element. . 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. Function getMin The function traverses the list and returns the minimum (smallest) value found. Assumptions: Lst has at least one element. All values are greater than zero. Function haveThree The function returns true if the value 3 appears in the calling list exactly 3 times and no 3's are next to each other. After implementing and testing your function, analyze your code and make sure it is efficient. Example: 3, 1, 3, 1, 3 => true 3, 1, 3,3 => false 3, 4, 3, 3, 4 => false o Assumptions: List has at least one element
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
