In the lecture we studied IntStack, a class that implements a static stack of integers. Write a template that will create a static stack of any data type. Demonstrate the class with a driver program. #pragma once
In the lecture we studied IntStack, a class that implements a static stack of integers. Write a template that will create a static stack of any data type. Demonstrate the class with a driver program. #pragma once
In the lecture we studied IntStack, a class that implements a static stack of integers. Write a template that will create a static stack of any data type. Demonstrate the class with a driver program. #pragma once
In the lecture we studied IntStack, a class that implements a static stack of integers. Write a template that will create a static stack of any data type. Demonstrate the class with a driver program.
#pragma once
class IntStack { private: int *stackArray; int stackSize; int top;
Queue Exceptions: Modify the static queue class provided in our lecture as follows.
Make the isFull and isEmpty member functions private.
Define a queue overflow exception and modify enqueue so that it throws this exception when the queue runs out of space.
Define a queue underflow exception and modify dequeue so that it throws this exception when the queue is empty.
Rewrite the main program so that it catches overflow exceptions when they occur. The exception handler for queue overflow should print an appropriate error message and then terminate the program.
#include <iostream> #include "Data.h" using namespace std;
//******************************************** // Function enqueue inserts the value in num * // at the rear of the queue. * //********************************************
void IntQueue::enqueue(int num) { if (isFull()) cout << "The queue is full.\n"; else { // Calculate the new rear position rear = (rear + 1) % queueSize; // Insert new item queueArray[rear] = num; // Update item count numItems++; } }
//********************************************* // Function dequeue removes the value at the * // front of the queue, and copies t into num. * //*********************************************
void IntQueue::dequeue(int &num) { if (isEmpty()) cout << "The queue is empty.\n"; else { // Move front front = (front + 1) % queueSize; // Retrieve the front item num = queueArray[front]; // Update item count numItems--; } } //********************************************* // Function isEmpty returns true if the queue * // is empty, and false otherwise. * //*********************************************
bool IntQueue::isEmpty() { bool status;
if (numItems) status = false; else status = true;
return status; }
//******************************************** // Function isFull returns true if the queue * // is full, and false otherwise. * //********************************************
bool IntQueue::isFull() { bool status;
if (numItems < queueSize) status = false; else status = true;
return status; } //******************************************* // Function clear resets the front and rear * // indices, and sets numItems to 0. * //*******************************************
Recursive Member Test: Write a recursive boolean function named isMember. The function should accept three parameters: an array of integers, an integer indicating the number of elements in the array, and an integer value to be searched for. The function should return true if the value is found in the array, or false if the value is not found. Demonstrate the use of the function in a program that asks the user to enter an array of numbers and a value to be searched for.
#include <iostream> using namespace std;
int main() {
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.