S10 Flowgorithm Assignment / Chapter 9: Sorting and Searching Arrays .ZIP

S10 Flowgorithm Assignment / Chapter 9: Sorting and Searching Arrays

INTRODUCTION: Download this document (S10 Flowgorithm Assignment.docx) from Blackboard, save it on your computer (in a folder that you can easily locate), and then open it in Word.

 PREREQUISITE: You need to have the Flowgorithm program installed. Refer to S02 Flowgorithm Assignment if you have not done this already.

TASKS: This assignment is taken from Program 9-8 on page 369-371 in Chapter 9 of the textbook. This program performs a binary search on an array of last names, and if a match is found, returns the phone number from a parallel array. There is a Main module and a function called   binarySearch(), which returns the array index of the found item, or -1 if a match is not found.

 You can create the program in Flowgorithm by following the pseudocode in the book for Program 9-8. There are a few new things, but none of them are difficult.

·         Constants, which can be simulated by using Integer variables spelled with upper case letters

·         String variables and String arrays, whose values must be entered with double quotes around them

·         A Boolean variable (found), which indicates if a match has been found

 It is important that you understand the logic of the binary search. You pick a middle point in a sorted array. If the value you are trying to match is lower than the middle value, you eliminate the top half of the array (by resetting the first pointer to one position after the middle). If the value you are trying to match is higher than the middle value, you eliminate the bottom half of the array (by resetting the last pointer to one position before the middle). You continue to search in the new “half array”, until a match is found, or you have determined that the match does not exist.

In this program, you will set up a sorted String array of last names, and a parallel String array of corresponding phone numbers. You will enter a last name to look for, and the program will tell you the person’s phone number if a match was found, or an error message if a match was not found.

ASSIGNMENT: Start Flowgorithm, and then do the assignment outlined in step 2. Save the Flowgorithm file on your flash drive or PC as S10.fprg. Submit the Flowgorithm file in Blackboard.

1)      Create a Flowgorithm program as follows.

a.       Include the usual comment lines for Author, Date and Description.

b.       Declare the constant   SIZE   as an Integer variable, and assign the value 6.

c.       Declare the two String arrays to a size of SIZE, and use individual assignment statements to set their values (names[0] = “Hall”, etc.). This takes some time to type, but you’ll be pleased when you get it working!

d.       Remember that you have to declare and assign variables in separate steps.

e.       You will write a function called   binarySearch()   with three arguments just as specified in line 31. It will return an Integer value named   position,   which is declared in line 62 and initially set to -1.

f.        Flowgorithm accepts both the C and Visual Basic operators, so you can specify “not found” as   NOT found, or you can specify it as   !found

g.       Be careful with your spelling and punctuation. Each non-comment line in this Flowgorithm program can be entered from the pseudocode in the book.

h.       Run the program with the input on page 371. Your output in the Console window should show the same values as the textbook. The screen shot below is from running the program with that input data.

i.        If there are any errors, recheck the instructions and correct them, then resave the file.

2)      Submit the Flowgorithm file S10.fprg by clicking on the View/Complete Assignment link in Blackboard, and attaching the file.

DEBUGGING THE PROGRAM: One of the greatest skills a programmer can develop is debugging, which means locating and fixing errors in a program. Email your instructor and ASK QUESTIONS if you are having trouble. Please attach your Flowgorithm file (S10.fprg) to your email.


·         You have tested the Flowgorithm program (S10.fprg) and it works correctly

·         Then, Attach the Flowgorithm file (S10.fprg) and Submit it through Blackboard

Powered by