|

_________________________________________________________________________________________

___________________
Welcome
to our website
{$P256,G256,B-,R+}
{ THIS PASCAL PROGRAM READS FROM A DOCUMENT AND PICKS OUT THE LETTERS A - Z. }
{ THEN IT COUNTS THE OCCURANCE OF EACH LETTER AND PRINTS OUT A }
{ HISTOGRAM REPRESENTING THE NUMBER OF OCCURANCES. IT ALSO PROVIDES }
{ A LETTER COUNT AND THE LEAST AND MOST OCCURED LETTERS ARE ALSO }
{ PROVIDED. }
program histary(input,output,infile,outfile);
const maxchar = 90;
star = '*';
type arytype = array['A'..'Z'] of integer;
var
letter : char;
list : arytype;
infile,outfile : text;
{************************************************************************}
function highchar(list : arytype) : char;
var lcv,highest : integer;
{ THIS FUNCTION FINDS THE MOST FREQUENTLY OCCURING LETTER. }
begin { HIGHCHAR }
highest := -maxint;
for lcv := 65 to 90 do
if list[chr(lcv)] > highest then
begin
highest := list[chr(lcv)];
highchar := chr(lcv); { STORES LATEST DATA }
end; { IF }
end; { HIGHCHAR }
{************************************************************************}
function lowchar(list : arytype) : char;
var lcv,lowest : integer;
{ THIS FUNCTION FINDS THE LEAST OCCURING LETTER. }
begin { LOWCHAR }
lowest := maxint;
for lcv := 65 to 90 do
if list[chr(lcv)] < lowest then
begin
lowest := list[chr(lcv)];
lowchar := chr(lcv);
end; { IF }
end; { LOWCHAR }
{************************************************************************}
function array_sum(list : arytype) : integer;
var sum,lcv : integer;
{ THIS FUNCTION COUNTS HOW MANY LETTERS WERE READ. }
begin { ARRAY_SUM }
sum := 0;
for lcv := 65 to 90 do
if list[chr(lcv)] <> 65 then
sum := sum + list[chr(lcv)];
array_sum := sum;
end; { ARRAY_SUM }
{************************************************************************}
procedure zerofreq(var list : arytype; maxchar : integer);
var lcv : integer;
{ THIS PROCEDURE ZEROS OUT THE ARRAY. }
begin { ZEROFREQ }
for lcv := 65 to maxchar do
list[chr(lcv)] := 0;
end; { ZEROFREQ }
{************************************************************************}
procedure histogram(list : arytype; maxchar : integer;
star : char; var histfile : text);
var i,count,lcv : integer;
{ THIS PROCEDURE PRINTS OUT THE NUMBER OF LETTERS FOUND.}
begin { histogram }
for lcv := 65 to 90 do
begin { FOR }
count := 0;
if list[chr(lcv)] <> 65 then
write(histfile,chr(lcv),':');
count := list[chr(lcv)] div 5;
for i := 1 to count do
write(histfile,star);
writeln(histfile);
end; { FOR }
writeln(histfile);
writeln(histfile,' SCALE : * = 5 OCCURANCES. ');
writeln(histfile);
end; { HISTOGRAM }
{************************************************************************}
procedure read_file(var inred,outrite : text;var ch : char;
var list : arytype);
{ THIS PROCEDURE READS IN THE LETTERS AND STORES THEM IN THE ARRAY }
{ AND COUNTS UP THE OCCURANCES OF EACH LETTER. }
begin { READ_FILE }
read(inred,ch);
ch := upcase(ch);
if (ch >= 'A') and (ch <= 'Z') then
list[ch] := list[ch] + 1;
end; { READ_FILE }
{***********************************************************************}
begin { MAIN }
assign(infile,'LAB8.DOC');
assign(outfile,'PRN');
reset(infile);
rewrite(outfile);
zerofreq(list,maxchar);
while not eof(infile) do
read_file(infile,outfile,letter,list);
histogram(list,maxchar,star,outfile);
writeln(outfile,' TOTAL LETTER COUNT : ',array_sum(list));
writeln(outfile);
write(outfile,' THE MOST FREQUENTLY OCCURING LETTER IS ');
writeln(outfile,highchar(list));
writeln(outfile);
write(outfile,' THE LEAST FREQUENTLY OCCURING LETTER IS ');
writeln(outfile,lowchar(list));
close(outfile);
close(infile)
end. { MAIN }
_________________________________________________________________________________________
About
Us
Content
provided by VirtualeCorporation
GeminiSoftwareSystems
GeminiMalls GeminiMagazine
TradeLinks
VirtualeCatalog
VirtualeCorporation
VirtualeDirectory
VirtualeJobs VirtualeMedia
VirtualeOffices
_______________________________________________________________________________________
Give to Charities Click
Here!
Michael J. Fox Parkinson's Website Click
Here!
__________________________________________
Software
including hosting, websites, graphics, development, office, security..Click
Here!
________________________________________________________________________________________

Buy Online at Autodesk
"Internet Security Systems' BlackICE Protection Products"
Need to create a business plan now? Get OfficeReady Business Plans
Kaspersky Anti-Virus Products
Free Shipping when you spend $100 on Macromedia.com
Convert paper and PDF into Documents you can edit, share and archive - Buy OmniPage Pro from ScanSoft.
Broderbund Bargain Bin - All Titles Under $9.99! Plus FREE shipping with orders over $20!
_____________________

|