Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please help me on this program.. the teacher wants it done in the form of the pr

ID: 3700734 • Letter: P

Question

please help me on this program.. the teacher wants it done in the form of the program template i put in the last photo

? nsu.blackboard.com [37] Alpha Male Strategi... Students NSU Labs- Spring 2018 https:Insu.blackboard.c Students NSU Inbox near newport news va jobs newport news va CSC 260L Laboratory 9 Spring 2018 Stacks & Queues Review You may assume the classes Stack and Queue hold integers class Stack will contain the usual functions bool Empey bool Fullo void Push (int item): void Pop D int Top D void displayStack class Queue will contain the usual functions bool Enqueue(int num) int Dequeue() bool Enptyo: bool Fullo vold displayQueue Enter an item in the queue Remove an item from the queue /Return true f queue is empty Return true if queue is ful1 Example of a problem: Suppose we have a queue Q: containing some integers. the integers in the queue, we can use a stack. Like this we want to reverse Stack S while (O.Empty0) s-push (Q. Dequeue 0) hile (1s.Emptyo) O.Enqueue (S.Top ) Exercise: 1. Given a Queue S0 points) Write code to a. Enqueue 200 randomly generated integers (ranging 200-1000, inclusively) into the b. Modify the queue by change all of its even values to the number 2. Otherwise, the final values in the queue will be the same and in the same order but with all even values changed to Hint: use a temporary queue Save your file as labo9ModifyQueue finitialLastName.cpp

Explanation / Answer

Program 1:

// File Name: Queue1.cpp
#include<iostream>
#include<string.h>
#include<stdlib.h> // for srand
#include <time.h> // for time
using namespace std;
// Define maximum length of the queue
#define MAX_SIZE 200

class Queue
{
private:
// Index to top of the queue
int head, tail;
// The Queue
int theQueue[MAX_SIZE];
public:
// Default constructor
Queue();
// Insert an item into the queue
bool Enqueue(int num);
// Delete an item from the queue
int Dequeue();
// Returns true if the queue is empty
bool isEmpty();
// Returns true if the queue is full
bool isFull();
// Display the queue contents
void displayQueue();
};// End of class

// Default constructor definition
Queue::Queue()
{
head = tail = -1;
}

// Function to insert an item into the queue
bool Queue::Enqueue(int num)
{
// Checks to see if the queue is full. If full returns false
if(isFull())
return false;
// Increase the tail index by one
tail++;
// Insert the number into the queue
theQueue[tail % MAX_SIZE] = num;
// Returns success
return true;
}// End of function

// Function to delete an item from the queue
int Queue::Dequeue()
{
// To store the deleted number
int num;
// Checks for empty queue. If empty returns null
if(isEmpty())
return '';
// Otherwise delete the number
else
{
// Increase the head index by one
head++;
// Stores the deleted number
num = theQueue[head % MAX_SIZE];
// Returns the deleted number
return num;
}// End of else
}// End of function

// Function to returns true if the queue is empty otherwise false
bool Queue::isEmpty()
{
// Checks if head value is equals to tail value return true otherwise return false
return (head == tail);
}// End of function

// Function to returns true if the queue is full otherwise return false
bool Queue::isFull()
{
// Queue is full if tail has wrap around to location of the head
return ((tail - MAX_SIZE) == head);
}// End of function

// Display the queue contents
void Queue::displayQueue()
{
for(int c = head + 1; c <= tail; c++)
cout<<theQueue[c]<<"...";
cout<<endl<<endl;
}// End of function

// main function definition
int main()
{
// Creates one original queue, and one temporary queue
Queue myQueue, tempQueue;
// Initializes the high and low range for random number
int high = 1000, low = 200;
// To store the number
int no;
// initialize random seed
srand (time(NULL));
// Loops till MAX_SIZE
for(int c = 0; c < MAX_SIZE; c++)
// Generates a random number between high and low inclusive
// and insets it in the queue by calling Enqueue() function
myQueue.Enqueue(low + (rand() % high));

// Displays the original queue
cout<<" Original Queue: ";
myQueue.displayQueue();
// Loops till MAX_SIZE
for(int c = 0; c < MAX_SIZE; c++)
{
// Extracts item from the queue by calling Dequeue() function and stores it in no
no = myQueue.Dequeue();
// If the number is even
if(no % 2 == 0)
// Insert 2 to the in temporary queue
tempQueue.Enqueue(2);
// Otherwise number is odd.
else
// Insert the original number in temporary queue
tempQueue.Enqueue(no);
}// End of for loop

// Displays the temporary queue
cout<<" After Manipulation Queue: ";
tempQueue.displayQueue();
}// End of main function

Sample Output:

Original Queue:
257...317...603...670...634...1129...670...1081...655...1002...256...254...549...1044...523...641...966...235...523...390...628...1095...786...298...1166...655...1003...446...305...372...945...725...1018...560...560...384...331...414...1076...448...892...763...921...364...1028...997...723...931...904...771...984...300...1092...630...394...596...1088...527...280...584...732...617...632...1171...263...775...1182...675...1132...1121...400...831...470...771...781...779...854...887...651...200...658...533...520...797...1184...959...899...523...844...506...268...727...734...362...985...329...527...316...443...805...205...474...465...487...742...555...211...797...258...977...473...368...659...1183...564...474...393...347...773...318...601...584...1182...885...710...759...670...717...371...927...769...623...360...242...1158...1176...619...802...802...1136...1112...308...958...626...596...547...301...739...847...832...553...495...552...682...990...416...773...504...1022...1128...1147...278...334...1169...275...736...201...1162...1038...896...364...333...466...766...1170...831...1181...681...593...656...849...1001...909...300...841...878...803...337...1139...1142...673...1090...462...739...460...531...342...580...681...445...


After Manipulation Queue:
257...317...603...2...2...1129...2...1081...655...2...2...2...549...2...523...641...2...235...523...2...2...1095...2...2...2...655...1003...2...305...2...945...725...2...2...2...2...331...2...2...2...2...763...921...2...2...997...723...931...2...771...2...2...2...2...2...2...2...527...2...2...2...617...2...1171...263...775...2...675...2...1121...2...831...2...771...781...779...2...887...651...2...2...533...2...797...2...959...899...523...2...2...2...727...2...2...985...329...527...2...443...805...205...2...465...487...2...555...211...797...2...977...473...2...659...1183...2...2...393...347...773...2...601...2...2...885...2...759...2...717...371...927...769...623...2...2...2...2...619...2...2...2...2...2...2...2...2...547...301...739...847...2...553...495...2...2...2...2...773...2...2...2...1147...2...2...1169...275...2...201...2...2...2...2...333...2...2...2...831...1181...681...593...2...849...1001...909...2...841...2...803...337...1139...2...673...2...2...739...2...531...2...2...681...445...

Program 2:

// File Name: Queue2.cpp
#include<iostream>
#include<string.h>
#include<stdlib.h> // for srand
#include <time.h> // for time
using namespace std;
// Define maximum length of the queue
#define MAX_SIZE 200

class Queue
{
private:
// Index to top of the queue
int head, tail;
// The Queue
int theQueue[MAX_SIZE];
public:
// Default constructor
Queue();
// Insert an item into the queue
bool Enqueue(int num);
// Delete an item from the queue
int Dequeue();
// Returns true if the queue is empty
bool isEmpty();
// Returns true if the queue is full
bool isFull();
// Display the queue contents
void displayQueue();
};// End of class

// Default constructor definition
Queue::Queue()
{
head = tail = -1;
}

// Function to insert an item into the queue
bool Queue::Enqueue(int num)
{
// Checks to see if the queue is full. If full returns false
if(isFull())
return false;
// Increase the tail index by one
tail++;
// Insert the number into the queue
theQueue[tail % MAX_SIZE] = num;
// Returns success
return true;
}// End of function

// Function to delete an item from the queue
int Queue::Dequeue()
{
// To store the deleted number
int num;
// Checks for empty queue. If empty returns null
if(isEmpty())
return '';
// Otherwise delete the number
else
{
// Increase the head index by one
head++;
// Stores the deleted number
num = theQueue[head % MAX_SIZE];
// Returns the deleted number
return num;
}// End of else
}// End of function

// Function to returns true if the queue is empty otherwise false
bool Queue::isEmpty()
{
// Checks if head value is equals to tail value return true otherwise return false
return (head == tail);
}// End of function

// Function to returns true if the queue is full otherwise return false
bool Queue::isFull()
{
// Queue is full if tail has wrap around to location of the head
return ((tail - MAX_SIZE) == head);
}// End of function

// Display the queue contents
void Queue::displayQueue()
{
for(int c = head + 1; c <= tail; c++)
cout<<theQueue[c]<<"...";
cout<<endl<<endl;
}// End of function

// main function definition
int main()
{
// Creates one original queue, and one temporary queue
Queue numQueue;
// Initializes the high and low range for random number
int high = 120, low = 0;
// To store the number
int no, counter = 0;
// initialize random seed
srand (time(NULL));
// Loops till MAX_SIZE
for(int c = 0; c < MAX_SIZE; c++)
// Generates a random number between high and low inclusive
// and insets it in the queue by calling Enqueue() function
numQueue.Enqueue(low + (rand() % high));

// Displays the original queue
cout<<" Original Queue: ";
numQueue.displayQueue();

// Loops till MAX_SIZE
for(int c = 0; c < MAX_SIZE; c++)
{
// Extracts item from the queue by calling Dequeue() function and stores it in no
no = numQueue.Dequeue();
// If the number is greater than or equals to 60 increase the counter by one
if(no >= 60)
counter++;
// Otherwise number is less than 60 display it.
else
cout<<no<<"...";
}// End of for loop
// Displays the counter value
cout<<" Number of elements >= 60 is: "<<counter;
}// End of main function

Sample Output:

Original Queue:
93...0...30...49...0...73...22...36...31...12...1...76...57...81...67...66...42...18...78...16...2...110...103...53...96...102...85...103...41...29...26...96...84...33...14...108...8...63...111...73...24...110...13...32...14...25...53...27...93...19...68...96...99...63...95...45...111...94...89...60...48...5...29...25...79...45...12...73...61...12...0...86...95...13...66...113...113...27...50...31...65...76...93...62...30...20...99...105...89...111...65...3...106...67...101...1...6...60...33...83...119...90...89...68...53...57...40...15...92...32...96...53...45...20...48...20...82...109...75...114...84...8...87...11...103...103...51...79...25...103...85...0...63...48...50...2...64...10...55...99...118...78...88...69...10...90...63...34...111...98...87...64...26...51...113...117...104...73...111...52...41...28...103...80...84...102...75...25...50...32...38...69...23...70...9...65...39...96...88...104...21...67...14...74...58...63...112...64...92...49...112...96...61...60...25...61...38...100...107...0...

0...30...49...0...22...36...31...12...1...57...42...18...16...2...53...41...29...26...33...14...8...24...13...32...14...25...53...27...19...45...48...5...29...25...45...12...12...0...13...27...50...31...30...20...3...1...6...33...53...57...40...15...32...53...45...20...48...20...8...11...51...25...0...48...50...2...10...55...10...34...26...51...52...41...28...25...50...32...38...23...9...39...21...14...58...49...25...38...0...
Number of elements >= 60 is: 111