Pyramids

In this lab you will write a program that prints "pyramids" of a size specified by the user. Here is a sample pyramid of size 5:

     5
    4 4 
   3 3 3
  2 2 2 2
 1 1 1 1 1  

The basic idea is that the ith row from the bottom row of a pyramid of size n consists of i instances of the number i, printed in a 2-character field. In addition, note that the ith row (0 for the bottom row, 1 for the row "on top" of the bottom row) from the bottom of a pyramid of size n is indented by i space characters.

Program specification:

Your program should prompt the user for the size of the pyramid. If the user enters a value greater than 20 or less than 0, the program should print and error message and ask the user to enter a proper value. Note that an input value of 0 results in no output. The basic structure of the remainder of your program will be an outer loop that iterates once for each row, and an inner loop that is responsible for printing one (the current, as specified by the outer loop) row.

Steps:

  1. Write pseudo-code to solve this problem. Have your lab instructor sign off on the pseudo-code in lab. Include it with the materials you hand in.
  2. Create a class, called Pyramid, that implements your pseudo-code. Test the program for various input values, including 5 and 12. Consider how your program should handle two-digit values in the pyramid.
  3. Modify your program so that it continues to prompt the user for a size, prints the corresponding pyramid, then prompts the user for another size until the user enters a negative size, at which point the program should terminate. You'll have to wrap the whole program in another loop, as well as modify the prompt and input handling code to deal correctly with negative input values.
  4. Hand in hard-copy of your program as well as a transcript of your programming printing pyramids of size 5 and 12. Submit the program electronically, as usual.