Re: Exercise from C++ How to program Cyber classroom 4th ed.
From: Dan Cernat (dcernat_at_excite.com)
Date: 01/07/04
- Next message: wenmang: "cast pointer to different type, what is the impact?"
- Previous message: tom_usenet: "Re: possibility to forbid use of "this"?"
- In reply to: John Carson: "Re: Exercise from C++ How to program Cyber classroom 4th ed."
- Next in thread: jbruno4000: "Re: Exercise from C++ How to program Cyber classroom 4th ed."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 7 Jan 2004 06:20:39 -0800
"John Carson" <donaldquixote@datafast.net.au> wrote in message news:<3ffbe237$1@usenet.per.paradox.net.au>...
> "Bruce Lee 646" <brucelee646@aol.com> wrote in message
> news:20040107051345.01665.00002513@mb-m18.aol.com
> > Write a program that reads in the size of the side of a square and
> > then prints a hollow square of that size out of asterisks and blanks.
> > Your program should work for squares of all side sizes between 1 and
> > 20. For example, if your program reads a size of 5, it should print
> >
> > *****
> > * *
> > * *
> > * *
> > *****
> >
> >
> > Am I supposed to type all of the possible outputs between 1 and 20
> > and use a selection structure to choose which one? That's the only
> > thing I can think of. is there another way?
>
>
> You type out the outputs for n==1 and n==2. For n>2, you can construct the
> square on the spot. Just divide up the square into its component lines:
>
> Line 1: n asterisks.
> Lines 2 to n-1: a left asterisk, followed by n-2 spaces followed by a right
> asterisk.
> Line n: n asterisks.
Your algorithm above works fine for n == 1 and n == 2. One should not
have a special case for those situations.
- Next message: wenmang: "cast pointer to different type, what is the impact?"
- Previous message: tom_usenet: "Re: possibility to forbid use of "this"?"
- In reply to: John Carson: "Re: Exercise from C++ How to program Cyber classroom 4th ed."
- Next in thread: jbruno4000: "Re: Exercise from C++ How to program Cyber classroom 4th ed."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|