I need answers on this whole assignment, thank you so much! ? nsu.blackboard.com
ID: 3700235 • Letter: I
Question
I need answers on this whole assignment, thank you so much!
? 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.cppExplanation / Answer
NOTE: The code mention below has an assumption that the classes Queue and Stack exist. Without the, the code wont compile.
lab09ModifyQueue_.cpp
/*This code wont compile because classes Queue are not included. Kindly create Queue classes according to mention definition and then include it and then compile and run this code.*/
#include<iostream>
using namespace std;
int start = 200;
int last = 1000;
Queue Q;
int main(){
/*Generate 200 random numbers and enqueue them*/
for(int i=0; i < 200; i++){
int r = start + (rand() % (last - start + 1));
Q.Enqueue(r);
}
/*Change all the even values to number 2*/
Queue<int> tmp;
while(!Q.Empty()){
int f = Q.Dequeue();
if(f&1)
tmp.Enqueue(f);
else
tmp.Enqueue(2);
}
tmp.displayQueue();
return 0;
}
lab09LessThan60_.cpp
/*This code wont compile because classes Queue are not included. Kindly create Queue classes according to mention definition and then include it and then compile and run this code.*/
#include<iostream>
using namespace std;
int start = 0;
int last = 120;
Queue Q;
int main(){
/*Generate 200 random numbers and enqueue them*/
for(int i=0; i < 200; i++){
int r = start + (rand() % (last - start + 1));
Q.Enqueue(r);
}
int count = 0;
/*Search all the values greater than or equal to 60 and find the count*/
Queue<int> tmp;
while(!Q.Empty()){
int f = Q.Dequeue();
if(f>=60){
count+=1;
}
else{
tmp.Enqueue();
}
}
tmp.displayQueue();
return 0;
}
lab09ReverseStack_.cpp
/*This code wont compile because classes Queue are not included. Kindly create Queue classes according to mention definition and then include it and then compile and run this code.*/
#include<iostream>
using namespace std;
int start = 200;
int last = 1000;
Queue Q;
Stack S;
int main(){
/*Extracting elements and putting into Queue*/
while(!S.Empty()){
Q.Enqueue(S.top());
S.pop();
}
/*Putting back the elements into stack*/
while(!Q.Empty()){
S.push(Q.Dequeue());
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.