The main topics you may need in this lab are:
Define the following function prototypes
In most modern computer programming languages, programmers can break up programs into smaller components (such as classes and subroutines or functions) and distribute those components among many source files, which the system can compile separately.
The usefulness of code written in this way is that it is reusable. You can use the .h file to use functions written later with other code if you so choose.
Your first task in this lab is to write a header file that we will use to define the square function.
Create a new file named Shapes.h and add the following code.:#ifndef __SHAPE_H__ #define __SHAPE_H__ #include "Myro.h" void square(Scribbler& robot, double length); #endif
Let's break down what's happening in this file. The #indef and #define lines work like an if statment for the .h file. If a definition for SHAPE_H exists it does not redefine it. This helps avoid having multiple definitions of the same functions in large projects.
"Myro.h" is included so that the Scribbler& robot argument can be passed as an argument in square().
square() is the function you will be writting in Shapes.cpp
Next you need to define what void square() actually does. Create a new file named Shapes.cpp and start with the function prototype
void square(Scribbler& robot, double length) { }Now you'll need to fill in a function that connects to the robot which it is passed and draws a square with a line length determined by length. Remember: robot.forward() and other functions like it take arguments in time not distance.
It is fine to use the variable length for how long the robot should drive forward, but you will need to experiment to get something close to a right angle for drawing the square. You do not need to be exact. All robots vary slightly and there is always some uncertainty, just get close enough that you are obviously drawing a square.
You'll need to write a driver program named Lab3Driver.cpp that will connect to your robot and invoke the square() function.
In order for this driver to use the functions you created you will need to include "Shapes.h".
You will be adding more shapes than just square(), so you should also make a menu for your driver program. A good example of this is in the example exicutable.
Your menu should loop, unless the exit option is chosen and call the appriate shape functions otherwise. If something other than an option is printed you need to print an error message for that as well.
Please read integers for your menu, use 0 for square, -1 for exit, and 1+ for other shapes to make your lab easier to grade.
You will need to expand on everything you learned from writting the square() function. Create another function that draws another, shape, symbol, or pattern of your choice.
If you have worked with a partner, you will need to do this step twice (3 functions total).
Make sure you do each of the following steps:
Once you're finished submit your lab using the submit script.