Question

Using C++ Requirements Note: “deque” STL container is not allowed, for the simplicity for graders. Queue Queue is a firs...

Using C++

Requirements

Note: “deque” STL container is not allowed, for the simplicity for graders.

Queue

Queue is a first-in-first-out (FIFO) data structure.

For the Queue container, we will implement a program that simulates a buffer. The simulation needs a function that randomly generate number. And the buffer simulation starts with no value in the buffer.

At the start of simulation, the menu should ask user:

  • how many rounds will be simulated.
  • the percentage chance to put a randomly generated number at the end of buffer.
  • the percentage chance to take out a randomly generated number at the front of buffer.

Note: For all the percentages, the “%” character is not required from user inputs. For example, if user input 25, it means 25%, and the number “25” is stored in the variable, not “25%”, or “0.25”.

Once all the user input is validated and stored in variables, the buffer simulation will start.

The following is the flow of each round in the simulation:

  1. Generate a random number from 1 – 1000 called N.
  2. Appending number: Generate another random number from 1 – 100, if the outcome is less than or equal to the user specified percentage for adding value (Ex: 25), then append the number N into the queue.
  3. Removing numbers: Generate another random number from 1 – 100, if the outcome is less than or equal to the user specified percentage for removing value (Ex: 25), then remove a number from the front of queue.
  4. Output the values in the buffer, and then output the length of the buffer.
  5. Output the average length of buffer.

Equation for the average length of buffer:

ALi = (ALi-1 * (i – 1) + Li ) / i

where ALi and ALi-1 are the average length in the ith and (i-1)th round, Li is buffer length in the ith round.

Note: The average length should be double/float data type, so when printed, it should have decimals

Note: A general rule of thumb, if the buffer has higher percentage of adding value than removing value, the average length of buffer should increase; while if the buffer has lower percentage of removing value than adding value, the average length of buffer should decrease.

Stack

Use a stack to create a function that creates a palindrome, which is a string that is the same forwards and backwards. For example, “racecar” is a palindrome. The function should receive a string from user input, and return the string with the palindrome, by first adding the values of the original string sequentially to the stack, then popping off characters one by one and printing the character. The popped off string would be in reverse order when you pop them off the stack. For example, if user inputs "hello", your program will print the palindrome "helloolleh".

Menu

Create a menu for the user to test the buffer and create a palindrome.

For the queue, prompt the user to enter the two percentages, and the total number of rounds. Then, display the results to the console in each round.

For the stack, prompt the user to enter a string. Create the palindrome and then display it.

This criterion is linked to a Learning OutcomeImplement buffer simulation using <queue>

Implement palindrome function using <stack>

Create a menu program

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Stack palindrome using C++

#include<iostream>
#include<string.h>
#include<stack>
using namespace std;
void reverse(char *str,int len)
{
stack<char>s;
int i;
for(i=0;i<len;i++)
{
s.push(str[i]);
}
for(i=0;i<len;i++)
{
str[i]=s.top();
s.pop();
}
}
int main()
{
char str[50];
cin.getline(str,100);
int len=strlen(str);
cout<<str<<"";
  
reverse(str,len);
  
cout<<str;
return 0;
}

*******************************************************************END**********************************************************************

Add a comment
Know the answer?
Add Answer to:
Using C++ Requirements Note: “deque” STL container is not allowed, for the simplicity for graders. Queue Queue is a firs...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ Task 3: Use the stack and queue to simulate receiving and transforming data We are creating a system that will co...

    In C++ Task 3: Use the stack and queue to simulate receiving and transforming data We are creating a system that will convert strings sent over a serial bus one character at a time. The conversion will be from big to little endian or from little to big endian. To simplify this, each character will be considered a word. Little endian will have the lowest address first. Big endian will have the biggest address first. For example (for this lab),...

  • C++ -- Event processing simulation using a transaction queue Hi! it is queue simulation please read...

    C++ -- Event processing simulation using a transaction queue Hi! it is queue simulation please read the instructions, write codes, and explain the code with comments. Thank you Transactions enter the system and are stored in a queue. Each transaction represents some work that needs to be accomplished. Servers exist which process transactions. Servers take transactions off the queue and process them. you’re building the simulation framework. The idea is that somebody would take your framework, and add the specifics...

  • Using C++ in Visual Studios Rewrite the code to use a Stack instead of a Queue....

    Using C++ in Visual Studios Rewrite the code to use a Stack instead of a Queue. You will need to think about the differences in the Stack and Queue. Think about how they operate and how the nodes may differ.   Modify the code as necessary. You will need to push to the Stack, pop from the Stack, peek at the Stack. You will need a member functions like in the example code. Your program will need to show that everything...

  • Java:Netbeans-Use the LinkedList class to simulate a queue, and use the add method to simulate the...

    Java:Netbeans-Use the LinkedList class to simulate a queue, and use the add method to simulate the enqueue, and the remove method to simulate the dequeue method for a Queue. Remember to use FIFO. Need help with 0. Add New Microchips pushMicroChip(), popMicroChip() and . To simulate this, you will create a menu option 0, which will generate 100 microchip long objects, and place them into a stack of microchips. Those microchip objects will be generated by using the System.nanotime() method.  ...

  • In this assignment, you will write a simulator to determine maximum, minimum and average queue length....

    In this assignment, you will write a simulator to determine maximum, minimum and average queue length. Important: You can implement with the linked list classes described in Chapter 20 or the queueing structures described in Chapter 21. The user inputs the following information a. The relative weight of arrivals. This is an integer between 1-100. b. The number of servers. This is an integer between 1-25. c. The relative weight of a server. This is an integer between 1-100. d....

  • NOTE – You may use C++ - but you MAY NOT use #include <string> The goal...

    NOTE – You may use C++ - but you MAY NOT use #include <string> The goal is to use C-Style character array based strings. You will put all of your code in this file. You may use any technique we have learned so far. Specifications: This assignment is split into several parts. The goal is to get you used to working with C/C++ run-time arrays and strings. Part 0 – Create a Menu You should create a menu that gives...

  • Hi! it is c++ queue simulation please read the instructions, write codes, and explain the code...

    Hi! it is c++ queue simulation please read the instructions, write codes, and explain the code with comments. Thank you Transactions enter the system and are stored in a queue. Each transaction represents some work that needs to be accomplished. Servers exist which process transactions. Servers take transactions off the queue and process them. you’re building the simulation framework. The idea is that somebody would take your framework, and add the specifics for whatever type of system it was going...

  • In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and...

    In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and use recursive functions In this lab, we will write a program that uses three recursive functions. Requirements: Important: You must use the array for this lab, no vectors allowed. First Recursive Function Write a function that recursively prints a string in reverse. The function has ONLY one parameter of type string. It prints the reversed character to the screen followed by a newline character....

  • Project Lists and Object-oriented Programming Note: using c++ This project is an individual assignment that focuses...

    Project Lists and Object-oriented Programming Note: using c++ This project is an individual assignment that focuses on object-oriented programming and lists. The list will be a doubly-linked list and it will be implemented using nodes and pointers. The data contained in the list will be objects from a class. Project data: You will choose one of the following classes to define: Boat, Earthquake, Game, Sport, State, Website, House, Phone, Activist, Plant, Fish, Parrot, and Course. Your class code will include...

  • Please note that I cannot use the string library function and that it must be coded...

    Please note that I cannot use the string library function and that it must be coded in C89, thank you! Formatting: Make sure that you follow the precise recommendations for the output content and formatting: for example, do not change the text in the first problem from “Please enter a string of maximum 30 characters:” to “Enter string: ”. Your assignment will be auto-graded and any changes in formatting will result in a loss in the grade. 2.Comments: Header comments...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT