Exercises
Exercise 1
In the main, create a one-dimensional array named
exampleArray, consisting of 1000 random integers in the range 1 through 50
Call a function named printIt that will print
the last 100 elements of the array, 10 elements per line (the array should be labeled appropriately using
a
technique of your choosing)
Call a function named bubble that will bubble
sort the array.
The bubble sort routine will call a separate function to perform needed swaps.
The function will keep track of the number of times the swap routine is called
Call the function developed to print the array -
the array should be labeled as after bubble sort.
Once again, print the last 100 elements of the array, 10 elements per line
Also, print the number of times, appropriately labeled, that the swap function is called for bubble sort
Exercise 1a
Same as exercise 1 except prompt the user to enter an integer in the range 1 through 50
Call a function named findIT and pass the array and the integer to find
If the integer is found, print an appropriate statement along with the cell in which the first occurrence is found
If it is not found, print an apropriate statement
Exercise 2
Create an array consisting of 12 integers
(randomize by hand) using an initializer list
Call a function named selectionSort that will use
selection sort to sort the array.
Use a separate swap function to perform the needed swaps
The function will keep track of the number of times the swap routine is called.
Call the function developed to print the array -
the array should be labeled as after selection sort.
Also, print the number of times, appropriately labeled, that that the swap function is called for selection sort
Exercise 3
Create a two-dimensional array named twoD that
consists of 25 random integers (randomize by hand) in the range 1 through 9.
Use an initializer list
Print the array, appropriately labeled.
Use the built-in swap function to sort the second row
(second row only) - second row, not the one whose index is
2
Print the array, appropriately labeled.
Exercise 4
In the main
Ø create a one-dimensional array named exampleArray, consisting of 100 random integers in the range 0 through 99.
Ø prompt the user to enter a number between 1 and 100 to search for.
Ø give the user an option to use either bubble sort or selection sort to sort the array.
If the user selects an incorrect option, allow 2 more tries, if still unsuccessful, tell user the program is terminating or some
appropriate message
Ø call a function named printArray that will print the array, 10 elements per line (the array should be labeled appropriately using a technique of
your choosing)
Ø call a function named bubbleSort or selection sort depending upon the option chosen above that will sort the array.
Ø call the function developed to print the array - the array should be labeled as after sorting
Ø call a function named findIt and passes the number to search for identified above along necessary information about the array
Write the bubble sort and selection sort functions
Ø The functions will call a separate function to perform needed swaps.
Ø The functions will keep track of the number of times the swap routine is called
Write the function named findIt.
Ø The purpose of the function is to find and print, appropriately labeled, the index of the cell in which the number is found.
Ø Alternatively, if the number is not in the array, an appropriate statement that it is not in the array will be made
Ø This function will call a function named binarySerch to search for the array
Ø The binarySearch function will use the binary search algorithm
Write the function named binarySearch as described
above
Turn in
code
sample output working with correct user selection
sample output if user fails to select proper
option listed above
Exercise 5
This program simulates an automatic teller machine
Establish a numerical password
Prompt the user to enter the password
Create some type of loop so that the user has 3 tries to get the password
right.
Set a timer so that the user has 10 seconds to get the password right.
Give an appropriate message if the password is correct and if he misses it 3
times or time runs out