Question
C++ This is a a few programs I need completed all in C++. The first part following this is the deliverables required and the steps
C++
This is a a few programs I need completed all in C++. The first part following this is the deliverables required and the steps required for each exercise. After that will be the code for each of the programs required to start the exercises.
Deliverables
There are six exercises in this Lab, although not all of them will be required for submission. Be sure to read the following instructions carefully.
Exercises 1 and 4: No submissions are required.
Create a folder and name it Week 3 Lab. Inside this folder, create the subfolders Ex2, Ex3, Ex5, and Ex6. Place the solution to each of the four exercises required for submission in the corresponding subfolder. Compress the folder Week 3 Lab, and submit the resulting zipped folder.
Note that Exercises 2, 3, 5, and 6 require software development. For each of them, place in the corresponding folder the source code files (i.e., .h and .cpp files) you created, and a screenshot of the execution window. Do not submit other files or folders, including those automatically generated by the IDE.
Exercise 1: Review of the Stack ADT
Create a project, A Simple Stack Class, using the programs in:
A Simple Stack Class (Links to an external site.)Links to an external site.
Compile the project, run it, and review the code that is given carefully. This program tests the Stack class discussed in the lesson.
Exercise 2: An Improved Stack Class
Modify the Stack class to include appropriate error messages if invalid conditions occurfor example, trying to pop an item when the stack is empty.
Exercise 3: Using a Stack in an Application
Complete Project P-5.12 at the end of Chapter 5 in our 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).
(C-5.8 Postfix notation is 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.)
Exercise 4: Review of the Queue ADT
Create a project, A Simple Queue Class, using the programs in:
A Simple Queue Class (Links to an external site.)Links to an external site.
Compile the project, run it, and review the code that is given carefully. This program tests the Queue class discussed in the lesson.
Exercise 5: An Improved Queue Class
Modify the Queue class to include appropriate error messages if invalid conditions occurfor example, trying to dequeue an item when the queue is empty.
Exercise 6: Using a Queue in an Application
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).
A SIMPLE STACK CLASS
main.cpp
/*******************************
* 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;
}
Stack.cpp
/*******************************
* 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;
}
Stack.h
/*******************************
* 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
};
A SIMPLE QUEUE CLASS
main.cpp
/*******************************
* Week 2 lesson: *
* 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;
}
Queue.cpp
/*******************************
* Week 2 lesson: *
* 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;
}
Queue.h
/*******************************
* 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
};
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started