Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need in c++ asap thank you!! This assignment writeup represents a program specification. It explicitly states how you are to code the API for each

Need in c++ asap thank you!!
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
This assignment writeup represents a program specification. It explicitly states how you are to code the API for each function. Once developed and debugged, they could be placed into a library, documented, and made available to anybody for use. For that to happen, you must follow the function specs exactly, and must also document your functions with descriptions of the preconditions, postconditions, and what they do (why somebody would use them). If you code doesn't follow the spec, you will lose two letter grades. In this assignment, you're going to create an array of integers, sort it, and search it. You're going to modularize your code into six functions: main createArray display selectionsort linearsearch binarysearch Main's skeleton: allocate two arrays of 105 random integers each display array 1 sort array 1 giving array 2 display array 2 ask the user for an integer to search for search array 2 using linear search display search results: search array 2 using binary search display search results continue search logic until user enters 1 as the search value, which is the indicator that the program should stop. Sample console session: Here is the unsorted array 3265698965 116278469 349359810055 - (display of all 105 elements) Here is the sorted array 12256 7891114-(displayofall105elements) Enter an integer to search for 49 Invoking linear search target found - element \# 25 number of iterations =25 invoking binary search target found - element \# 25 number of iterations =6 Enter an integer to search for 82. invoking linear search element not found number of iterations =105 invoking linear search element not found number of Iterations =4 Enter an integer to search for 1 Thanks and have a nice day! Function dynAlloc Prototype void createArray (arguments) Arguments: (1) the number of elements to allocate (2) a pointer to the allocated array. The pointer is defined in main and passed by reference so that when the function allocates the array, the address of that array can be passed back to main. createArray allocates memory for an array of ints of the specified size, and populates it with random integers in the range 1-100 inclusive. Function selectionSort Prototype void selectionsort (arguments) Arguments: (1) the size of the array (2) a pointer to the sorted array (3) a pointer to the unsorted array Pass 1. Scan list looking for lowest element. It's 10. Swap 10 with the leftmost element and we get 10206050408070 Notice that 10 is in its final position. Pass 2. Scan the list again, but when we find it, put it into the leftmost +1 position. We swap 20 and 20 (nothing happens). Now 10 and 20 are in their final positions. 10206050408070 Pass 3. Repeat the process. We swap 60 and 40 10204050608070 Pass 4. Swap 50 and 50 (nothing happens) 10204050608070 Pass 5. Swap 60 and 60 (nothing happens) 10204050608070 Pass 6, Swap 80 and 70 10204050607080 We're at the last element, so we're done. 10204050607080 Selection sort logic pre conditions list array of items to sort n size of list: post conditions list is sorted in ascending order selection sort (list, n) Pass 1. Scan list looking for lowest element. It's 10. Swap 10 with the leftmost element and we get 10206050408070 Notice that 10 is in its final position. Pass 2. Scan the list again, but when we find it, put it into the leftmost +1 position. We swap 20 and 20 (nothing happens). Now 10 and 20 are in their final positions. 10206050408070 Pass 3. Repeat the process. We swap 60 and 40 10204050608070 Pass 4. Swap 50 and 50 (nothing happens) 1020.4050608070 Pass 5. Swap 60 and 60 (nothing happens) 10204050608070 Pass 6. Swap 80 and 70 10204050607080 We're at the last element, so we're done. 10204050607080 Selection sort logic pre conditions list array of items to sort n size of list post conditions list is sorted in accending order. selection sort (list, n ) fori=1tosize1min=iforj=i+1tosizeiflist[j] target value high = middle 1 else found-true end while If (found = false) arrayposition =1 else arrayposition = middle endif retum arrayposition end binary search

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

Students also viewed these Databases questions

Question

-9 + (-5) Find the sum by hand.

Answered: 1 week ago

Question

socialist egalitarianism which resulted in wage levelling;

Answered: 1 week ago

Question

soyuznye (all-Union, controlling enterprises directly from Moscow);

Answered: 1 week ago