Board index » delphi » Pascal Problems

Pascal Problems

On 10 Jan 1997 09:22:44 GMT, "George Li" <georg...@ecs.school.net.hk>
wrote:

Quote
>Hi all :    
>    I want to use For-DO or While-Do to draw above picture.

>              *                     *****
>             **                      ****
>            ***                       ***
>           ****                        **
>          *****                         *
>           (a)                       (b)

These will probably not be easily done by one single while-do or
for-do loop.  Anyway, you want these in an equilateral triangle or a
right triangle?  In either case, I can't think of a way to do a signle
while or for loop.
 

Re:Pascal Problems


Hi all :        
        I want to use For-DO or While-Do to draw above picture.

              *                     *****
             **                      ****
            ***                       ***
           ****                        **
          *****                         *
           (a)                       (b)

If you can draw these picture (a) and (b) ,
Please E-mail for me .   georg...@ecs.school.net.hk
Thanks
                                                                George Li

Re:Pascal Problems


Quote
>  I want to use For-DO or While-Do to draw above picture.
>                                           ^^^^^ ???
>               *                     *****
>              **                      ****
>             ***                       ***
>            ****                        **
>           *****                         *
>            (a)                       (b)

> If you can draw these picture (a) and (b) ,
> Please E-mail for me

   I won't e-mail you, but yes, I can draw these pictures.  I sure can
do it - absolutely!  No problem-o... Any time I want, I'm able to do
such things...easily, too!  It's really easy, and I can do it, alrighty.
No problem to do it - this is one of the easier things I can do, as a
matter of fact.  Quite simple, actually.
   HOWEVER, I'm not going to do it FOR you, WHILE you're in school,
begging to get someone to do your homework FOR you - WHILE you sleep
through or otherwise blow off your classroom activities...  Nosiree!  I
mean, what possible benefit is it to US to do YOUR work - do we get YOUR
grade at the end of the semester?  Or are you going to let use date your
sister or mother?   Hmmmm?

Re:Pascal Problems


On 10 Jan 1997 09:22:44 GMT,  "George Li"

Quote
<georg...@ecs.school.net.hk> wrote:
>Hi all :    
>    I want to use For-DO or While-Do to draw above picture.

>              *                     *****
>             **                      ****
>            ***                       ***
>           ****                        **
>          *****                         *
>           (a)                       (b)

>If you can draw these picture (a) and (b) ,
>Please E-mail for me .   georg...@ecs.school.net.hk

With a closing statement like that I was sorely tempted to email
you saying nothing more than that I could do it!  Did you get
any responses like that?  I might like to have a little fun, but
I can't be quite that cruel.  :-D

I have a feeling I'm being suckered into doing your homework.
This surely can't be anything but a learning exercise. I hope
you take the time to think about the following solutions so that
you can get the creative juices flowing for you next lesson.  

Probably the easiest solution is to start with a full string and
modify one character on each iteration.  This is a relatively
simple solution that uses "one-step-at-a-time" type of strategy.
I'll do one, you do the other.

VAR i: Integer;
    s: String;
BEGIN
    s := '*****';
    For i := 1 to Length(s) Do Begin
       Writeln(s);
       s[i] := ' ';;
    End;

    { -- or -- }
    s := '*****';
    i := 1;
    While i < Length(s) Do Begin
       Writeln(s);
       s[1] := ' ';
       Inc(i);
    End;
END;

Of course you don't have to alter the string once it is
initialized.  This solution might be harder to visualize unless
you are familiar with copy function and aware that format
specifiers right justify.  But knowing this, it becomes a
relatively simple task:

    s := '*****';
    For i := 1 to Length(s) Do
       Write(Copy(s, 1, i):length(s));

And if the length of the string is to be specified at runtime:

    FillChar(s, *, Sizeof(s)); { fill entire string w/ *'s }
    s[0] := #255;              { make max length string }

    { I leave it to you to figure out how to             }
    { accept length from user and place into integer "j" }
    { and verify that "j" is within appropriate limits   }

    For i := 1 to j Do
       Write(Copy(s, 1, i):j);

I have provided you with a variety of solutions for "a", now you
need to work on "b".  I'll leave you with a hint to think about
what "downto" and subtraction could do for you.

BTW, I haven't tested any of this like I usually do, so I if
I've made a typo, syntax or logic error guess you'll have to
take it as part of your learning experience :-)

    ...red

Re:Pascal Problems


On 10 Jan 1997 09:22:44 GMT,  "George Li"

Quote
<georg...@ecs.school.net.hk> wrote:
>Hi all :    
>    I want to use For-DO or While-Do to draw above picture.

Sure, no problem:

for i:= 1 to 1 do writeln('Hi all :');

Bob Ferguson.

Re:Pascal Problems


Quote
> >       I want to use For-DO or While-Do to draw above picture.

> >              *                     *****
> >             **                      ****
> >            ***                       ***
> >           ****                        **
> >          *****                         *
> >           (a)                       (b)

> >If you can draw these picture (a) and (b) ,
> >Please E-mail for me .   georg...@ecs.school.net.hk

> With a closing statement like that I was sorely tempted to email
> you saying nothing more than that I could do it!  Did you get
> any responses like that?  I might like to have a little fun, but
> I can't be quite that cruel.  :-D

   I was...8<}}

Re:Pascal Problems


In article <32d39675.5932...@news.internetland.net> of Wed, 8 Jan 1997
12:45:31 in comp.lang.pascal.borland, Programmer Dude

Quote
<ggr...@internetland.net> wrote:
>On 10 Jan 1997 09:22:44 GMT, "George Li" <georg...@ecs.school.net.hk>
>wrote:

>>Hi all :      
>>      I want to use For-DO or While-Do to draw above picture.

>>              *                     *****
>>             **                      ****
>>            ***                       ***
>>           ****                        **
>>          *****                         *
>>           (a)                       (b)

>These will probably not be easily done by one single while-do or
>for-do loop.  Anyway, you want these in an equilateral triangle or a
>right triangle?  In either case, I can't think of a way to do a signle
>while or for loop.

No problem.

var j : integer ;
const P = 5 ; Q = 18 ;
begin ;
for J := 1 to P*Q do if (J mod Q)=0 then Writeln
  else if (J mod Q)+(J div Q)>Q-2 then Write('*') else Write(#32) ;
Readln ;
for J := 1 to P*Q do if (J mod Q)=0 then Writeln
  else if (J mod Q)-(J div Q)>=Q-P then Write('*') else Write(#32) ;
Readln end.

Conversion of a for loop to a while loop is trivial.

Anyone handing in such perverse code should of course expect negligible
credit.  It would be easy enough to remove the if .. then and even the
if .. then .. else, by using a suitable const A : array [boolean] of ...
--
John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk  Turnpike v1.12  MIME
    http://www.merlyn.demon.co.uk/
    My news-service has variable input backlog, currently 0-36 hours.

Other Threads