Lab 6: Vectors/arrays
- Due No Due Date
- Points 1
Note: You are encouraged to work on the following with a partner.
Overview
In this lab, you'll practice using arrays and vectors.
Learning outcomes
By the end of this lab, you should be more comfortable...
- using vectors and arrays to store lists of data
- iterating over lists of data using loops
- performing actions on selective items in a list using branches
- using parallel (multiple) vectors/arrays
Exercises
Complete the following zyLabs in the zyBook. While you do them, be sure to implement incrementally—write a line or two of code, then compile/run it. Test frequently by clicking "Submit mode" and then "Submit for grading". You have unlimited submits, so don't worry about using some quota up.
- zyLab 4.24: Print string in reverse
- zyLab 5.18: Output numbers in reverse
- zyLab 5.22: Word frequencies
- zyLab 5.25: Two smallest numbers
Submitting
Click "Submit mode" then "Submit for grading" when you are finished so I can see that you have done the zyLab.
PA options
Please see the syllabus and course schedule (both on the homepage) for more information about how many programming assignments you are required to pass, due dates, etc. Of note: you do not need to attempt every or even most PAs.
PA 6.1 (Advanced): Word stats
Write a program that reads in text from the user until they enter the word END, then reports several stats about their text. Specifically, it should report:
- the number of total words entered
- the number of distinct words (case insensitive)
- the number of characters (the length of all input words summed together)
- the distribution of distinct words and their corresponding counts represented as a "bar graph" of characters (see the example)
You should use parallel (multiple) vectors or arrays to keep track of distinct words and their frequencies. For distinct words, use the `tolower()` function described in zyBook chapter 3.14 Character operations. You'll need to apply this to each character in an input word. For showing the word distributions as bar graphs, use `setw`, as described in zyBook chapter 9.2 (and detailed in Table 9.2.2), to set the width of the word to something reasonable (e.g., 15 or 20).
Here's a run of a program that meets these criteria (your output doesn't have to look exactly the same as long as it has the same information and your formatting is good). User input is shown in bold orange.
$ ./word-stats
==== WORD STATS ====
Enter your text and enter END (all caps) when you're finished:
Mary had a little LAMB
little lamb
little lamb
Mary had a little lamb whose fleece was white as snow END
Stats:
words: 20
distinct words: 10
characters: 81
Distribution:
mary XX
had XX
a XX
little XXXX
lamb XXXX
whose X
fleece X
was X
white X
as X
snow X
// Name:
// Date:
// Partner:
//
// Specifications checklist for PA Option 6.1 (Advanced)
// [ ] the header includes your name and anyone you worked with
// [ ] the header includes this specifications checklist
// [ ] the code in indented properly (use the autoformatter if you're not sure)
// [ ] useful comments are present above chunks of code that "hang together" (work toward a higher level goal)
// [ ] the identifiers are well named
// [ ] the program compiles
// [ ] the program runs without crashing
// [ ] all output and prompts look clean (correct spelling, capitalization, nothing squished)
// [ ] the program prompts the user for their text
// [ ] all words entered by the user are read in until the sentinel END is read in
// [ ] the END sentinel is not used in any of the stats
// [ ] the program uses parallel (multiple) arrays or vectors to store words and their counts
// [ ] words are stored and reported at the end in all lower case
// [ ] these stats are displayed at the end and are accurate:
// [ ] the number of total words entered
// [ ] the number of distinct words (case insensitive)
// [ ] the number of characters (the length of all input words summed together)
// [ ] the distribution of distinct words and their corresponding counts represented as a bar graph
// [ ] the left side of the bar graphs are aligned across words
Submit your PA to First programming assignment, Second programming assignment, Third programming assignment, or Fourth programming assignment based on whether this is your first, second, third, or forth PA. If you are working with a partner, both of you must submit individually.
Rubric
Criteria | Ratings | ||
---|---|---|---|
Worked diligently on the lab problems
|
|
||
Submitted all materials according to the instructions
|
|
||
|