Function Prototypes, Functions with Values and Addresses, Arrays
Project: Uninterpretable Dance
Working in pairs, students should develop a program which makes the robot perform a randomized dance. That is, the program should have these features.
-
The program should contain at least five dance functions, each of which instructs the robot to follow a different sequence of activities (beeps and movements) in a dance pattern.
-
The main function should make at least five calls at random to the five movement functions. The functions should be executed in a different random order each time the program is run.
-
The program need not ensure that each function is called at least once for any single run of the program, but all functions should have an equal probability of being called in each program execution.
-
The program must have:
- no global variables,
- function prototypes for all functions (the function bodies should all appear after the main program),
- at least one dance function with an array parameter,
- at least one dance function to which a value is passed as a parameter, and
-
at least one dance function to which a pointer is passed as a parameter
which is not an array.
- The function which uses the pointer parameter should modify the value in a significant way within the function.
- The function which calls this function with a pointer parameter should then be effected by the change of that variable.
-
Well-written code should should be easy to read, understand, and modify; and the code should run efficiently. In the context of this project, therefore, your program should have these characteristics:
-
There should be no redundant or unused code. For example,
- If a code segment is repeated several places, consider collecting the code in a procedure that is called as needed.
- If the same statements are repeated several times in a row, consider placing one copy of the statements in a loop.
-
The code should be formatted to be easily readable. For example,
- Each procedure should have comments that describe what the procedure does (including any pre- and post-conditions).
- Comments should outline the main sections within a procedure. (It is distracting for a comment to simply repeat what the code does, but it is helpful to have a high-level comment that describes the idea behind a section of code.)
- Variable names should be descriptive. (Use variable names b1, b2, etc. only for vitamins.)
- Formatting/indenting should clarify the structure of the programs. (For example, indent consistently with in a loop and within conditional statements.)
-
The code should also be reasonably efficient. For example,
- If variables i and j always have the same value, then one could be used throughout and the other discarded.
- If a value can be computed directly, do not use a loop. (No need to count 1 by 1 to ten, if one can simply make the assignment value = 10.)
- If logic seems particularly complex for one section of code, consider if there is a simpler way.
-
Grading
created 19 July 2011 by Dilan Ustek full revision 26 July 2011 by Dilan Ustek full revision 14 October 2011 by Henry M. Walker revised 30 October 2011 by Erik Opavsky revised 26 August 2012 by Henry M. Walker dates updated 1 September 2012, 31 December 2012, 14 August 2013, 21 September 2013 by Henry M. Walker modest lab restructuring 25 September 2013 by Henry M. Walker complete reorganization of module 26 January 2014 by Henry M. Walker project clarified 17 March 2014 by Henry M. Walker wording refined for passing values and addresses as parameters 21 September 2014 by Henry M. Walker> dates updated 14 January 2015 by Henry M. Walker reformatting and minor editing 8 August 2016 by Henry M. Walker |
![]() ![]() |
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu. |