This program should let me type a Path and file name, then it
should read the file for the following:
A. Number of words
B. Average word length
C. Percentage of vowels
C. Frequency count (i.e. No. of 'A' ********
'B' ****
.
etc. etc
.
'Z' ****************
and then write the result on to a file called wordout.txt.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
I HAVE TWO PROBLEMS
1. When I write the path and file name the program says it
can't find the file, but it works if I hard-code it in the
program-Assign(Infile,'Dir\file').
Q. What am I doing wrong?
2. The part of the program that write the result of the array
to wordout.txt don't work. It also said it can't close the file as
it not open.
Q. What am I doing wrong?
Below, I have grouped the area where I think things are not right.
THANKS FRIENDS.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
program Textfile;{Input,Output text}
Type
AtoZ = array ['A'..'Z'] of Integer;
var
Store : AtoZ ;
InFile,OutFile : Text;
CountWord,Countletter, Star : Integer;
AvWordLength : Real;
ch : char;
AVowelPercent : Real;
EVowelPercent : Real;
IVowelPercent : Real;
OVowelPercent : Real;
UVowelPercent : Real;
StartofWord : Boolean;
Filename : string;
procedure ProcessCharacter;
begin
If ch in ['A'..'Z','0'..'9'] then {}
begin
If not StartofWord then
begin
Store[ch] := Store[ch] + 1;
Countletter := Countletter + 1;
end
end;
end; {processcharacter}
procedure ProcessWord;
begin
If ch in ['A'..'Z','0'..'9'] then {}
begin
If not StartofWord then
begin
CountWord := CountWord + 1;
StartofWord := true;
end
end
end;
procedure DoStats;
begin
AvWordLength := Countletter / CountWord;
AVowelPercent := Store['A'] / CountLetter * 100;
EVowelPercent := Store['E'] / CountLetter * 100;
IVowelPercent := Store['I'] / CountLetter * 100;
OVowelPercent := Store['O'] / CountLetter * 100;
UVowelPercent := Store['U'] / CountLetter * 100;
end;
procedure DoResults;
begin
Assign(OutFile,'a:\WordOut.TxT');
Rewrite(OutFile);
writeln(OutFile, 'Number of words ', CountWord);
writeln(OutFile,'Average word length ', AvWordLength:5:3,'
Characters');
writeln(OutFile,'A ',AVowelPercent:5:3,'%');
writeln(OutFile,'E ',EVowelPercent:5:3,'%');
writeln(OutFile,'I ',IVowelPercent:5:3,'%');
writeln(OutFile,'O ',OVowelPercent:5:3,'%');
writeln(OutFile,'U ',UVowelPercent:5:3,'%');
(1)
*************************************************************
For ch := 'A' to 'Z' do
Begin
Write(ch,store[ch]);
If store[ch] < 75 then
Begin
For Star := 1 to Store[ch] do
Write(OutFile,' *');
End {if}
Else
Begin
For Star := 1 to 75 do
Write(OutFile,' *');
Writeln(OutFile,'. . .');
End; {else}
close(outFile);
End; {for}
end;
*********************************************************
Begin {Main program}
CountWord := 0;
CountLetter := 0;
AvWordLength := 0;
AVowelPercent := 0;
EVowelPercent := 0;
IVowelPercent := 0;
OVowelPercent := 0;
UVowelPercent := 0;
StartofWord := False;
(2)
**************************************************************
Writeln('Please type file name and press return=>');
Read(Filename);
Assign(InFile,'Filename');
Reset(InFile);
***********************************************************
While not eof (InFile) do
Begin
Read(InFile,ch);
ch := upcase(ch);
ProcessCharacter;
ProcessWord;
end;
Close(InFile);
DoStats;
DoResults;
End.