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...

  • 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....

  • 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....

  • 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...

  • Hello, I have some errors in my C++ code when I try to debug it. I...

    Hello, I have some errors in my C++ code when I try to debug it. I tried to follow the requirements stated below: Code: // Linked.h #ifndef INTLINKEDQUEUE #define INTLINKEDQUEUE #include <iostream> usingnamespace std; class IntLinkedQueue { private: struct Node { int data; Node *next; }; Node *front; // -> first item Node *rear; // -> last item Node *p; // traversal position Node *pp ; // previous position int size; // number of elements in the queue public: IntLinkedQueue();...

  • PROGRAMMING LANGUAGE OOP'S WITH C++ Functional Requirements: A jewelry designer friend of mine requires a program...

    PROGRAMMING LANGUAGE OOP'S WITH C++ Functional Requirements: A jewelry designer friend of mine requires a program to hold information about the gemstones he has in his safe. Offer the jewelry designer the following menu that loops until he chooses option 4. 1. Input a gemstone 2. Search for a gemstone by ID number 3. Display all gemstone information with total value 4. Exit ------------------------------------- Gemstone data: ID number (int > 0, must be unique) Gem Name (string, length < 15)...

  • Using C++ create a lotto program Lottery Design a program that simulates a lottery. Requirements:  The program...

    Using C++ create a lotto program Lottery Design a program that simulates a lottery. Requirements:  The program should have an array of 5 integers named lottery and should generate a random number in the range of 1 through 99 for each element of the array. The user should enter five digits, which should be stored in an integer array named user. The program is to compare the corresponding elements in the two arrays and keep a count of the digits that...

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
ADVERTISEMENT