College Help 
Author Message
 College Help

PLease help me covert this program to one that will read as input a
sentence up to 150 characters long and then display it in reverse order
(the words only not the letters in the words).  I have started on what I
think could help and this is program #2.  PLease respond to

[ Classhlp.pas 1K ]
Program SoftArray (Input, Output);
CONST
     MaxValue = 10;
Type NumArray = Array [1..MaxValue] of INteger;
VAR
   A : NumArray;
   j, count: integer;

Procedure SelectSort (Var N: NumArray; MaxValue: Integer);
Var j, MinIndex, Afterj, temp : integer;

Begin {Select Sort}
      For j := 1 to MaxValue - 1 do
          Begin
               MinIndex := j;
          For Afterj := j to MaxValue do
          Begin
               If N[Afterj] = N[MinIndex] then
                  MinIndex := afterj
                  End; {For after j}
               If MinIndex <> j then
               Begin
                    Temp := N[j];
                    N[j] := N[MinIndex];
                    N[MinIndex] := temp
                    End; {for j}
                    End;
                    End; {Select Sort}
                    Begin {Soft Array}
                    Writeln ('Enter up to 10 integers on 1 line ending with 0');
                    Count := 1;
                    Repeat
                    Read (A[Count]);
                    Count := Count + 1
                    until (A[count - 1] = 0) or (Count > MaxValue);
                    SelectSort (A, count -2);
                    Writeln;
                    For j := 1 to count do
                    Write (A[j])
                    End. {Sort Array}

[ Program7.pas < 1K ]
Program ReverseSentence (Input, Output);
CONST
     StringSize = 150;
Type
IndexRange = 1..StringSize;
CharArray = Array [IndexRange] of Char;

VAR
   I : IndexRange;
   Sentence : CharArray;
   Begin
   for I := 1 to StringSize do
       Read (Sentence[I]);
       Readln;
       Write ('Enter sentence to be displayed in reverse');
       for I := 1 to StringSize do
           Write (Sentence[I]);
           Writeln
           End.



Wed, 18 Jun 1902 08:00:00 GMT  
 College Help


Wed, 18 Jun 1902 08:00:00 GMT  
 College Help

: PLease help me covert this program to one that will read as input a
: sentence up to 150 characters long and then display it in reverse order
: (the words only not the letters in the words).  I have started on what I
: think could help and this is program #2.  PLease respond to

I'm not going to respond to your email address because it is bad enough
that you are asking for help with *your* homework but you should also
expect me to mail it to you as well?  Feel fortunate that I am even doing
this for you.

I have removed your code because I have no idea what you were trying to
do.  I can see that some of your ideas were going the right way but you
were doing a lot more then you have to.  The general algorithm I am using
is this:

1) get the string[150]
2) step through the string one char at a time.  Each time you get to a
   char add it to the string[20] in the array of words.  If you encounter
   a space then it must be time for a new word.
3) Increment wordcount (array index value) and start making a new word.
4) print the array in reverse order.

Some notes about this:

This program is hardly robust.  It will only handle words up to 20
characters in length (it can be modified to the string type maximum) and
only handle sentences of 20 words in length (which can be modified as far
as memory constraints -- and maxint -- allow).  This is quick and dirty
but I believe it will work.

----begin code snipit----

Program ReverseSentence (Input, Output);

CONST StringSize = 150;

VAR in_string : string[StringSize];
    wordcount, eow : integer;
    wordarray : array[1..20] of string[20];

BEGIN
     wordcount := 1;

     write('Enter string: ');
     readln(in_string);

     for eow := 1 to length(in_string) do
     begin
          if (in_string[eow] = ' ') OR (eow = length(in_string)+1) then
             wordcount := wordcount + 1
          else wordarray[wordcount] := wordarray[wordcount] + in_string[eow]
     end; {of 'for' loop}

     while wordcount <> 0 do
     begin
          write(wordarray[wordcount], ' ');
          wordcount := wordcount - 1
     end
END.

----end code snippit----

I do sincerly hope you will have enough ethics to not use my code as it
is but instead read it, learn from it and consider your own solution(s)
to the problem.  Mine is very minimalistic and is just one of many ways
to do it.  If I were doing this for a class I would create a link list
based stack and push each word on then pop them all off.  It would take
some more code but the dynamic memory allocation would be less comsuming
(in non worse case situations) of resources, would allow for sentences of
varying word length and word count without creating (and wasting) space.  
I didn't want to get into that here because perhaps you haven't gotten to
the stack ADT would certainly be caught for some sort of cheating (which
this very definantly is - if you use any of my code).

So again I ask that this code be used only as a learning tool and not as
a solution to a very basic problem in a computer science course.  I, and
no one else on Usenet, will be out to hold your hand on the testing day
and no amount of code on Usenet will save your butt.

good day and good luck.

Robert

--
 .-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-.

 | Computer Science & Psychology - http://cobweb.cord.edu/horvick    [KaNiN] |
 `-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-.-_-'

For every credibility gap, there is a gullibility fill.
                -- R. Clopton



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. College Help PLease?

2. College needs help tpb7 where to put

3. help college student!

4. HELP A college student!

5. To all you college students out there!

6. College & Pascal

7. College Programs/Projects?

8. Pascal in College

9. online delphi college course - acredited

10. HELP HELP HELP HELP HELP HELP HELP HELP HELP HELP............

11. Lousy Palette - help, help, help, help, help...

12. HELP HELP HELP HELP!!!

 

 
Powered by phpBB® Forum Software