Computer Science E50a
Wednesday Section . 7:30 . Emerson 106

TF: Alix Marchandise-Franquet
September 23rd, 1998

Introduction

TF Vital Statistics

Alix Marchandise-Franquet
Email: afranq@fas.harvard.edu
Please put [E50a] in the subject of your messages
If you figure out the answer to a question before I reply, please email me back with the subject: [E50a]Never mind

Where to turn in your homework
Outside of Science Center 102, the first box to your right

Office Hours
* Always, by e-mail
* After section on Wednesday nights in Emerson 106
* Some weeks on Thursday nights at the Church street lab (time TBD)
* Feel free to ask questions after lecture too (I usually sit in the back).

Section Web Page:
http://www.fas.harvard.edu/~afranq/e50a

You can always send questions to libe50a@fas.harvard.edu (which is read by all the TFs) or to other TFs.

UNIX Info

What are these .something files?
Remember that after you activated your account, we asked you to do the following:
% cp ~libe50a/.login .
% cp ~libe50a/.cshrc .
I am sure that many of you are wondering what all this was about. Basically, these are files that are loaded when you log into your account, and that set up your environment. Thanks to the .login file you can see the MOTD (Message Of The Day) which provides various info for the course. Without the proper .cshrc file, you couldnıt use the ³sections² command.

How to find out if someone is online?
If you want to know if your new best friend from E50a is also working on his/her assignment or if your TF is still working on a project at 5am, you can use the ³finger² command as follows:
%finger login@hostname
For example: %finger afranq@fas.harvard.edu
If you just type ³finger joe², it will automatically finger the person whose login is joe on the machine you are currently logged on.

The Wonderful World of Karel++

The settings:

All the above is defined in a .wld file that we provide or you create.

The basic robot type (class): the ur_Robot
A robot of class ur_robot can obey to 5 basic instructions:

It can also sense several things:

Robots are created at the beginning of a task. You have to specify:

Here is an example of a declaration of a Robot:
ur_Robot Karel (3, 4, South, 2); // donıt forget the semicolumn!
This will create a robot of class ur_Robot named Karel.
Karel will start to execute its instructions at the corner of 3rd street and 4th avenue, facing South, with 2 beepers in its beeper bag.

Loops
Loops are just a way to repeat an instruction or a set of instruction a given number of times.
loop (number of times you want this repeated)
{
instruction1();
instruction2();
}

Making new robots, an example
Problem 16, page 66

class Fencebuilder : ur_Robot // remember the single column
{
        // declaration of new instructions
        void arrangeOneRow(); // donıt forget the semicolumns
        void arrangeFourRows();
}; // donıt forget this semicolumn either!

// definition of the arrangeOneRow instruction
void Fencebuilder :: arrangeOneRow() // here, double column
{
        putBeeper(); // no robot name in the definition of new instructions
        move();
        putBeeper();
        move();
        putBeeper();
        move();
} // no semicolumn here

// definition of the arrangeFourRows instruction
void Fencebuilder :: arrangeFourRows()
{
        arrangeOneRow();
        turnLeft();
        arrangeOneRow();
        turnLeft();
        arrangeOneRow();
        turnLeft();
        arrangeOneRow();
        turnLeft();
} // no semicolumn here

task
{
        Fencebuilder Karel (3, 3, East, 12);
        // these instructions are for Karel, so we put its name
        Karel.arrangeFourRows();
        Karel.turnOff();
} // no semicolumn here

Syntax / Indentation

Writing a Program

  1. Think in English about what needs to be done and how, try to break up the problem into smaller problems.
  2. Try to find patterns in what you need to do. These patterns will enable you to define new instructions. For example, if very often you have to do 3 left turns, define a turnRight instruction.
  3. Write your program in ³pseudocode² with the new instructions
  4. Translate it into code
  5. Test it
  6. if needed, fix it:

A Word on Problem Set 1 (due Monday, October 5 before lecture)

This week, try to read at least the first three chapters of the Karel++ book.

Part C: Debugging
First fix the problems with spelling and syntax.
Then see if the program terminates abnormally (with an error shutoff) and fix that.
Finally, is it doing what it should?
After every change you make, test again!

Part D: Pencil and Paper (you are strongly encouraged to type your answers...)
Stick to problem 1 for this week. You may define extra instructions in order to define the 3 new instructions. But remember: do not use loops or if statements.

Part E: Programming Exercises Do only problem 5 this week (you will need next weekıs lecture for the others).