A5-Five Easy Functions

On This Page


Overview

There are three parts to this assignment:

  1. Review Exercises:

    First make sure you have completed and turned in the exercises from lesson 5. Then complete the exercises in CodeLab 5. These exercises will help prepare you for the problem-solving program and should be completed first. You can look at solutions if you miss your first attempt.

  2. Problem Solving Program:

    Complete the programming project following the Program Specifications listed below. You may make extra credit additions to this program as outlined in the section on Extra Credit.

  3. Tutorial Exercises:

    Complete the Tutorial Exercises in CodeLab 5 before the specified due date. Refer to the assigned reading for the next lesson to help you understand the problems. Also, you can use the online lecture notes for more information as the notes become available.

    In addition, type the program printime.cpp from the textbook on page 170 into a text editor, and then compile and run the program. In order to compile you will need to change the include file to use "ccc_time.cpp":

    #include "ccc_time.cpp"

    Submit your working source code file to Blackboard for grading using the file name printime.cpp. Note that on the Mac or a Linux system you will need to include the cccfiles for Time in the same directory to compile the code.

Program Specifications

Note that you must complete this program either by yourself or by working with one other student of this class following the rules of Pair Programming for Homework Assignments.

  1. Write a graphics application that uses the Turtle class to draw "artwork" consisting of 10 randomly created regular polygons and your initials.

    All of the shapes must be drawn more or less inside the graphics window.

  2. Define the five (5) required functions (shown below) in your turtlefun.cpp file and code at least one function call for each of the functions.

    Note that you must code these functions with the exact name shown. You may change parameters or add more functions but your source code must contain these functions with these names at a minimum.

  3. In the main() function, write a for loop that counts ten times. Within the loop, create a random number and use the random number to select which of the four shapes to call. (Hint: use if statements to select which function to call.)
  4. When calling the functions, create random floating-point numbers to specify the side length and location of each shape. Make sure each side length is not zero. All side lengths must be large enough that the type of shape is easily visible.
  5. After you draw the ten randomly selected, sized and positioned shapes, write your initials at the bottom-right corner of the window to "sign" your artwork.
  6. After drawing the "artwork", in the graphics window ask the user if they want to run again using the following message:
    Do you want to run again? (y/n)

    If the user enters a "y" then repeat the program. If the user enters any other letter, then exit the program using the statement: exit(0);.

  7. You must clear the window using the clear() function of your turtle before repeating the program.
  8. The name of the source code file must be turtlefun.cpp and all your code must be in this file.

    Be careful of the spelling, including capitalization, as you will lose points for a misspelled name.

  9. Remember to include a file comment block and follow all the other style rules we have covered so far, including no magic numbers.
  10. Submit your files to Blackboard as explained in the section of this document: What to Turn In.

Example Program

You can see an example of how the program operates by downloading and running the executable file: turtlefun.exe. Note that this example program may include some extra credit features.

Required Functions

/**
    Use the turtle to draw an equilateral triangle of
    the specified size.

    @param turtle The turtle to draw with.
    @param size The size of the sides of the triangle.
*/
void drawTriangle(Turtle& turtle, double size) { }

/**
    Use the turtle to draw a square of the specified
    size.

    @param turtle The turtle to draw with.
    @param size The size of the sides of the square.
*/
void drawSquare(Turtle& turtle, double size) { }

/**
    Use the turtle to draw a pentagon of the specified
    size.

    @param turtle The turtle to draw with.
    @param size The size of the sides of the pentagon.
*/
void drawPentagon(Turtle& turtle, double size) { }

/**
    Use the turtle to draw a hexagon of the specified
    size.

    @param turtle The turtle to draw with.
    @param size The size of the sides of the hexagon.
*/
void drawHexagon(Turtle& turtle, double size) { }

/**
    Use the turtle to draw my initials.

    @param turtle The turtle to draw with.
*/
void drawInitials(Turtle& turtle) { }

Extra Credit

The following are worth extra credit points:

  1. Complete the assignment using pair programming. (1 point)
  2. Add a function comment block for all functions. (1 point)
  3. Add a drawShape() function with the following declaration. Call this drawShape() function from each of the four functions that draw regular polygons. Also, allow additional shapes to be drawn up to at least 10 sides. You may change the parameters but must use this function name. (1 point for a correct function and one for using the function as specified)
    /**
        Use the turtle to draw a regular polygon of
        the specified size. Note: extra credit.
    
        @param turtle The turtle to draw with.
        @param size The size of the sides of the shape.
        @param sides The number of sides of the shape.
    */
    void drawShape(Turtle& turtle, double size, int sides) { }
    
  4. Write your code such that all the shapes are drawn entirely within the graphics window but still with random locations and side lengths. For this extra credit, you must have some shapes with sides of a length that is at least 20% of the window size. Thus, for the standard size graphics window, the sides of some shapes must be at least length 4. (3 points)

    Hint: See Radius of a regular polygon

Make certain that your README.txt file describes any extra credit attempted.

Grading Criteria

The instructor will evaluate your assignment using the following criteria. Each criteria represents a specific achievement of your assignment and has a scoring guide. The scoring guide explains the possible scores you can receive.

Some scoring guides have a list of indicators. These indicators are a sign of meeting, or a symptom of not meeting, the specific criterion. Note that a single indicator may not always be reliable or appropriate in a given context. However, as a group, they show the condition of meeting the criterion.

For information on grading policies, including interpretation of scores, see the course information page.

Lesson Exercises

  • 2: All lesson exercises attempted and turned in
  • 1: Some lesson exercises completed and turned in
  • 0: No lesson exercises completed or turned in

Program Compilation

  • 4: Source code compiles with no errors or warnings
  • 3: Source code compiles with 1 warning
  • 2: Source code compiles with 2 warnings
  • 1: Source code compiles with 3+ warnings
  • 0: Does not compile or wrong file turned in

Program Functionality

  • 10: Demonstrates mastery of the assignment
    • Applies concepts from the lessons appropriately
    • Meets all specifications (see above) with particularly elegant solutions
    • Runs to completion with no abnormal error conditions
    • Generates correct output given correct input
    • Behaves in a reasonable way in response to incorrect data
  • 8: Has all the functionality expected of the assignment
    • Demonstrates many techniques from the lesson
    • Attempts to meet all specifications (see above)
    • Implementation seems more complicated than necessary.
    • May have one minor error
  • 6: Has most of the functionality expected of the assignment
    • Demonstrates some techniques from the lesson
    • Attempts to meet all but one of the specifications (see above)
    • Implementation seems excessively complicated.
    • May have 2-3 minor errors
  • 4: Has some of the functionality expected of the assignment
    • Demonstrates some techniques from the lesson
    • Attempts to meet at least 1/2 of the specifications (see above)
    • Implementation seems excessively complicated.
    • May have more than 3 minor errors
  • 2: Serious functional problems but shows some effort and understanding
    • Attempts to meet less than 1/2 of the of the specifications (see above)
    • Has a major error or many minor errors
    • Implementation seems very convoluted
    • Demonstrates few techniques from the lesson
  • 0: Does not execute

Program Style

  • 4: Code is well-documented including:
    • Name, date, and program description in file comment block
    • Follows specified format for file comment block
    • Has a function comment block for all function declarations following the specified format
    • Proper use of spaces around operators
    • No tab characters are present in the source code
    • As described in How To Document and Organize C++ Code
    • Correct file name used
  • 3: Code has a minor documentation error
  • 2: Code has some documentation errors
  • 1: Code has many documentation errors
  • 0: No apparent attempt to follow documentation standards or write documentation comments

CodeLab and Other Tutorial Exercises

  • Number CodeLab completed correctly / number exercises * 8 and rounded up to the nearest integer.
  • -1 if the printime.cpp file does not compile
  • -2 if the printime.cpp file is not turned in

README.txt File

  • 2: README.txt file submitted following the instructions
  • 1: README.txt file submitted but some information was missing
  • 0: No README.txt file submitted

Total possible: 30, plus extra credit

What to Turn In

Submit your assignment to Blackboard, in the assignment folder that matches the name of this assignment, following the instructions for submitting homework. Include the following items for grading:

  1. README.txt file
  2. All the exercise files from Lesson 5
  3. turtlefun.cpp

You must submit all the files needed to complete your assignment. Your assignment must work as submitted.

You may assume that I have the turtle and graphics classes we discussed in class and you do not need to turn in the source code for those classes.

Home | Blackboard | Announcements | Day Schedule | Eve Schedule
Course info | Help | FAQ's | HowTo's | Links
Last Updated: April 01 2009 @17:08:53