How to resolve the algorithm Letter frequency step by step in the Seed7 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Letter frequency step by step in the Seed7 programming language

Table of Contents

Problem Statement

Open a text file and count the occurrences of each letter. Some of these programs count all characters (including punctuation), but some only count letters A to Z.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Letter frequency step by step in the Seed7 programming language

Source code in the seed7 programming language

$ include "seed7_05.s7i";
 
const type: charHash is hash [char] integer;
 
const proc: main is func
  local
    var charHash: numberOfChars is charHash.EMPTY_HASH;
    var char: ch is ' ';
  begin
    ch := getc(IN);
    while ch <> EOF do
      if ch in numberOfChars then
        incr(numberOfChars[ch]);
      else
        numberOfChars @:= [ch] 1;
      end if;
      ch := getc(IN);
    end while;
    for ch range sort(keys(numberOfChars)) do
      writeln(ch <& " " <& numberOfChars[ch]);
    end for;
  end func;

  

You may also check:How to resolve the algorithm Stack step by step in the Batch File programming language
You may also check:How to resolve the algorithm Maze generation step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Kernighans large earthquake problem step by step in the Perl programming language
You may also check:How to resolve the algorithm Add a variable to a class instance at runtime step by step in the Logtalk programming language
You may also check:How to resolve the algorithm Floyd's triangle step by step in the Racket programming language