Starting from:
$30

$24

Lab 04 Solution

Objectives:




Learn how to write a function to search an array.
Learn how to generate an array of n random values.
Learn how to sort an array (using selection sort)



First, write a program to create an array and fill it up with 20 randomly generated integers (range 0–10) and output the array. (Hint: Check the provided PowerPoint file regarding the random number generator code.)




Part 1:




Write a function to implement following function prototype:




void search(int array[], int length, int key);




The function takes input an integer array, the size of the array, and a key to search. The function outputs the key value and a message whether the key exists in the array or not. If the key exists, function outputs the number of occurrence of the key in the array.




Part 2:




Write a function to sort the array in Descending order (from largest to smallest) and output the result. You should implement the following function prototype and use the selection sort provided in the text book.




void selectionSort(int list[], int length);




Submit a single cpp file for both questions. You should get the similar output as below.






More products