\documentstyle{report}

\pagestyle{myheadings}
\def\headlineaux{\sc Math 220/317: Programming II/Data Structures
\hrulefill
}
\markboth{\headlineaux}{\headlineaux}

\setlength{\textwidth}{6.25in}
\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}



\newcommand{\assignmentNumber}{2}
\newcommand{\outdate}{14 September, 1993}

\begin{document}
\begin{titlepage}\begin{centerline}{\Huge \framebox{Burt Rosenberg}}
\end{centerline}\end{titlepage}

\section*{Answer Set \assignmentNumber \hfill{\parbox{3in}
    {\small\sc\begin{flushright} Out: \outdate\end{flushright}}}}

\begin{verbatim}

program letFreq( input, output ) ;

{  program to count letter frequencies,
   and print a small histogram.
   burt rosenberg, 27 aug 93
   revised 14 sep 93
}

const
  infile = 'InFile.txt' ;

var
  a : array [0..25] of integer ;
  i, j : integer ;
  ch : char ;
  total, most : integer ;
  f : TEXT ;

begin

  { zero out array of letter counts.
    a[0] corresponds to 'a' and 'A',
    a[25] to 'z' and 'Z'. }
  for i := 0 to 25 do a[i] := 0 ;

  {open file and count letters}
  reset( f, inFile ) ;
  while (not eof(f)) do begin
    read(f, ch ) ;
    if (ch>='a') then i := ord(ch) - ord('a') {convert the upper case}
    else i := ord(ch) - ord('A') ;            {convert the lower case}
    if ((i>=0) and (i<=25)) then
      a[i] := a[i] + 1 ;
  end ;

  { write first line of output while collecting
   statistics, total number of letters and number of
   most frequent letter }
  total := 0 ;
  most := 0 ;
  writeln ;
  write(' ') ;
  for i := 0 to 25 do begin
     write(' ', chr(i+ ord('a')), ' ') ;
     if (most<a[i]) then most := a[i] ;
     total := total + a[i] ;
  end ;
  if total=0 then total := 1 ; {correct for empty text files}

  { write second line of output, percentage of
    each letter. }
  writeln ;
  for i := 0 to 25 do begin
     j := (100 * a[i]) div total ;
     write(j:3) ;
  end ;
  writeln ;

  { make historgram. Cycle to 1/10's putting an
    X if the letter's percentage exceeds that tenth. }
  for j := 0 to 9 do begin
    write(' ') ;
    for i := 0 to 25 do begin
      if ((10*a[i])>(j*most)) then write(' X ' ) 
      else write('   ') ;
    end ; 
    writeln ;
  end ; 

end.

\end{verbatim}

\newpage
Here is the output when {\em InFile.txt} is a file of
normal English text:
\begin{verbatim}
  a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v  w  x  y  z
  7  2  2  3 12  3  2  5  6  0  1  3  2  8  7  0  0  5  7  9  2  0  3  0  0  0
  X  X  X  X  X  X  X  X  X     X  X  X  X  X  X     X  X  X  X  X  X     X
  X  X  X  X  X  X  X  X  X     X  X  X  X  X        X  X  X  X     X
  X  X  X  X  X  X  X  X  X        X     X  X        X  X  X  X     X
  X        X  X        X  X        X     X  X        X  X  X        X
  X           X        X  X              X  X        X  X  X
  X           X           X              X  X           X  X
  X           X                          X  X           X  X
              X                                            X
              X
              X
\end{verbatim}

When {\em InText.txt} is the following encoded message:
\begin{verbatim}
pybio kbcdr opyvu csxkv sddvo dygxs
xdohk czbyz yconx kwocd ydros bvymk
vzycd yppsm oyxol iyxod rozyc dkvco
bfsmo botom dondr owkvv psxkv visxo
sqrdo oxrex nbonk xnosq rdidr oigby
dokps xkvpe bsyec voddo bdydr oboqs
yxkvz ycdwk cdobg sdrdr scmvy csxqp
bywxy gyxmy xcsno becxk wovoc ckxnc
ydroi nsnxk wovoc cdohk csckl yeddg
oxdiw svocx ybdrg ocdyp kecds xtecd
yppyp xkwov occby kn
\end{verbatim}
 
The output of {\em letFreq} is:
\begin{verbatim}
  a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v  w  x  y  z
  0  5  8 10  2  0  1  0  2  0  6  0  1  3 12  3  1  4  6  0  0  5  2  7  9  1
     X  X  X  X  X  X  X  X     X  X  X  X  X  X  X  X  X  X  X  X  X  X  X  X
     X  X  X  X     X     X     X     X  X  X  X     X  X        X  X  X  X  X
     X  X  X                    X        X  X  X     X  X        X     X  X
     X  X  X                    X           X        X  X        X     X  X
        X  X                    X           X           X        X     X  X
        X  X                    X           X           X              X  X
        X  X                                X                             X
           X                                X                             X
           X                                X
                                            X
\end{verbatim}

\end{document}

