copyright Steve J. Hodges   http://steveh.net/cs19/cs19-hw03.html

CS 19 Spring 2019

Assignment 3 (Codebreaker!)

Filename

decoder.cpp

Program Description

Your program will note if any command line parameters are present. In this assignment, you will read an unspecified number of lines of text from STDIN. Input is terminated with EOF (ctrl-D). When the input is completed, your program will print all of the input transformed as described below. The output will preserve the input except as described below (so for example, whitespace and punctuation will not be modified.) Your program must have no other output.

For this assignment, you may use vector or array containers. If you do any sorting, use either bubblesort or selectionsort, as described in class.

Text Transformation

Your program will find the frequency of each letter in input. Replace the 10 most frequently appearing letters with these letters (also in this order): E T A O I N S H R D. (so E replaces the most frequently appearing letter, T replaces the second most frequent letter etc.) Use as many letters as necessary if there are fewer than ten different letters in the input.

Letters that were replaced (as above) must be output in uppercase. Letters that were not replaced must be output in lowercase.

If your program recieved any command line parameters, letters that were not replaced (so letters that would normally have been output in lowercase) will be replaced with a hyphen/minus character '-' instead.

Sample Runs

Run #1

[steveh@pengo cpp]$ ./a.out <input1 >output1	
[steveh@pengo cpp]$ cat input1
South Ireland?
etAOIn, shrdLU.
etaoin shrdl!
To Sheridan!
"Thorasine"
I, Eao shunt?
et;aoins
O n e i t a
etAoi
to ae
tea?
et
E
[steveh@pengo cpp]$ cat output1
SOuTH IRElAND?
ETAOIN, SHRDlu.
ETAOIN SHRDl!
TO SHERIDAN!
"THORASINE"
I, EAO SHuNT?
ET;AOINS
O N E I T A
ETAOI
TO AE
TEA?
ET
E
[steveh@pengo cpp]$ 	

Run #2

[steveh@pengo cpp]$ ./a.out < input3
I
OO
AAA
TTTT
EEEEE
[steveh@pengo cpp]$ cat input3
A
BB
CCC
DDDD
EEEEE
[steveh@pengo cpp]$
	

Run #3

[steveh@pengo cpp]$ ./a.out - < input2.txt > output2.txt

FILES: input2.txt output2.txt


What to "turn in"

As usual, leave your .cpp file for this program ("decoder.cpp") in your home directory on pengo.