MODULE CountChars4; (* ========================================================================= Example GPCP .NET Console Program Count the number of occurrences of different categories of characters in a string using IF THEN ELSE statements Author : Chris Burrows Created: Jan 2007 (c) 2007-2008 CFB Software http://www.cfbsoftware.com/gpcp ========================================================================= *) IMPORT Out, CPmain; VAR i: INTEGER; PROCEDURE WriteCount(count: INTEGER; IN msg: ARRAY OF CHAR); BEGIN Out.Int(count, 3); Out.String(msg); Out.Ln() END WriteCount; PROCEDURE CountChars(IN s: ARRAY OF CHAR); VAR i, vowels, letters, capitals, digits, others: INTEGER; ch: CHAR; BEGIN Out.String(s); Out.Ln(); vowels := 0; letters := 0; capitals := 0; digits := 0; others := 0; FOR i := 0 TO LEN(s$) - 1 DO ch := s[i]; IF (ch >= 'a') & (ch <= 'z') THEN INC(letters); IF (ch = 'a') OR (ch = 'e') OR (ch = 'i') OR (ch = 'o') OR (ch = 'u') THEN INC(vowels) END ELSIF (ch >= 'A') & (ch <= 'Z') THEN INC(letters); INC(capitals); IF (ch = 'A') OR (ch = 'E') OR (ch = 'I') OR (ch = 'O') OR (ch = 'U') THEN INC(vowels) END ELSIF (ch >= '0') & (ch <= '9') THEN INC(digits) ELSE INC(others) END END; WriteCount(letters, ' letters'); WriteCount(capitals, ' capitals'); WriteCount(vowels, ' vowels'); WriteCount(letters - vowels, ' consonants'); WriteCount(digits, ' digits'); WriteCount(others, ' others'); Out.Ln() END CountChars; BEGIN CountChars('The quick brown fox jumped over the lazy dog.'); CountChars('Digit 1 looks like letter l, and digit 0 looks like letter O.') END CountChars4.