Write a function called sort that takes in two parameters

Assignment Help Data Structure & Algorithms
Reference no: EM131264410

Assignment- Array Practice

Objective

To gain practice with arrays and common array algorithms, as well as the use of array parameters in functions.

Task

This assignment will consist of writing several functions that manipulate arrays or access data from arrays, as well as a test program that will allow interactive testing of the array functions.

Part 1: Functions

Write the following functions. Each one takes in an integer array as a parameter, and other necessary parameters and returns are described - read carefully. Make sure the parameters are in the order specified. **Make sure to use the const qualifier on the array parameter on any function where it is appropriate.** A sample CALL is given for each function.

• Insert

Write a function called Insert that takes in four parameters:

o an integer array
o the size of the array
o the new value to be inserted into the array
o the index at which to insert the new value

This function should insert a a new value into the array, at the specified index. Note that this means that other values have to "move" to make room. The last value in the array will just disappear from the array. If the index is out of bounds for the array, abort the function with no change made to the array. This function does not return a value. Sample call:

// Suppose the array "list" is {2, 4, 6, 8, 10, 12}

Insert(list, 6, 100, 3); // insert the value 100 at index 3.

// "list" is now {2, 4, 6, 100, 8, 10}

• Delete

Write a function called Delete that takes in three parameters:

o an integer array
o the size of the array
o the index of the item to delete

This function should delete the value at the given index. The remaining items in the array will need to shift over to fill the "empty" slot. The last item in the array (now vacant) should be set to 0. If the given index is out of bounds for the array, abort the function without deleting anything. This function does not return a value. Sample call:

// Suppose the array "list" is {2, 4, 6, 8, 10, 12}

Delete(list, 6, 2); // delete the value at index 2.

// "list" is now {2, 4, 8, 10, 12, 0}

• Reverse

Write a function called Reverse that takes in two parameters:

o an integer array
o the size of the array

This function should reverse the order of the array's contents. No returned value. Sample call:

// Suppose the array "list" is {2, 4, 6, 8, 10, 12}

Reverse(list, 6); // Reverse the array "list"

// "list" is now {12, 10, 8, 6, 4, 2}

• Sort

Write a function called Sort that takes in two parameters:

o an integer array
o the size of the array

This function should sort the array in ascending order. Note: You are NOT permitted to create any other Arrays to do this task (or any other task on this assignment). (See "bubble sort" in the book for help if needed, but you can use any type of sort you'd like.). This function should not return a value.

// Suppose "list" is {2, 5, 5, 10, 5, 10, 3, 4, 5, 9, -1, 6}

Sort(list, 12) // would change the list array to :

// {-1, 2, 3, 4, 5, 5, 5, 5, 6, 9, 10, 10}

• Found

Write a function called Found that takes in three parameters:

o an integer array
o size of the array
o The value to search for in the array

This function should return true if the value was found in the array and false otherwise. Sample calls:

// suppose "list" is {1, 3, 4, 6, 9, 10, 12, 0, 5, 2, -3}

Found(list, 11, 4); // this call should return the value true
Found(list, 11, 8); // this call should return the value false

Note that none of the five functions you'll write above do any keyboard input or screen output. You're also not permitted to create any other arrays in your code besides the original one in main().

Part 2: Test your Functions with your main() function

To help you test and get you started, I've provided you with a STARTER FILE which you SHOULD use to start. Fill in your code into this starter file. The starter file already contains the PrintArray function that we looked at in lecture class, as well as a function called FillArray that allows the user to enter values into an array from the keyboard. Call FillArray right after you create your array in main(). You may use these two provided functions in writing your main function which will test your array functions, as well as anywhere else you need these functionalities.

Write a main() function that creates an array of size SIZE (a constant given in the starter file). Since this is a constant, it can be changed for testing different sizes of arrays easily. Use this constant whenever referring to the array's size from main() (instead of using a hard-coded literal value).

Then, the program should go into a menu loop, presenting the user with the following menu the first time:

** Given features **

P Print the array contents
F Fill the array (user entry)

** Function Tests **

I Insert
D Delete
R Reverse
S Sort
X Found

M Print this menu
Q Quit this program

• The menu only needs to be printed explicitly the first time. Then, only re-print the menu if the user selects the M menu option.

• Prompt the user the first time and after every user selection to enter their next menu selection with the following:

• Enter your menu selection:

• The first two menu choices should just invoke the two already given functions: PrintArray and FillArray. The first will print the array contents, and the second will populate the array with user-entered values. (When testing, you'll want to populate your array first so you can test your functions that you create).

• The Q option should exit the menu loop and allow the program to end. Make sure to print out the final array before quitting the program

• The 5 menu options under **Function Tests** will test your functions. Some of them call for extra user input. The options should behave as follows (make sure to do any user input in the order specified):

o I: Prompt the user to type the value to be inserted, then the index to insert at. Call the Insert function appropriately, then print out the contents of the array

o D: Prompt the user to type the index to be deleted. Call the Delete function appropriately, then print out the contents of the array.

o R: No extra input required. Just call the Reverse function appropriately, then print out the array

o S: No extra input required. Just call the Sort function appropriately, then print out the array

o X: Prompt the user to enter a value to search for. Then call the Found function and print out a message indicating whether that value was found or not based on the function's return value. Example:

The value 6 appears in the list.

Hint: A good way to implement a menu loop is a switch statement (for processing a menu selection) inside of a do-while loop (for repeating the menu selection process).

General Requirements

• No global variables

• The required array tasks must be performed with the functions specified (not just with a single main() routine). Note that your 5 required functions should not have any cout/cin statements in them. You can have additional functions if you like, however make sure to have the 5 required ones, and that your required functions adhere to the specs.

• You may not change the two provided functions in any way (PrintArray and FillArray)

• You will need the iostream library. You may also use iomanip and/or cctype if you like. (No other libraries).

• As always, your source code must be readable and appropriately documented.

Reference no: EM131264410

Questions Cloud

Describe how disney decided to deal with long lines : Read page Service Insights 9.2 and Service Insights 9.3. Describe how Disney decided to deal with long lines. SERVICE INSIGHTS 9.2 - Disney Turns Queue Management into a Science and SERVICE INSIGHTS 9.3 - Waiting in a Virtual Queue
Accept in order to maximize operating income : Assume an engineering company provides services for three types of clients. Each service requires a different amount of a specific form of specialized labor that is in limited supply. If the company is limited to 4,000 hours of this specialized labor..
Consulting company performs basic market analysis : A consulting company performs a “basic” market analysis for a client. It incurs costs of $80,000 in performing the analysis and plans to sell the report to the client for $240,000. After reviewing the initial report, the client asks the firm if it is..
Who is correctly saving their files to a cd : When prompted, Mary Ann will click on Burn files to disc, indicate how she'll use the files, click on Burn to disc, and indicate the recording speed. Who is correctly saving their files to a CD?
Write a function called sort that takes in two parameters : Write a function called Sort that takes in two parameters. Write a function called Reverse that takes in two parameters. Write a function called Delete that takes in three parameters.
Analyze the case and conduct a value chain analysis : What does Coke do that adds value to the Coca-Cola Company. - Analyze the case and conduct a Value Chain Analysis (VCA) for Coca Cola Company.
Write a program that display a menu student can select from : Write a program that will help a student practice basic math (addition, subtraction, multiplication, and division). Display a menu the student can select from.
Determine the best threshold size for the combined : Design an experiment to determine the best threshold size for the combined "quicksort-plusinsertion-sort" implementation. You'll need to consider a range of data sizes, including both random and "worst-case" data sets.
Design an application that has an array of twenty integers : Design an application that has an array of at least 20 integers. It should call a module that uses the sequential search algorithm to locate one of the values.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  What is the probability

Suppose that the probability than an incoming email is a spam is p(S), that the probability that the word "w" occurs in the subject line of the spam is p(w), and that q(w) is the probability that the word "w" occurs in the subject line of an email th..

  Oracle provides erp solutions for mid-size business

oracle provides erp solutions for mid-size business organizations. for this assignment you are to write a research

  Find the spanning tree for the graph

Apply depth-first-search to find the spanning tree for the following graph with vertex d as the starting vertex

  Calculate the diffie-hellman key values

Calculate the Diffie-Hellman key values. Calculate values for both keys (secret key a and secret key b). You must show your work for full credit.This includes the calculations each person performs to calculate and verify the values.

  Determinethe assymtotic complexity

Determinethe assymtotic complexity (Big Theta) int terms of n (not sum) for the following code fragment in the average case.

  What would be the slowest time the algorithm can run

What would be the slowest time the algorithm can run (in terms of n). What input would cause this slowest time. What would be the fastest time your algorithm could run (in terms of n). For what input would this fastest time be achieved.

  Create a program that allows the user to input a list

Create a program that allows the user to input a list of first names into one array and last names into a parallel array. Input should be terminated when the user enters a sentinel character.

  Sort the objects use one sorting algorithm

Sort the objects use one sorting algorithm (e.g. bubble-sort) and write the sorting results back to a file 126export.txt.

  Draw a structured flowchart or write pseudocode

Draw a structured flowchart or write pseudocode that describes the process of looking up a word in a dictionary. Pick a word at random and have a fellow student attempt to carry out your instructions

  How many topological orderings does it have

Consider the directed acyclic graph G in Figure 3.10. How many topological orderings does it have. The algorithm described for computing a topological ordering of a DAG repeatedly finds a node with no incoming edges and deletes it. This will eventu..

  What would be value of elements in array after three passes

An array contains the elements shown below. What would be the value of the elements in the array after three passes of the heap sort algorithm?

  Design time randomized monte carlo algorithm

You have to design an O(n) time randomized Monte Carlo algorithm which computes an (1 + o)- approximate ham-sandwich cut with probability 1 - n-c for any given constant c > 0.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd