I don't have a specific exercise for this, I get a lot of assignments that state "write the definition of a function .. (or for the class stackType, for this weeks example), if anybody has already worked these kinds of problems, can you tell me what the %^%^ they are actually asking for, is it a specific program I'm supposed to create, is it pseudocode, or do I get a dictionary and give the word-for-word definition of a function and hope thats good enough. This is one online class I am hating soooo bad. Writing code is fairly straightforward, but I have no idea what the books programming exercises are asking for (Data Structures with C++-Malik). Googling "definition of a function, c++" doesn't give any concrete answers.
To DEFINE a function means to write the actual function body.
This is a function DECLARATION:
int add(int a, int b);
It just "declares" that a function called "add" that takes two ints and returns an int EXISTS. But it doesn't really tell us what it does (we can guess from the name, but we can't be sure).
This is a function DEFINITION:
1 2 3 4
int add(int a, int b)
{
return a + b;
}
The definition includes the function's body. The definition tells us what it actually does, so in that sense it "defines" it.
yeah, its like pretend you're the group manager and you have a bunch of code monkeys working for you and you're gonna release a coin op video game. you write the program, which defines the major functions you want in your int main, and int main, which consists of three lines, a call to getCoin a call to playGame and a call to scores. :-) the code monkeys fill in the other part, but its your program because you're the boss :-D