Sei sulla pagina 1di 5

CMPSC 121.

1
Sort Program
Monday 04/25/2011
Due in Handin Folder anytime Wednesday 5/4/2011
Hardcopy due: Anytime Thursday 5/5/2011

Name: Grade:
1
Date:
1
Permission to post?  yes  no
I may post your assignment on the class disk, but only if you check yes.

Status:
sortv1 (60):  Complete, no issues  Unresolved Issues2  Not Attempted
sortv2 (10):  Complete, no issues  Unresolved Issues2  Not Attempted
sortv3 (10):  Complete, no issues  Unresolved Issues2  Not Attempted
sortv4 (10):  Complete, no issues  Unresolved Issues2  Not Attempted
sortv5 (10):  Complete, no issues  Unresolved Issues2  Not Attempted
*sortv6 (10):  Complete, no issues  Unresolved Issues2  Not Attempted

2
Description of Unresolved Issues:

1
The purpose of this assignment is to read in a list of words and display reports
showing the words and their lengths in alphabetic order and in order by length. You
are also to display the length of the shortest word, the length of the longest word,
the average word length and a table showing how many words there are of each
length.

The files for this problem can be found in …/121/assignments/programs/sort


The main program is called sort.cpp and the functions are in arrays.h

sortv1: (60pts) Build the word and length arrays from “v:\words.txt”

Write a program which reads the contents of words.txt, one word at a time into an
array of strings. As you do this, store the length of each word in a parallel array of
ints. When you have finished reading in all the words, call the displayReport()
function to display the words and their lengths.

Functions to complete for part 1: getData() and displayReport().


Here is a sample report:
Words and Word Lengths Before Any Sorting
WORD LENGTH
freshman 8
sophomore 9
junior 6
senior 6
school 6
grade 5
point 5
average 7
Pentium 7
computer 8
science 8
software 8
engineering 11

2
sortv2: (20pts) Determine the minimum, maximum, and average lengths

Complete min(), max(), sum(), and average() functions and use them to determine
the shortest, longest, and average word length.

Functions to complete for part2: min(), max(), sum(), average(), displayStats()


Here is a sample report:
<same report as above>
Statistics for Word Length:
Length of Shortest Word: 5
Average Length of Word: 7.23
Length of Longest Word: 11

sortv3: (10pts) Sort the words alphabetically and by length

Use the generic sort() function to sort:

1. sort the words alphabetically


2. sort the words by ascending length

Call the displayReaport() function after each sort. Be sure to give the report an
appropriate title.

Functions to complete for part 3: We will write the sort() function in class.
Here are sample reports:
Words and Word Lengths Sorted Alphabetically by Word
WORD LENGTH
average 7
computer 8
engineering 11
freshman 8
grade 5
junior 6
Pentium 7
point 5
science 8
school 6
senior 6
software 8
sophomore 9

3
Words and Word Lengths Sorted by Length
WORD LENGTH
grade 5
point 5
junior 6
senior 6
school 6
average 7
Pentium 7
computer 8
science 8
software 8
freshman 8
sophomore 9
engineering 11

(Note: your word order for a given length may be different)

sortv4: (10pts) Get file name from user

Modify the program so that the user enters the name of the word file and the
program opens it from the some folder the program is in.

Here are other word files you can try:

words.txt hangman.txt, dict.dat

sortv5: (10pts) Build a “frequency distribution” of word lengths

Add a frequency distribution to the statistics report. The frequency distribution


should show each word length and how many words were that long. This can be done
using an array of counters as will be shown in class.

Here is a sample report:


<same report as above>
Word Length Frequency Distribution
LENGTH COUNT
5 2
6 3
7 2
8 4
9 1
11 1

4
*sortv6: (10pts extra) Process files containing multiples of some words

Modify the program so that it can process a file with multiple occurrences of some
of the words. The program should keep track of how many times each word occurs
but only store it once in the array(Hint: use a linear search to look for the word, if
you fin it, increment its count, if you don’t, store it in the array with a count of 1).
The program will also have to strip off punctuation and convert to all upper or all
lower case. Modify the sort() and the displayReport() to handle the array of word
counts. Add statistics for the word counts like you have for the word lengths.

You can use the quote.txt file as the input for this part.

Potrebbero piacerti anche