CSSE 120 -- Intro. to Software Development

Homework 12

  1. There is no new reading for the next session.
  2. There is no Angel quiz for the next session.
  3. You must do this assignment using Eclipse and the FirstSVNProject project that you checked out in class. Within that project, open the file NestedLoopsPatterns.py. It contains a template for the rest of this assignment.
  4. Deadline change: You will be granted a 24-hour extension, so this assignment is due Tuesday, not Monday. You will have an additional homework assigned on Monday, so you should attempt to complete this homework early.

  5. (2 points) Look at the function rectangleOfStars. Make sure you understand how it works. Ask for help if you're confused.
  6. (5 points) Based on rectangleOfStars, fill in code for the function triangleOfStars. This prints out a triangle-shaped grid of stars. For example, the code:
    triangleOfStars(6)
    
    should produce the output:
    *
    **
    ***
    ****
    *****
    ******
    

    The main() function already includes one call to triangleOfStars. Add at least two more test calls for it to main().

    After testing and debugging this function, commit your work to your Subversion repository. Do this by right-clicking on your FirstSVNProject in Eclipse and choosing Team → Commit.... Be sure to enter in a sensible log message as the course staff will review the messages.

  7. (5 points) Now make a function called triangleSameNumEachRow. This function will be like triangleOfStars, except each row shows its number, rather than asterisks. For example, the code:
    triangleSameNumEachRow(7)
    
    should produce the output:
    1
    22
    333
    4444
    55555
    666666
    7777777
    

    Add at least two more test calls for this function to main().

    After testing and debugging this function, commit your work to your Subversion repository. Be sure to enter in a sensible log message as the course staff will review the messages.

  8. (5 points) The next function, triangleAllNumsEachRow, is like triangleSameNumEachRow, except that each character is its position from the left, instead of from the top. For example:
    triangleAllNumsEachRow(6)
    
    should produce the output:
    1
    12
    123
    1234
    12345
    123456
    

    Add at least two more test calls for this function to main().

    After testing and debugging this function, commit your work to your Subversion repository using a sensible log message.

  9. (7 points) The next function, triangleNumsRightJustified, is like triangleSameNumEachRow (from problem 6, not the previous problem), except that the triangle is right-justified. For example:
    triangleNumsRightJustified(8)
    
    should produce the output:
           1
          22
         333
        4444
       55555
      666666
     7777777
    88888888
    

    Add at least two more test calls for this function to main().

    After testing and debugging this function, commit your work to your Subversion repository using a sensible log message.

  10. (10 points) The next function, triangleNumsCentered, is like triangleNumsRightJustified, except that the triangle is centered and includes spaces. For example:
    triangleNumsCentered(9)
    
    should produce the output:
            1 
           2 2 
          3 3 3 
         4 4 4 4 
        5 5 5 5 5 
       6 6 6 6 6 6 
      7 7 7 7 7 7 7 
     8 8 8 8 8 8 8 8 
    9 9 9 9 9 9 9 9 9 
    

    Add at least two more test calls for this function to main().

    After testing and debugging this function, commit your work to your Subversion repository using a sensible log message.

  11. (5 points) The next function, numbersConstantForward, takes three arguments: the number of rows, a maximum number to display, and a number of occurrences. The function displays a block of numbers. Each row should be identical and consist of the given number of occurrences of each number from 1 to the maximum number. For example:
    numbersConstantForward(4, 7, 3)
    
    should produce the output:
    111222333444555666777
    111222333444555666777
    111222333444555666777
    111222333444555666777
    

    Add at least two more test calls for this function to main().

    After testing and debugging this function, commit your work to your Subversion repository using a sensible log message.

  12. (6 points) The next function, numbersConstantBackward, is just like numbersConstantForward, except the numbers go from the maximum number down to one. For example:
    numbersConstantBackward(4, 7, 3)
    
    should produce the output:
    777666555444333222111
    777666555444333222111
    777666555444333222111
    777666555444333222111
    

    Add at least two more test calls for this function to main().

    After testing and debugging this function, commit your work to your Subversion repository using a sensible log message.

  13. (5 points) The next function, numbersIncreasingForward, also produces a block of numbers. But it takes just two arguments: the number of rows to print and the maximum number, n, to reach. Each row should be identical and consist of a single 1, a pair of 2's, and so on, up to n occurrences of the number n. For example:
    numbersIncreasingForward(5, 6)
    
    should produce the output:
    122333444455555666666
    122333444455555666666
    122333444455555666666
    122333444455555666666
    122333444455555666666
    

    Add at least two more test calls for this function to main().

    After testing and debugging this function, commit your work to your Subversion repository using a sensible log message.

  14. (10 points) The final function, triangularPyramid, uses nested loops with graphics, rather than printing text. The function takes a single argument, n, giving the height of a pyramid made of triangles. It should create an appropriately sized graphics window and draw a pyramid of triangles in the window. Each triangle should be the same size, with a single upright triangle in the top row, two in the second, and so on down to n upright triangles in the bottom row. (Hint: you don't need to draw the upside-down triangles explicitly.) You can choose how narrow you want your triangles to be, I chose the height to be half the width of the triangle. For example:
    triangularPyramid(9)
    

    could produce the output (color and thick lines optional):

    Include a getMouse() call at the end of your function so the graphics window is displayed long enough to be seen.

    Add at least two more test calls for this function to main().

  15. BONUS: (5 points) Decorate your pyramid with flags or poles. Hang them using loop patterns, of course. You could even hang photos (Zellegraphics accepts GIF format only) on the poles.
  16. Submit your code by committing the final version to your Subversion repository.