Designing your own user interface and algorithms/code
Step 1: Do the 1st line of n *
Step 1.a Using a for loop, print the n * one at a time.
Step 1.b Advance to a new line by using print without ;
Step 2: Do the n - 2 inner lines
Step 2 restated:
For each line of the n - 2 "inner lines" do following
print (produce) one of the inner lines
(not the top, not the bottom) of the rectangle
Next line
Step 3: Do the last line of n *
-------------------------------------------------------------------------------
Step 2 restated again to show details of what happens in the loop
body....
For each line of the n - 2 lines do
2.a Print the 1st * (the left edge * for an inner row)
2.b Print the n - 2 spaces that are inside or between *
2.c Print the last or closing or right edge *
2.d Advance to the next line
Next line
How do you do step 2.b above? How can you print n - 2 spaces?
It is another loop, nested within the For each line loop.
------
Triangles and Rectangles
program hints and discussion
of how Top Down Development and StepWise refinement and Ghostbusters
VET SAT AUC and TVV SO YMDC fit in with the current task.
Your program will provide the following capabilities:
- Request a number greater than or equal to 3 from the user. Display
a hollow
rectangle of stars (asterisks) with each outer row and column
having that many stars. Using a fixed-width font such as Courier
New is essential. This causes the space and the * to have the
same width. Hollow rectangle
with 3 * for each outer row and column illustrated.
- Request an odd number and display a triangle similar to the one
shown here with the input number of stars in the top row on down
to the one star row for the last row. There will be an odd number
of stars in each row. Triangles for
row n = 9 and n = 3 shown.
- Request a word and print it out with all of its characters, then
with its last character missing,
then with its last two characters missing,
and so on until you print only its first two characters,
and finally print only its 1st character.
Dinosaur was the word
printed in this example.