Question: Purpose This is what I learned so far: Functions Arrays Adding, removing, and shifting elements in an array Task Open the Algorithmic Design Document, make
Purpose
This is what I learned so far:
Functions
Arrays
Adding, removing, and shifting elements in an array
Task
Open the Algorithmic Design Document, make a copy, and follow the steps to create your algorithm.
You must express your algorithm as pseudocode or a flowchart.
Please take a look at the sample run below before you continue!
Start with the code in this starter file. You will want to copy it into a directory of your own:
You are not allowed to use or any other header files in STL
Complete the functions enqueue and dequeue The function printQueuehas been created for you. Please use printQueue to print the queue.
Complete the function: int enqueueint queue int &size, int val
Inserts a value into the REAR of a queue of integers.
Takes three arguments:
queue The array containing the queue
size A reference to the number of elements in the queue
val The value to insert
Returns on success, on overflow queue is full, cannot add
For example, queue with MAX of and size after integers were added in that order calls to enqueuequeue size, enqueuequeue size, enqueuequeue size, :
Complete the function: int dequeueint queue int &size, int val
Removes a value out of a queue of integers.
Integers are removed from the FRONT of the queue.
If the integer is in the queue, ALL integers before are also removed and the remaining elements are shifted to the FRONT of the queue.
The first occurrence is removed if there are multiple occurrences.
Takes three arguments:
queue The array containing the queue
size A reference to the number of elements in the queue
val The integer to be removed from the queue
Returns on success, on underflow queue is empty, no values to dequeue if integer is not in the queue.
For example, using the queue above, the queue after a call to dequeuequeue size, notice both elements and were removed from the queue and was moved to the front of the queue, size is now :
Requirements for enqueueand dequeue functions:
Do not alter the existing prototypes.
Your functions should insert the integers from the REAR of the queue, low indices to high indices; that is newer elements should be added at higher array indices. FRONT of the queue is at index
If an overflow or an underflow occurs, your functions must return an error code; they should not attempt to modify the queue. Handle the return code in the main function, print the error message in main
enqueue and dequeue should only manipulate the given queue; they should not print anything!
In your main an array of size has been declared for you. Using a small array will make it easier to debug all of the conditions. You should then read user commands input type char and use the queue functions to manipulate the queue accordingly. The program must support the following singlecharacter commands:
Adds an integer into the rear of the queue.
Removes an integer from the front of the queue. All integers before are also removed see sample run
p Prints the queue.
q Quit.
The queue should be printed using printQueue after every command except q
If an unknown command is entered, print an error message and DO NOT print the queue.
Use only the concepts we have learned so far.
Please follow ALL the instructions to submit your file in the Criteria for Success section below.
Criteria for Success
Test your program using the following sample runs using the given queue size of making sure you get the same output using the given inputs in blue
@ p q
Welcome to the FIFO Queue Program!
Enter option:
Integer:
Enter option:
Integer:
Enter option:
Integer:
Enter option:
Integer:
Error: Queue Overflow!
Enter option:
Integer:
is not in the queue.
Enter option:
Integer:
Enter option: @
Invalid option.
Enter option: p
Enter option:
Integer:
Enter option:
Integer:
Queue Empty.
Enter option:
Integer:
Enter option: q
Goodbye!
Complete all sections of your Algorithmic Design Document.
Include pseudocode or a flowchart in part d of the design document.
Please open and compare your work with the grading rubric before submitting.
Remember to follow all style guidelines.
Download your Algorithmic Design Document as a PDF File Download PDF rename it to midterm.pdf
Upload your midterm.cpp C source file and midterm.pdf to the DL assignment folder.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
