CSCI 261 - Programming Concepts (C++)Spring 2017 - Assignment 08 - Letter FrequencyQuick Links: Blackboard | Canvas | CS @ Mines | Cloud9 | Piazza | zyBooks |
|||||||||
| Home | Contact | Syllabus | Assignments | Schedule | Resources | | |||||||||
This assignment is due
by Tuesday, March 21, 2017 11:59pm.
ConceptsHave you ever finished a book and
wondered, "Geez, I wonder how many times the letter Q occurs in this
text?" No? This week's homework illustrates a fundamental use of the
array: storing related values in a single data structure, and then
using that data structure to reveal interesting facts about the data.
Now that you have some experience with
many fundamental programming tasks, it's time to test your mettle. Use
file I/O, functions, arrays, and loops together in one assignment to
create a program that displays a summary of data.
Program from what YOU KNOW
Did you know that most programs aren't well-designed? They really
aren't. Often, they're put together by geographically diverse people
with different styles, knowledge, programming ability and design taste.
But, the programs work. It's a freaky miracle, but they do
work.
When given a task in your engineering field that could be solved with
software, we do not expect you to be expert programmers (unless your
field is software engineering). However, we do expect you to
be able to assemble the things you know how to code into cohesive,
meaningful, useful programs.
You know how to open a file and read
data from it. You know how to declare and work with arrays. You know
that C++ can be your friend or your enemy. You know how to use a
framework to draw some simple graphics. You know how to conduct
repetitive tasks with loops. You know about data types.
Try to rely on these things that you know, before
over-complicating your own solution with things that you don't yet
know. This doesn't mean you shouldn't explore and learn more. You
should! Always! Until your last dying breath! But, start with what
you know first, and build from there.
ABCUF
Always Be Using Functions. Let that be a rule of thumb for the
remainder of the semester. When working on your programs, try to reach
an end result where
main
doesn't do much "low level stuff" but rather leverages functions in
order to do what your program needs to do.
For example, if you were to write a pizza-making program, don't write
one super-long, hard-to-read, scare-your-date-away implementation of
main
. Use functions:
int main() {
CreateShoppingList(); BuyIngredients(); GatherIngredientsInKitchen(); PourYourselfGlassOfFineChianti(); MakeDough(); MakaSauce(); //... CookPizza(); return 0; } InstructionsWrite a program that prints the
frequencies of letters that occur in the full text of Alice in
Wonderland.
Your program MUST:
When your program runs, it should create a file that looks
like this (but with the correct values):
a 2
b 3 c 1 d 3 e 6 f 77 g 2 h 23 i 34 j 4 k 24 l 15 m 235 n 45 o 23 p 23 q 24 r 24 s 24 t 24 u 24 v 24 w 24 x 55 y 45245 z 4 And when your program runs, it should display the following the user in the terminal (again with the correct values):
Most frequent letter: y
Least frequent letter: c HintsThis assigment isn't difficult if you
start early, ask questions, and do things one step at a time.
Do not just dive into the assignment. Create a mental
plan of what tasks your program needs to accomplish. Tackle the first
task (eg, "can I open the file ok?") and conduct a sanity check. Then
tackle the next task (eg, "can I read all the letters in the file, and
store the frequencies of each letter in an array?") and conduct another
sanity check. We strongly suggest writing your program (one step at a
time!)
As discussed above, we encourage you to Always Be Using Functions (ABCUF). However, there is
nothing wrong with doing all of your steps inside main at first
and then refactoring your work into functions later, once your program
is working.
Notice that you should use an array to store letter frequencies,
indexed from 0 - 25, with the frequencies of 'a' and 'A' stored in
frequencies[0] (and so on). There is an elegant way to increment the
occurance of a particular letter in the array. What is 'a' minus 97?
What is 'b' minus 97? Why subtract 97? (See the online ASCII Table.)
You could solve the problem of which
array index to increment with one VERY long switch statement. We do not
recommend this; there are far more elegant (and easier to code/debug)
solutions!
Grading Rubric
Your submission will be graded according to the following rubric.
Submission
Always, always, ALWAYS update the
header comments at the top of your main.cpp file. And if you ever get
stuck, remember that there is LOTS of help
available.
In summary, for homework due on
Tuesday, March 21 follow these specific steps:
This assignment is due
by Tuesday, March 21, 2017 11:59pm.
| |||||||||
Last Updated: 01/01/70 00:00
|