CSSE 120 -- Intro. to Software Development

Homework 11

  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. Look at the function rectangleOfStars. Make sure you understand how it works. Ask for help if you're confused.
  5. 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.

  6. 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.

  7. 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.

  8. 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.

  9. 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.

  10. 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.

  11. 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.

  12. 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.

  13. The final function, brickPyramid, uses nested loops with graphics, rather than printing text. The function takes a single argument, n, giving the height of a pyramid of rectangles. It should create an appropriately sized graphics window and draw a pyramid of rectangles in the window. Each rectangle should be the same size, with a single rectangle in the top row, two in the second, and so on down to n rectangles in the bottom row. For example:
    brickPyramid(9)
    

    should produce the output:

    Include a sleep time or 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().

  14. Submit your code by committing the final version to your Subversion repository.