Upload
kenneth-richard
View
213
Download
0
Embed Size (px)
Citation preview
ENEE150 – 0102ANDREW GOFFIN
Functional Decomposition
Why use functions?
Code ReuseSplitting Up FunctionalityReadabilityEase of testingSeparating use and implementation
Goffin – ENEE150
Choosing Functions
Top down design Look at high level description and split up the
functions from thereBottom up design
Building up from basic functionsTypically use top down, and look for
Repeated modules Hierarchy Logical units
Goffin – ENEE150
Declaring Functions
Function prototype
Function implementation
Function prototypes allow freedom of where you put your implementations in the program
Implementation has return type, name, and input variables
Goffin – ENEE150
Code Example – Robot Control
Goffin – ENEE150
Multiple Modules
Can split code up into multiple .c filesWhen compiling, just type:
gcc <file1> <file2> … <filen> Will still compile to one a.out file
Goffin – ENEE150
Project 1 - Chess
Note that queen is just a bishop and a rook put together
King is a queen that only moves one space
Goffin – ENEE150
Project 1 - Chess
Mainly just implementing move checksMUST use functions listed, but you can (and
are encouraged to) create more
Goffin – ENEE150
Project 1 - Chess
Pawn and general game logic should come FIRST Don’t start with knight… that’s going to be looked at
last for grading Cannot actually move most of the pieces without
moving the pawn anywayNo checks/checkmates/queening pawns
Only implement what’s listed in the project description
Start project ASAP The full two weeks are likely needed
Goffin – ENEE150