Design a modular no global variables or constants program th
Design a modular (no global variables or constants) program that allows the user to enter 20 names into a string array. Sort the array in ascending alphabetical order and displays its contents. Then modify the Sorted Names Program that you wrote so it allows you to search arrray for a specific name.
Additional program requirements: • Program functionality should execute as follows: o Create an array of 10 names that is initially populated with values. The pseudocode format for this array is given below:Declare String names[10] = “Ross Harrison”, “Hannah Beauregard”, “Bob White”, “Ava Fischer”, “Chris Rich”, “Xavier Adams”, “Sasha Ricci”, “Danielle Porter”, “Gordon Pike”, “Matt Hoyle”
o Sort the array of 10 names in ascending (a to z) order using either the Bubble, Selection, or Insertion Sort algorithms. The names will be sorted by first and last name together (NOTE: Do not parse out the last name and sort by last name.) o Display the sorted list of names to the user with a descriptive message. o Prompt the user to enter a name to search and use the search name to determine if it is in the array of names. o If the name is found in the list, identify the ordered number (in the array) of the user requested name. If the name is not found in the list, display an error message indicating the name is not in the list. o Include a modular approach: no global variables, use parameters and return values to transfer data between modules and functions. • Include and use modules (at least) to do the following: o Main controlling start module to create variables, call sort and display modules, prompt for search name, call search function and display search results o Sort names array. o Display the names array • Include and use a function (at least) to do the following: o Search the names array for a given name and return the index of found, -1 otherwise. Use either the Linear Search or the Binary Search algorithms in your solution.
a) Use a software application to create the PSEUDOCODE (NOT JUST A COPY OF PYTHON CODE... ACTUAL PSEUDOCODE)
b) Create the Python source code that represents the pseudocode requirements from the previous step. The Python source code must have the following for full credit: •Program header comments that includes short problem description • End of program comments that include output from sample program run.
Solution
#Pseudocode
\'\'\'
bubble sort
for each pass i <- 1 to n-1 //n-1 passes
for each j <- 0 to n-i
check every pair of adjescent elements
and swap if a[j] > a[j+1]
end for
end for
binary search
1. Let low = 0 and high = n-1.
2. Compute guess as the average of low and high,
rounded down (so that it is an integer).
3. If array[guess] equals target, then stop.
You found it! Return guess.
4. If the guess was too low, that is,
array[guess] < target, then set low = guess + 1.
5. Otherwise, the guess was too high. Set high = guess - 1.
6. Go back to step 2.
\'\'\'
#Method to sort array using bubble sort
def bubbleSort(alist):
for i in range(1,len(alist)-1):
for j in range(0,len(alist)-i):
if alist[j]>alist[j+1]:
alist[j],alist[j+1] = alist[j+1],alist[j] #swapping in one line
#Searching using binary search because of efficiecy
def binary_search(alist,key,low,high):
if(high >= low):
mid = (low + high)/2
if(alist[mid]==key):
return mid
if(alist[mid] > key):
return binary_search(alist,key,low,mid-1)
return binary_search(alist,key,mid+1,high)
return -1
def main():
#Declare array of strings
names = [\"Ross Harrison\", \"Hannah Beauregard\", \"Bob White\", \"Ava Fischer\", \"Chris Rich\", \"Xavier Adams\", \"Sasha Ricci\", \"Danielle Porter\", \"Gordon Pike\", \"Matt Hoyle\"]
#Sort array using bubble sort
bubbleSort(names)
#Print Sorted array
print \"Sorted Array : \",names
#Print Location of searched element in sorted array
key = raw_input(\"Enter a key to be searched: \")
result = binary_search(names,key,0,len(names)-1)
if result == -1:
print \"Element Missing!!\"
else:
print \"Element found at : \", result
if __name__==\"__main__\":
main()
#Output:
\'\'\'
akshay@akshay-Inspiron-3537:~/Chegg$ python buub.py
Sorted Array : [\'Ava Fischer\', \'Bob White\', \'Chris Rich\', \'Danielle Porter\', \'Gordon Pike\', \'Hannah Beauregard\', \'Matt Hoyle\', \'Ross Harrison\', \'Sasha Ricci\', \'Xavier Adams\']
Enter a key to be searched: Chris Rich
Element found at : 2
akshay@akshay-Inspiron-3537:~/Chegg$ python buub.py
Sorted Array : [\'Ava Fischer\', \'Bob White\', \'Chris Rich\', \'Danielle Porter\', \'Gordon Pike\', \'Hannah Beauregard\', \'Matt Hoyle\', \'Ross Harrison\', \'Sasha Ricci\', \'Xavier Adams\']
Enter a key to be searched: Matt Hoyle
Element found at : 6
akshay@akshay-Inspiron-3537:~/Chegg$ python buub.py
Sorted Array : [\'Ava Fischer\', \'Bob White\', \'Chris Rich\', \'Danielle Porter\', \'Gordon Pike\', \'Hannah Beauregard\', \'Matt Hoyle\', \'Ross Harrison\', \'Sasha Ricci\', \'Xavier Adams\']
Enter a key to be searched: Mark Zane
Element Missing!!
\'\'\'

