Monday's Session
Thanks for everyone who showed up. We'll be touching on functions more today if you have more questions on them.Brief
The goal for this session is to get everyone to accept functions as their best friends.Outline
- [0-10 min] Q & A on anything that's been covered
- [2 min] Quick Syntax Review
- Return Value
- Name of Function
- Parameters
- [10 min] Mini-Quiz
- Write a function that, given two floating point numbers, returns the distance between those two numbers on the number line.
Hint: In math this would be something like |a-b| (super simple). - [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)
- [5 min] Using Rand
- Low + rand() % (Max - Low + 1)
- [10 min] Functions and Instinct
- Instinct Objects are Just Objects
- Exercise: Create a function that, given three points, draws a triangle to the screen.
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 program which displays four rectangles (buttons) onto the screen. When the user clicks on a button it should turn red. When the user clicks the button again it should turn back to black. If you user makes the right combinations of red and black buttons, a secret message should be displayed. Your program should implement a couple of functions besides the main.
An inside function like the one Kris showed in class. Given a rectangle and a point it should return true or false depending on whether or not the point is inside of the rectangle.
A checkWin function that returns true if the correct combination of true and false boolean values is given. So the signature will look something like: bool checkWin(bool a, bool b, bool c, bool d).
Lab Option 2 (designed to help you with the new material this week and next week's lab):
Create a function distance which will give the distance between two Points, two Integers, two Floating-Point Numbers, and two Circles depending on the type of the argument given.
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):
Write a function which takes in a string in the format "Lucy {verb} over the {noun} and {verb} through the {noun}." and then prompts the user for a verb, a noun, another verb, then another noun. Then returns a string containing the ad-libbed phrase. This is perfectly possible with the tools you have and shouldn't even be very much code at all. You'll need to use find and substr extensively.
No comments:
Post a Comment