Solved

Compute the average length of sentences?

Posted on 2002-03-08
5
196 Views
Last Modified: 2010-08-05
I am not familiar when dealing with file in pascal.The question is how do I construct a program that reads a file containing a love letter or something familiar and computes the avarege length of sentences in it.Sentences are terminated by '.'(full stop).The length of a sentence is defined to be the number of words in it.Words in sentences are separated by at least a ' '(space).

This is how far I can go.I use Pascal 7.0

Program Average;
var
 inputdata:text;
 word:string;
count:integer;
 
begin
Assign(inputdata,'A:Newrec.dat')
reset(inputdata);
while not seekEOF (inputdata) do
begin
count:=count +1;
.....
....
End.

0
Comment
Question by:ktpule
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 49

Expert Comment

by:dbrunton
ID: 6851322


Roughly the code should be

var
 count : integer;
 words : integer;
 character : char;
 fullstops : integer;

count := 0;
fullstops := 0;
words := 0;
while not eof (inputdata) do
begin
read(inputdata, character);
inc(count);
if character = '.' then
 inc(fullstops);
if character = ' ' then
 inc(words);
end;


That'll give you the number of words, number of fullstops (sentences), and number of characters.  And you can do the average calculations from that info.  Code still needs tidying up because there can be strange combos in there but that's enough to get you started.
0
 
LVL 1

Expert Comment

by:Shivshankar
ID: 6856551
I'll modify the program given by dbrunton a bit so that if there are multiple spaces between words, it should'nt count more.

var
  count : integer;
  words : integer;
  character : char;
  fullstops : integer;
  prevchar : char;
begin
  count := 0;
  fullstops := 0;
  words := 0;
  prevchar := Chr(0);
  Assign(inputdata,'A:Newrec.dat')
  reset(inputdata);
  while not eof (inputdata) do
  begin
    read(inputdata, character);
    inc(count);
    if character = '.' then
      inc(fullstops);
    if character = ' ' and prevchar <> ' ' then
      inc(words);
    prevchar = character;
  end;

And change the assignment of Words:= 0; to words:= 1;

If not even 1 character is read from inputdata, then decrement words by 1. That should do.

Hope this helps.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6858502
You have asked 11 questions at this site and NEVER closed/awarded any of them.  ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.

Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you. You must tell the participants why you wish to do this, and allow for Expert response.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question. Again, please comment to advise the other participants why you wish to do this.

For special handling needs, please post a zero point question in the link below and include the question QID/link(s) that it regards.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Please click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE Pro user, use the Power Search option to find them.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20186611.html
http://www.experts-exchange.com/questions/Q.20188338.html
http://www.experts-exchange.com/questions/Q.20253034.html
http://www.experts-exchange.com/questions/Q.20253103.html
http://www.experts-exchange.com/questions/Q.20253032.html
http://www.experts-exchange.com/questions/Q.20254643.html
http://www.experts-exchange.com/questions/Q.20274803.html
http://www.experts-exchange.com/questions/Q.20275020.html
http://www.experts-exchange.com/questions/Q.20275204.html


To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20194313.html
http://www.experts-exchange.com/questions/Q.20275908.html

PLEASE DO NOT AWARD THE POINTS TO ME.  
 
------------>  EXPERTS:  Please leave any comments regarding your closing recommendations if this item remains inactive another seven (7) days.  Also, if you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange

P.S.  For any year 2000 questions, special attention is needed to ensure the first correct response is awarded, since they are not in the comment date order, but rather in Member ID order.
0
 
LVL 49

Expert Comment

by:dbrunton
ID: 6884872
PAQ and zero points this one.
0
 
LVL 1

Accepted Solution

by:
Moondancer earned 0 total points
ID: 6897982
Thank you, dbrunton.  100 points refunded, moved to PAQ at zero to close.
Moondancer - EE Moderator
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With the rising number of cyber attacks in recent years, keeping your personal data safe has become more important than ever. The tips outlined in this article will help you keep your identitfy safe.
Part One of the two-part Q&A series with MalwareTech.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question