Solved

Compute the average length of sentences?

Posted on 2002-03-08
5
188 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
  • 2
  • 2
5 Comments
 
LVL 47

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 47

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

A Short Story about the Best File Recovery Software – Acronis True Image 2017
Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now