Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Screenshot of the output is at the bottom. Program provided is as3_Combo_starter.cpp. #include #include #include #include using namespace std; template struct Node { T value;

image text in transcribed

Screenshot of the output is at the bottom. Program provided is as3_Combo_starter.cpp.

#include #include #include #include using namespace std;

template struct Node { T value; // The value in this node Node *next; // To point to the next node };

template class Combo { private: int count; Node *head; // List head pointer public: // Constructor Combo() { head = nullptr; count = 0; }

// Destructor ~Combo() { Node *p = head; while(p) { delete p; p = p->next; } } void insert(T); // ref. for push_front void remove(T); // ref. for pop_front and pop_back void display() const; // std::string toString();

// here are the new ones T front(); // read front T back(); // read back void push_front(T); void push_back(T); // i.e append void pop_front(); void pop_back(); int size() { return count; } }; template void Combo::insert(T num) { Node *newNode, *p, *prev=nullptr; newNode = new Node; newNode->value = num; newNode->next = nullptr;

// if(head == nullptr) if(!head) { // empty list head = newNode; count++; } else { p = head; while( p != nullptr && p->value next; } // p must be pointing to the first bigger, or end if(prev==nullptr) { // the first one is the last one. head = newNode; newNode->next = p; } else { prev->next = newNode; newNode->next = p; } count++; } }

template void Combo::remove(T num) { Node *p, *prev=nullptr; if(!head) return; if(head->value == num) { p = head->next; delete head; head = p; count--; } else { p = head; // skip all NOTs while( p != nullptr && p->value != num) { prev = p; p = p->next; } if(p) { prev->next = p->next; delete p; count--; } } }

template void Combo::display() const { Node *p = head;

while(p->next) { std::cout value next; } std::cout value

template std::string Combo::toString() { std::stringstream ss; Node *p = head; bool first = true; while(p){ if (first) first = !first; else ss value; p = p->next; } return ss.str(); }

int main() { Combo list; list.push_front(3.3); list.push_front(1.1); list.push_back(5.5); list.push_back(7.7); list.push_back(9.9); auto showd = [](Combo& x) { cout

list.pop_front(); list.pop_back(); showd(list);

list.pop_front(); list.pop_back(); showd(list); list.pop_front(); list.pop_back(); showd(list); Combo slist; auto shows = [](Combo& x) { cout

slist.push_front("fruits"); slist.push_front("delicious"); slist.push_front("eat"); slist.push_back("like"); slist.push_back("apple"); shows(slist); slist.pop_front(); slist.pop_back(); shows(slist);

slist.pop_front(); slist.pop_back(); shows(slist);

slist.pop_front(); slist.pop_back(); shows(slist); }

image text in transcribed

This assignment is to exercise one of the basic container class: List, Stack and Queue in Chapter 7, 8, 9, 13 and 14 of the Carrano textbook. We are going to use the NumberList Class that we templated in Module 2(source code can be found in the mo2/test NumberList.cpp) as a base and designa generic Combo (Stack +Queue) Class. You may use the textbook Chapter 14 example and exercise on design and apply the C++ class. Designing a Combo (Stack + Queue) Class Before you start on this exercise, you must be pretty familiar with the templating of a specifc typed container. We have covered that topic in Module 2. Let us assume everyone is really comfortable in converting a typed linked list to a generic template linked list. We are going to add the following class methods by adding/modifying necessary code to the LinkedLList class from the Module 2. We are going to complete the following Combo features mapped from the STL Stack and Queue: STL Stack STL Queue empty size front Combo Container empty size front back push front push back pop front pop back empty size back push push pop pop 1. Complete all combo class feature methods listed above 2. Create a toString method to output a string of the all nodes' value separated by a space character. 3. Use the provided test driver to validate your work. 4. Convert this test driver software into an user interactive with batch capability test program. Defined below is the Combo container class definition. Some NumberList class methods are commented out but left there for your reference. You may also find the following source code in the starter m03/as3_Combo_starter.cpp and the original NumberList Class m02/test_list.cpp at the course github This assignment is to exercise one of the basic container class: List, Stack and Queue in Chapter 7, 8, 9, 13 and 14 of the Carrano textbook. We are going to use the NumberList Class that we templated in Module 2(source code can be found in the mo2/test NumberList.cpp) as a base and designa generic Combo (Stack +Queue) Class. You may use the textbook Chapter 14 example and exercise on design and apply the C++ class. Designing a Combo (Stack + Queue) Class Before you start on this exercise, you must be pretty familiar with the templating of a specifc typed container. We have covered that topic in Module 2. Let us assume everyone is really comfortable in converting a typed linked list to a generic template linked list. We are going to add the following class methods by adding/modifying necessary code to the LinkedLList class from the Module 2. We are going to complete the following Combo features mapped from the STL Stack and Queue: STL Stack STL Queue empty size front Combo Container empty size front back push front push back pop front pop back empty size back push push pop pop 1. Complete all combo class feature methods listed above 2. Create a toString method to output a string of the all nodes' value separated by a space character. 3. Use the provided test driver to validate your work. 4. Convert this test driver software into an user interactive with batch capability test program. Defined below is the Combo container class definition. Some NumberList class methods are commented out but left there for your reference. You may also find the following source code in the starter m03/as3_Combo_starter.cpp and the original NumberList Class m02/test_list.cpp at the course github

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle PL/SQL Programming Database Management Systems

Authors: Steven Feuerstein

1st Edition

978-1565921429

Students also viewed these Databases questions

Question

=+ (b) Show that no record stands forever.

Answered: 1 week ago