Programming Summary (version 6.0.x/UNIX) |
-Primitive Procedures 1) TurnOn(); Karel is initialized. 2) Move(); Karel moves one block forward. 3) TurnLeft(); Karel pivots 90 degrees to left. 4) PickBeeper(); Karel removes a beeper from corner. 5) PutBeeper(); Karel places a beeper on corner. 6) TurnOff(); Karel turns off. -Specifying a Complete Program 7) // olaNNN BY student name, CSCI 2170-sec, ... // PROGRAM ID: source-name.cpp / one-line description // AUTHOR: student name // INSTALLATION: MTSU // REMARKS: short description and comments // . . . #include <karel.h> using namespace std; int main() { TurnOn(); ...your Karel statements here... TurnOff(); } -The Mechanism for Defining New Function Procedures 8) void IDENTIFIER() { ...your Karel statements here... } where the IDENTIFIER consists of the following characters: A-Z, a-z, 0-9, and underscore. The IDENTIFIER cannot contain any blanks and must begin with an alphabetic letter. -The Predicates for Testing the Environment 9) SIGHT: frontIsClear frontIsBlocked leftIsClear leftIsBlocked rightIsClear rightIsBlocked 10) SOUND: nextToABeeper notNextToABeeper 11) COMPASS: facingNorth notFacingNorth facingSouth notFacingSouth facingEast notFacingEast facingWest notFacingWest 12) TOUCH: anyBeepersInBeeperBag noBeepersInBeeperBag -Conditional Instructions 13) if (predicate) 15) if (predicate) { { statement(s); statement(s); } } else if (predicate) 14) if (predicate) { { statement(s); statement(s); } } . . . else else { { statement(s); statement(s); } } -Repetition (Looping) Instructions 16) iterate (NUMBER) { statement(s) comprising body of loop; . . . } 17) while (predicate) { statement(s) comprising body of loop; . . . } 18) do { statement(s) comprising body of loop; . . . } while (predicate);