Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

SIMPLE QUEUE CLASS CODE /******************************* * a simple Queue class * *******************************/ #include Queue.h /* * Constructor. Initializes the queue. */ Queue::Queue() { front =

SIMPLE QUEUE CLASS CODE

/******************************* * a simple Queue class * *******************************/

#include "Queue.h"

/* * Constructor. Initializes the queue. */ Queue::Queue() { front = 0; back = SIZE-1; count = 0; }

/* * Determines whether the queue is empty. * * Returns true if the queue is empty, false otherwise. */ bool Queue::isEmpty() { return count == 0; }

/* * Adds an element to the back of the queue. * * x: element to be added to the queue. */ void Queue::enqueue(char x) { back = (back+1)%SIZE; list[back] = x; count++; }

/* * Removes the element in the front of the queue. */ void Queue::dequeue() { front = (front+1)%SIZE; count--; }

/* * Returns the element in the front of the queue. Does not remove it. */ char Queue::getFront() { return list[front]; }

/* * Returns the size of the queue. */ int Queue::getSize() { return SIZE; }

SIMPLE QUEUE CLASS MAIN.CPP CODE

/******************************* * a simple Queue class * *******************************/

#include "Queue.h" #include

using namespace std;

int main() { Queue q;

cout << "Insertion of 10 characters in q" << endl; for(int i=0; i < q.getSize(); i++) { char x = 32 + rand()%95; cout << x << endl; q.enqueue(x); }

cout << endl << "Displaying and deleting elements from q" << endl; while(!q.isEmpty()) { cout << "Item at the front: " << q.getFront() << endl; q.dequeue(); }

return 0; }

SIMPLE QUEUE CLASS HEADER CODE

/******************************* * Week 2 lesson: * * a simple Queue class * *******************************/

/* * Class implementing a Queue ADT. */ class Queue { public: Queue(); bool isEmpty(); void enqueue(char); void dequeue(); char getFront(); int getSize();

private: static const int SIZE = 10; //size of the queue array char list[SIZE]; //array to store the queue items int count; //number of items in the queue int front, back; //front and back locations };

SIMPLE STACK CLASS CODE

/******************************* * Week 2 lesson: * * a simple Stack class * *******************************/

#include "Stack.h"

/* * Constructor. Initializes the stack. */ Stack::Stack() { top = 0; }

/* * Determines whether the stack is empty. * * Returns true if the stack is empty, false otherwise. */ bool Stack::isEmpty() { return top == 0; }

/* * Adds an element to the top of the stack. * * x: element to be added to the stack. */ void Stack::push(char x) { list[top] = x; top++; }

/* * Removes the element at the top of the stack. */ void Stack::pop() { top--; }

/* * Returns the element at the top of the stack. Does not remove it. */ char Stack::peek() { return list[top-1]; }

/* * Returns the size of the stack. */ int Stack::getSize() { return SIZE; }

SIMPLE STACK CLASS MAIN.CPP CODE

/******************************* * Week 2 lesson: * * a simple Stack class * *******************************/

#include #include "stack.h"

using namespace std;

int main() { Stack s;

cout << "Insertion of 10 characters in s" << endl; for (int i = 0; i < s.getSize(); i++) { char x = 32 + rand()%95; cout << x << endl; s.push(x); }

cout << endl << "Displaying and deleting elements from s" << endl; while(!s.isEmpty()) { cout << "Item at the top: " << s.peek() << endl;

s.pop(); }

return 0; }

SIMPLE STACK CLASS HEADER CODE

/******************************* * Week 2 lesson: * * a simple Stack class * *******************************/

/* * Class implementing a Stack ADT. */ class Stack { public: Stack(); bool isEmpty(); void push(char); void pop(); char peek(); int getSize(); private: static const int SIZE = 10; //size of the queue array char list[SIZE]; //array to store the stack items int top; //amount of elements in the array };

QUESTIONS

PART 1

Modify the Stack class to include appropriate error messages if invalid conditions occurfor example, trying to pop an item when the stack is empty.

PART 2

Complete Project P-5.12 at the end of Chapter 5 in Data Structures and Algorithms in C++ textbook: Implement a program that can input an expression in postfix notation (see Exercise C-5.8) and output its value. As you can see, you will need to read Exercise C-5.8 to complete this programming task.

To implement the solution to this problem, you are allowed to use the stack of characters from the previous exercises (1 and 2).

Exercise C-5.8 INFO:

Postfix notation s an unambiguous way of writing an arithmetic expression without parentheses. It is defined so that if (exp1) o (exp2) is a normal fully parenthesized expression whose operation is o, then the postfix version of this is pexp1 pexp2o, where pexp1 is the postfix version of exp1 and pexp2 is the postfix version of exp2. The postfix version of a single number or variable is just that number or variable. So, for example, the postfix version of ((5 + 2) * (8 3))/4 is 5 2 + 8 3 * 4 /. Describe a nonrecursive way of evaluating an expression in postfix notation.

PART 3

Modify the Queue class to include appropriate error messages if invalid conditions occurfor example, trying to dequeue an item when the queue is empty.

PART 4

Write an application to simulate an automatic call distributor or ACD. ACDs are used in call centers to route incoming calls to available agents. The application should consist of

  • an automatic call distributor (ACD) object; and
  • calls to be handled (each call is an object of the type Call).

The ACD object should contain a queue to store the information of the calls (therefore, the item type stored in your Queue class should be Call). Each Call object contains the associated phone number, date it was made, time it was made, a random ID, and a language chosen by the customer who made the call. Test your classes by deciding in main() the next action randomly: a call leaves the queue (call has been routed to an agent), a new call arrives to the queue, or simply do nothing (the state of the system remains the same).

C++

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

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions