CMPS-2020 Programming II: Data Structures and Algorithms
Lab-6

Overview:

Lab programming
Please do your work in 2020/6/ folder on Odin.

We will start this assignment together on the big-screen.

Start with your program named insertion.cpp

Gordon will show you how to fix the sort algorithm we did in class.

We will make this program display a sorting animation.

When this works, you will add another algorithm to your program.

Choose bubble or selection sort.

Let the user choose which sort algorithm to animate.


Homework part 1
Application of sort algorithm.

Name this program /2020/hw6.cpp.

Use your sorting skills to do the following...

1. Read the dictionary file at: /usr/share/dict/cracklib-small.

2. Put the dictionary words into an array of character strings.
   You may use the string class if you need to.

3. Sort the array of words.
   Use selection-sort algorithm.

4. Apply a binary search to look for a given word.
   The word will be stored in a c-string (or string).

5. Ask the user to enter a word.
   Search for the word using your binary search.
   Indicate found or not.


Other requirements:
No global variables.
Additional functions written go below the main function.
Function prototypes are just above the main function.


Additional homework item... Your hw6.cpp program should be able to read words from a file, along with input from a user. If your program detects a command-line argument from the user, do the following: The argument will be the name of a text file. 1. Open the file. 2. Read each word. 3. Search the dictionary. 4. Indicate found or not. A user will apply this functionality by entering a filename on the command-line when running your program. Example: run the program normally... $ ./hw6 run the program with input from a text file... $ ./hw6 words.txt We will discuss command-line input. The "words.txt" file would look like this: +------------------------+ | 9 | | dog | | cat | | school | | classroom | | student | | wristwatch | | hieroglyphics | | twitterfiles | | astronmy | +------------------------+ First line indicates how many words in file. Next lines are the words. While processing, display each word and indicate if found.

Sample output

Sample output...

$ ./hw6 Homework-6 Search for words in a dictionary using binary-search. 52875 words found. out of order. sorting now... sort complete! in order. Enter a word: bookstore bookstore was found at index 6439 Done.
Sample run with input of text file...
$ ./hw6 myfile.txt Homework-6 Search for words in a dictionary using binary-search. 52875 words found. out of order. sorting now... sort complete! in order. Reading text file: myfile.txt nn = how many compares were needed. 15 dog 16 cattle birdy 15 birdie lizzards 15 lizards 14 fishing 14 kingfisher 14 pro 13 gram 16 program 16 programmer 16 programming programable 12 programmable Done.
This assignment requires a minimum of 10-hours of work. Do the work one step at a time. Write some code, and compile often.

What to turn in...
Do your work on Odin in 2020/6/ folder.

files to be collected...
   insertion.cpp
   lab6.cpp
   hw6.cpp