Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Add a palindrome funtion to the code that returns true or false Main_enum.cpp file #include #include #include Stack_enum.h using namespace std; // ******************** Main Function

Add a palindrome funtion to the code that returns true or false

Main_enum.cpp file

#include #include #include "Stack_enum.h" using namespace std;

// ******************** Main Function ******************** void main () { int id; char ch; int total; cout << "enter the number of food trays (0-" << size <<"): "; cin >> total; ifstream infile; infile.open("in.txt");

StackType tray; for (int i = 0; i < total; i++) { infile >> id; tray.push(id); } // end for -i- tray.print();

cout << " *** top tray = " << tray.top() << endl; tray.pop(); tray.pop(); cout << " *** top tray = " << tray.top() << endl; tray.push(10); tray.push(20); tray.push(30); tray.print();

StackType Letters; for (int i = 0; i < total; i++) { infile >> ch; Letters.push(ch); } // end for -i- Letters.print();

// to hold the command prompt window system("pause"); } // end main

stack_enum.h file

#include using namespace std;

const int size = 10; enum ErrorCode {Successfull, Underflow, Overflow, NotFound};

template class StackType { protected: type stack[size]; int count; public: StackType(); ~StackType(); bool isEmpty() const; bool isFull() const; int getCount() const; ErrorCode print() const;

ErrorCode push(type e); // addToLast ErrorCode pop(); // deleteFromLast type top() const;

ErrorCode search (type e, int &index); };

template StackType::StackType() { count = 0; }

template StackType::~StackType() { cout << "we are about to delete our stack" << endl; }

template bool StackType::isEmpty() const { return (count == 0); }

template bool StackType::isFull() const { return (count == size); }

template int StackType::getCount() const { return count; }

template ErrorCode StackType::print() const { if(!isEmpty()) { for(int i=count-1; i>=0; i--) cout << "the stack element "<<(i+1) <<": " << stack[i] <

template ErrorCode StackType::push(type e) { if(!isFull()) { stack[count++] = e; return Successfull; } else return Overflow; }// addToLast

template ErrorCode StackType::pop() { if(!isEmpty()) { count--; return Successfull; } else return Underflow; }// deleteFromLast

template type StackType::top() const { return stack[count-1]; }

template ErrorCode StackType::search (type e, int &index) { index = -1; if(!isEmpty()) { for (int i=count-1; i>=0; i--) if(stack[i] == e) { index = i; return Successfull; } } else return Underflow; return NotFound; }

in.txt input file

100 97 50 33 20 A B C D F

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

Building The Data Warehouse

Authors: W. H. Inmon

4th Edition

0764599445, 978-0764599446

More Books

Students also viewed these Databases questions

Question

4 How do Interpretive tasks help learners for Mediation?

Answered: 1 week ago