CSSE 120 -- Intro. to Software Development

Homework 23

  1. Take a look at the Python vs C comparison document.  You may find this helpful as you try to do things in C that you already know how to do in Python.  Feel free to suggest things that we might add to this document.
  2. There is no Angel quiz for the next session.
  3. You must do this assignment using Eclipse and the CNestedLoops project that you checked out from your individual SVN repository in class.
    Be sure to check out that project into your Eclipse C workspace, not your Python workspace.  This will require connecting to the repository again in the new workspace,  using the SVN Repository Exploring perspective.
    Within that project, open the file NestedLoopsPatterns.c.
    It contains a template for the rest of this assignment.
    The output from most of the functions you are to write is similar (in some cases identical) to output from some of the Python functions that you wrote for Homework 11.  So the main purpose of the assignment is to get you accustomed to C syntax.  But there are also a couple of new challenges.
  4. Look at the function rectangleOfStars. Make sure you understand how it works. Ask for help if you're confused. Note that, unlike Python's print, C's printf does not automatically end the output line or put in extra spaces anywhere.

    Note: You may assume that the functions that print numbers will only be given one-digit numbers as their "highest number to print" actual parameters. numbers. Otherwise, some of the output formatting would be very tricky.
  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:
    *
    **
    ***
    ****
    *****
    ******
    

    After testing and debugging this function, commit your work to your Subversion repository. Do this by right-clicking on your CNestedLoops project 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
    

    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
    

    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, except that the triangle is right-justified. For example:
    triangleNumsRightJustified(8);
    
    should produce the output:
           1
          22
         333
        4444
       55555
      666666
     7777777
    88888888
    

    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 
    

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

  10. The next function, triangleOfStarsInBox, is like triangleNumsCentered, except the centered triangle contains stars, and is surounded by a box. For example:
    triangleOfStarsInBox(18);
    
    should produce the output:
    --------------------------------------
    |                 *                  |
    |                * *                 |
    |               * * *                |
    |              * * * *               |
    |             * * * * *              |
    |            * * * * * *             |
    |           * * * * * * *            |
    |          * * * * * * * *           |
    |         * * * * * * * * *          |
    |        * * * * * * * * * *         |
    |       * * * * * * * * * * *        |
    |      * * * * * * * * * * * *       |
    |     * * * * * * * * * * * * *      |
    |    * * * * * * * * * * * * * *     |
    |   * * * * * * * * * * * * * * *    |
    |  * * * * * * * * * * * * * * * *   |
    | * * * * * * * * * * * * * * * * *  |
    |* * * * * * * * * * * * * * * * * * |
    -------------------------------------- 
    

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

  11. The next function, numbersIncreasingForward, produces a block of numbers. It takes 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
    

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

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