CS215 - Introduction to Program Design, Abstraction, and Problem Solving

Fall, 2002

Programming Assignment #1

Assigned: Tuesday, October 1st, 2002

External Documentation Due: in class on Tuesday, October 8th, 2002

Program Listing and Executions Due: by e-mail by 11:59 pm on Tuesday, October 15th, 2002

Design, write, and execute a C++ program that will demonstrate the use of several sort and search routines by allowing the user to work with an ongoing, "current" list by repeatedly choosing actions from the following menu:
   1.  Reset the current list from the keyboard
   2.  Reset the current list using randomly generated elements
   3.  Perform Bubble Sort on the current list
   4.  Perform Insertion Sort on the current list
   5.  Perform Selection Sort on the current list
   6.  Perform Linear Search on the current list
   7.  Perform Binary Search on the current list
   8.  Quit the program
Here are some requirements for your program:

You should write this program by extending the AList class that we are currently developing in our CS215 lecture. At a minimum, your program must include and use the following C++ methods and associated parameters:

In order to make your main function relatively modular and easy to read, you should also include additional methods and/or functions as necessary.

Here are some hints to make your coding easier:

Be sure to follow the overall requirements for programming assignments found in the document called "Programming Requirements" posted on the CS215 Web Homepage. You'll need to develop and run your own thorough set of testcases, as well as run the set of required testcases I will make available shortly before the program listings and executions are due.

Be sure to submit your External Documentation printed out on paper, using the MS Word word-processing program and the MS Word "External Documentation Outline" provided on the CS215 Web Homepage.

Be sure to submit your Listing and Executions as two separate attachments to a single piece of e-mail sent from your SWEB computer account using the "pine" e-mail program. For your Listing, you should simply attach your C++ program (which should be in a file called "program1.cc"). For your Executions, you should attach your script file (which should be in a file called "program1.script"). Make sure that your script file shows that your program compiles using the g++ command on the SWEB Unix computer system, and shows both the required testcases and your own proposed testcases being executed by your program running on the SWEB Unix computer system. Be sure to use the following Subject: line in your e-mail, based on your CS215 section number:

Following is a sample of what your program executions should look like when completed. (The statistics shown below are only mock-ups -- your results may differ.)

Good luck!


Sort and Search Demo Program, version 1.0
(c) 2002, (your name)

Current list: (empty) (KNOWN to be ordered)

Actions:
   1.  Reset the current list from the keyboard
   2.  Reset the current list using randomly generated elements
   3.  Perform Bubble Sort on the current list
   4.  Perform Insertion Sort on the current list
   5.  Perform Selection Sort on the current list
   6.  Perform Linear Search on the current list
   7.  Perform Binary Search on the current list
   8.  Quit the program

Choose an action: 1

Resetting the current list from the keyboard.

Enter a series of elements, -1 to stop:  5 3 7 2 8 1 6 -1

Finished resetting, 7 elements entered.

Current list:  5 3 7 2 8 1 6 (NOT KNOWN to be ordered)

Actions:
   1.  Reset the current list from the keyboard
   2.  Reset the current list using randomly generated elements
   3.  Perform Bubble Sort on the current list
   4.  Perform Insertion Sort on the current list
   5.  Perform Selection Sort on the current list
   6.  Perform Linear Search on the current list
   7.  Perform Binary Search on the current list
   8.  Quit the program

Choose an action: 6

Performing Linear Search on the current list.

Enter a target element to search for: 8

The target was FOUND on the current list in position 4.

Theoretical search statistics:  7 element comparisons
Actual search statistics:       5 element comparisons

Finishing Linear Search.

Current list:  5 3 7 2 8 1 6 (NOT KNOWN to be ordered)

Actions:
   1.  Reset the current list from the keyboard
   2.  Reset the current list using randomly generated elements
   3.  Perform Bubble Sort on the current list
   4.  Perform Insertion Sort on the current list
   5.  Perform Selection Sort on the current list
   6.  Perform Linear Search on the current list
   7.  Perform Binary Search on the current list
   8.  Quit the program

Choose an action: 4

Performing Insertion Sort on the current list.

Theoretical sort statistics:  24 element comparisons, 73 element movements
Actual sort statistics:       19 element comparisons, 61 element movements

Finishing Insertion Sort.

Current list: 1 2 3 5 6 7 8 (KNOWN to be ordered)

Actions:
   1.  Reset the current list from the keyboard
   2.  Reset the current list using randomly generated elements
   3.  Perform Bubble Sort on the current list
   4.  Perform Insertion Sort on the current list
   5.  Perform Selection Sort on the current list
   6.  Perform Linear Search on the current list
   7.  Perform Binary Search on the current list
   8.  Quit the program

Choose an action: 8

Quitting Sort and Search Demo Program, version 1.0


Sort and Search Demo Program, version 1.0
(c) 2002, (your name)

Current list: (empty) (KNOWN to be ordered)

Actions:
   1.  Reset the current list from the keyboard
   2.  Reset the current list using randomly generated elements
   3.  Perform Bubble Sort on the current list
   4.  Perform Insertion Sort on the current list
   5.  Perform Selection Sort on the current list
   6.  Perform Linear Search on the current list
   7.  Perform Binary Search on the current list
   8.  Quit the program

Choose an action: 2

Resetting the current list using randomly generated elements.

Enter the desired number of elements (0 to 50): maybe
Response must be a whole number, try again: 51
Response must be between 0 and 50, try again: 5

Enter the lower limit of the range: 10
Enter the upper limit of the range: 30

Finished resetting, 5 elements between 10 and 30 randomly generated.

Current list:  15 22 11 26 17 (NOT KNOWN to be ordered)

Actions:
   1.  Reset the current list from the keyboard
   2.  Reset the current list using randomly generated elements
   3.  Perform Bubble Sort on the current list
   4.  Perform Insertion Sort on the current list
   5.  Perform Selection Sort on the current list
   6.  Perform Linear Search on the current list
   7.  Perform Binary Search on the current list
   8.  Quit the program

Choose an action: 7

Sorry, since the current list is not known to be ordered, the Binary Search
cannot be performed at this time.  Please sort the current list first.

Current list:  15 22 11 26 17 (NOT KNOWN to be ordered)

Actions:
   1.  Reset the current list from the keyboard
   2.  Reset the current list using randomly generated elements
   3.  Perform Bubble Sort on the current list
   4.  Perform Insertion Sort on the current list
   5.  Perform Selection Sort on the current list
   6.  Perform Linear Search on the current list
   7.  Perform Binary Search on the current list
   8.  Quit the program

Choose an action: 8

Quitting Sort and Search Demo Program, version 1.0