Monday's Session
Thanks for everyone who showed up Monday. It seems that people are still having lots of trouble with functions so I'll make sure to keep touching on it until everyone is feeling totally comfortable.
Brief
The goal for this session is to reinforce the material on functions.
Outline
- [0-10 min] Q & A on anything that's been covered
- [10-30 min] Functions
- Function Overloading
- Side Effects
- Void Functions
- Syntax etc.
- Forward Declarations and their Motivation
- More on Modularity (How and when to use functions, and when not to use them)
- [0-5 min] Rand
- Low + rand() % (Max - Low + 1)
- [5 min] Modulus Operator
Lab Session
I've copied the lab questions below. Hope to see you guys there!Remember: I can't help you with homework! Do the first lab option if your having issues with your homework!
Lab Option 1 (designed to help with your homework):
Create a
console program which displays a grid of N by N x-s (where N is some constant value). One of the x-s should be marked as an o. The user should be prompted to enter n, e, s, or w (north, east, etc.) and when they do, the grid should be reprinted with the o moved accordingly. This should repeat infinitely. For example, in a 4x4 grid:
x x x x
x x x x
x x o x
x x x x
Enter a direction: n
x x x x
x x o x
x x x x
x x x x
Enter a direction: e
x x x x
x x x o
x x x x
x x x x
Enter a direction:
For this option you'll need to use a nested loop. You'll also need to store the x and y coordinate of the o in integer variables.
Lab Option 2 (designed to help you with the new material this week and next week's lab):
We will be recreating a program from a previous lab question, via a different method. Create a program which displays a series of rectangles like below
Where the number of rectangles is defined by a constant. To do this without doing some insane math, you'll have to make a helper function which allows you to specify the center of a rectangle to create a rectangle rather than the lower left corner.
Lab Option 3 (designed to challenge those who are finding things easy or want to challenge themselves, for added incentive I'll buy you a danish from bytes if you successfully complete this option):
Make an instinct program which displays a circle onto the screen and allows you the user to use the arrow keys to move the circle around. To do this, take a look at the Real Time functions in the instinct reference. Once you have that working, try to make a slower moving square that chases the circle around.