Functions
Functions are something that we have been using since day one in this class.
We didn't realize that we were creating a function, but now we will begin discussing functions in such a way that you will realize that;
int main ()
{
}
is a function. When we begin to realize that this is a function and that we can have more than one of them, this greatly expands what we can do within our program.
Here are somevideos to help bring the point home to you.
We didn't realize that we were creating a function, but now we will begin discussing functions in such a way that you will realize that;
int main ()
{
}
is a function. When we begin to realize that this is a function and that we can have more than one of them, this greatly expands what we can do within our program.
Here are somevideos to help bring the point home to you.
Functions Videos
Here are a couple more videos that goes deeper into Functions
The assignment
Scenario Some time ago we asked you to write a program to find out if a certain year was leap or common.
We want to return to the issue, but in a completely different form.
We want you to write a function equipped with the following features: its name should be "isLeap"; it accepts one argument of type int representing the year number; it returns a bool value: true if the year is leap and false otherwise; it should be mute!
It mustn't write anything to the output – the only way it reveals its actions is by the value it returns.
We've prepared a skeleton of the program – fill the function body with the appropriate content. We've also attached the output that is expected from your program.
We want to return to the issue, but in a completely different form.
We want you to write a function equipped with the following features: its name should be "isLeap"; it accepts one argument of type int representing the year number; it returns a bool value: true if the year is leap and false otherwise; it should be mute!
It mustn't write anything to the output – the only way it reveals its actions is by the value it returns.
We've prepared a skeleton of the program – fill the function body with the appropriate content. We've also attached the output that is expected from your program.
Examples
1995 -> 0
1996 -> 1
1997 -> 0
1998 -> 0
1999 -> 0
2000 -> 1
2001 -> 0
2002 -> 0
2003 -> 0
2004 -> 1
2005 -> 0
2006 -> 0
2007 -> 0
2008 -> 1
2009 -> 0
2010 -> 0
2011 -> 0
2012 -> 1
2013 -> 0
2014 -> 0
2015 -> 0
2016 -> 1
1996 -> 1
1997 -> 0
1998 -> 0
1999 -> 0
2000 -> 1
2001 -> 0
2002 -> 0
2003 -> 0
2004 -> 1
2005 -> 0
2006 -> 0
2007 -> 0
2008 -> 1
2009 -> 0
2010 -> 0
2011 -> 0
2012 -> 1
2013 -> 0
2014 -> 0
2015 -> 0
2016 -> 1