Lab 4-1

Due: Thu, Feb 20, 11:59pm

 

payrol

SORTING an ARRAY of STRINGS

Make necessary changes to to the sorting program 7.12 (pages 411-14 in the textbook, source code availabel in P drive) so that it sorts an array of names (strings) in dictionary order. We do not necessarily sort the names by first name or last name (the user may enter the names in any format). We simply sort the strings. Make sure that the following specifications and requirements are satisfied:

1. Use a global constant variable =20 for an upper bound on the size of the array to be sorted (assume that the size of the array will be at most 20)

2. Use a function to print the array in sorted order (also use a function to fill in the array)

3. Give the user option of entering (and sorting) as many sets of names as s/he wants (but no more than 20). You may either ask for the number of names to be entered beforehand, or ask the user to use a sentinel value (such as "end") to indicate the end of the input. Also give the user the option of entering new sets of names to sort before quitting the program.

4. Do not assume that the strings will be single words. So don't use cin >> to get the input. Instead, use the function getline.

5. Do not worry about changing the case of the letters (upper case vs lower case). You may assume that all names will be given in a standard form such as: Lionel Messi

Note: You may encounter the "mixing cin >> variable and getline" problem. See pages 468-9 of the textbook for the description and possible solutions to the problem. An easy fix is to have the statement cin.ignore( ); after every cin statement.

Grading Table

Requirement Points
Fulfillment of all requirements listed above 30
Correct sorting of data for all sets of input 60
Complete source code with good formatting, variable names, and comments 10
Total 100