Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

this is the C++ code i used for a simmilar assignment: #include using namespace std; const int n = 10; void rotate(int* arr) //Rotates an

image text in transcribed

this is the C++ code i used for a simmilar assignment:

#include using namespace std;

const int n = 10; void rotate(int* arr) //Rotates an input array that is passed to it as a pointer. { int temp = *(arr + n - 1); //Copy the last element of the array to temp. for (int i = n - 1; i > 0; i--) //For each element from last to first. *(arr + i) = *(arr + i - 1); //Copy the previous element to current location. *arr = temp; //Finally, copy the temp value to start location. } int main() { //Instantiate an array of size n. int array[n]; cout > array[i]; rotate(array); //Rotate the array. cout > temp; }

In similarity with lab 4, develop a program that dynamically creates an integer array of size n, where n is an integer that is obtained after prompting the user for the desired array size and then storing his keyboard input in variable n. The code shall then initialize the array with a random value for each element, drawn using the c standard library function rand (), and hence the function rand () shall be called n times. Your code shall then ask the user to type either 'r', 'f, ' or o, and your program should react to the user's input by performing one of the tasks below and then repeat (i.e. asks the user for his input again) 1. If the user enters 'r', the program re-initializes the array using a new set of random values (as described in assignment 1). 2. If the user enters 'f, the program initializes/re-initializes the array using a Fibonacci sequence (as described in assignment 2) 3. If the user enters 's', the program swaps values of array elements as described in lab 2 4. If the user enters '0', the program rotates the array as described in assignment 3 Each one of the four tasks shall be implemented as a separate function, i.e. you should have the mainO function and at least four others, one for each of the tasks. After performing one of the four tasks, the program displays the array content on the screen. If the user enters anything other than 'r, f', 's' or 'o', then the program exits, else the program repeats ie. asks the user for his input, and performs one of the three previously mentioned tasks again. The program continues to repeat till the user enters a character that is not 'r, f','s, or 'o Hints: solution on BB, as a starting point. You may use lab3, for which I posted the Use the new keyword to dynamically allocate memory for the array Before your program ends, you need to use the delete keyword to de-allocate the memory Try to first design your algorithm (in pseudo code, plain English, or a flow chart), and then code what you've designed in C++ Test your code before you submit it. Debug your code; If it did not work properly, ask why (from a high level) did it not work? Is it an algorithmic or coding error? Use the debugger to identify the root-cause and fix your code. . . . . . . What to hand in: A description of your design/algorithm in pseudocode, flow chart, or plain English. The actual code in a".cpp" file (with appropriate comments)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

What is the significance of customer acceptance provisions?

Answered: 1 week ago

Question

What is the total amount of cash paid to suppliers for 2020?

Answered: 1 week ago