Previous exam question

Hey guys,

This is an exam question that was on a previous exam for my programming class a few years ago made public for us to practice. Could anybody help me out in actually figuring out how to answer the question because I'm completely lost. My professor has told us that we didn't need to have completed assignment 3 from that year to do the question.

The question is:

As we saw in Assignment 3, it is not very hard to program the 3π robot to respond to
the buttons A, B and C, so we could write a program to allow us to manually drive the robot by
pressing the buttons. Since it would be difficult to keep your fingers on the button as it moves,

we can instead have it move in small increments for each time we press a button.
Assume that we have the following functions:

void turnRight10 (); // turn right 10 degrees
void driveAhead10 (); // move ahead 10 cm
void turnLeft10 (); // turn left 10 degrees
bool is Target (); // returns true if and only if target is found

The following is a contract for a function to allow us to manually drive the robot until the target
is sensed (don’t worry about how the target is defined — you’ve got a function for that). Give
an implementation for the function.
/∗∗ driveToTarget ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
∗ As long as the robot is not on the target, wait for a button
∗ to be pushed and respond as follows:
∗ A − turn left 10 degrees
∗ B − move ahead 10 cm
∗ C − turn right 10 degrees
∗/
void driveToTarget()


I don't know that we have the context for this.

I mean, loosely without any context, I can pseudocode at you..


void turnRight10 ()
{
a = getcurrentangle();
while( getcurrentangle() <= a+10) //this is likely in radians, though, I am not going there right now
{
turnleft();
}
}

but it could just as easily be no while loop and turnleft(10_units);
or a loop of (turnleft(1_unit))
or whatever it is that you have. You may have to backtrack right if you swing past it if your system is sloppy, an track until its within some margin of acceptable error of the target angle.

lots of details could be involved, see? We know nothing!
Yea I get what you're saying. That's why I felt so clueless when doing the question. My professor did say that the question is completely doable given the actual question and without doing assignment 3 for that year so I'm just not really sure what's expected for the answer, maybe something extremely general.
Maybe you can ask somebody or the prof himself for a little more context or maybe even a hint. *shrug*
If you don't have the rest of it, I would find a better problem to work on.
side note but we did a lot of toggle buttons on ours -- click and it would go until you clicked again. Not so much for driving it, more like camera on or the like.
Topic archived. No new replies allowed.