Mon Apr 15 20:56:10 2024
EVENTS
 FREE
SOFTWARE
INSTITUTE

POLITICS
JOBS
MEMBERS'
CORNER

MAILING
LIST

NYLXS Mailing Lists and Archives
NYLXS Members have a lot to say and share but we don't keep many secrets. Join the Hangout Mailing List and say your peice.

DATE 2010-03-01

HANGOUT

2024-04-15 | 2024-03-15 | 2024-02-15 | 2024-01-15 | 2023-12-15 | 2023-11-15 | 2023-10-15 | 2023-09-15 | 2023-08-15 | 2023-07-15 | 2023-06-15 | 2023-05-15 | 2023-04-15 | 2023-03-15 | 2023-02-15 | 2023-01-15 | 2022-12-15 | 2022-11-15 | 2022-10-15 | 2022-09-15 | 2022-08-15 | 2022-07-15 | 2022-06-15 | 2022-05-15 | 2022-04-15 | 2022-03-15 | 2022-02-15 | 2022-01-15 | 2021-12-15 | 2021-11-15 | 2021-10-15 | 2021-09-15 | 2021-08-15 | 2021-07-15 | 2021-06-15 | 2021-05-15 | 2021-04-15 | 2021-03-15 | 2021-02-15 | 2021-01-15 | 2020-12-15 | 2020-11-15 | 2020-10-15 | 2020-09-15 | 2020-08-15 | 2020-07-15 | 2020-06-15 | 2020-05-15 | 2020-04-15 | 2020-03-15 | 2020-02-15 | 2020-01-15 | 2019-12-15 | 2019-11-15 | 2019-10-15 | 2019-09-15 | 2019-08-15 | 2019-07-15 | 2019-06-15 | 2019-05-15 | 2019-04-15 | 2019-03-15 | 2019-02-15 | 2019-01-15 | 2018-12-15 | 2018-11-15 | 2018-10-15 | 2018-09-15 | 2018-08-15 | 2018-07-15 | 2018-06-15 | 2018-05-15 | 2018-04-15 | 2018-03-15 | 2018-02-15 | 2018-01-15 | 2017-12-15 | 2017-11-15 | 2017-10-15 | 2017-09-15 | 2017-08-15 | 2017-07-15 | 2017-06-15 | 2017-05-15 | 2017-04-15 | 2017-03-15 | 2017-02-15 | 2017-01-15 | 2016-12-15 | 2016-11-15 | 2016-10-15 | 2016-09-15 | 2016-08-15 | 2016-07-15 | 2016-06-15 | 2016-05-15 | 2016-04-15 | 2016-03-15 | 2016-02-15 | 2016-01-15 | 2015-12-15 | 2015-11-15 | 2015-10-15 | 2015-09-15 | 2015-08-15 | 2015-07-15 | 2015-06-15 | 2015-05-15 | 2015-04-15 | 2015-03-15 | 2015-02-15 | 2015-01-15 | 2014-12-15 | 2014-11-15 | 2014-10-15 | 2014-09-15 | 2014-08-15 | 2014-07-15 | 2014-06-15 | 2014-05-15 | 2014-04-15 | 2014-03-15 | 2014-02-15 | 2014-01-15 | 2013-12-15 | 2013-11-15 | 2013-10-15 | 2013-09-15 | 2013-08-15 | 2013-07-15 | 2013-06-15 | 2013-05-15 | 2013-04-15 | 2013-03-15 | 2013-02-15 | 2013-01-15 | 2012-12-15 | 2012-11-15 | 2012-10-15 | 2012-09-15 | 2012-08-15 | 2012-07-15 | 2012-06-15 | 2012-05-15 | 2012-04-15 | 2012-03-15 | 2012-02-15 | 2012-01-15 | 2011-12-15 | 2011-11-15 | 2011-10-15 | 2011-09-15 | 2011-08-15 | 2011-07-15 | 2011-06-15 | 2011-05-15 | 2011-04-15 | 2011-03-15 | 2011-02-15 | 2011-01-15 | 2010-12-15 | 2010-11-15 | 2010-10-15 | 2010-09-15 | 2010-08-15 | 2010-07-15 | 2010-06-15 | 2010-05-15 | 2010-04-15 | 2010-03-15 | 2010-02-15 | 2010-01-15 | 2009-12-15 | 2009-11-15 | 2009-10-15 | 2009-09-15 | 2009-08-15 | 2009-07-15 | 2009-06-15 | 2009-05-15 | 2009-04-15 | 2009-03-15 | 2009-02-15 | 2009-01-15 | 2008-12-15 | 2008-11-15 | 2008-10-15 | 2008-09-15 | 2008-08-15 | 2008-07-15 | 2008-06-15 | 2008-05-15 | 2008-04-15 | 2008-03-15 | 2008-02-15 | 2008-01-15 | 2007-12-15 | 2007-11-15 | 2007-10-15 | 2007-09-15 | 2007-08-15 | 2007-07-15 | 2007-06-15 | 2007-05-15 | 2007-04-15 | 2007-03-15 | 2007-02-15 | 2007-01-15 | 2006-12-15 | 2006-11-15 | 2006-10-15 | 2006-09-15 | 2006-08-15 | 2006-07-15 | 2006-06-15 | 2006-05-15 | 2006-04-15 | 2006-03-15 | 2006-02-15 | 2006-01-15 | 2005-12-15 | 2005-11-15 | 2005-10-15 | 2005-09-15 | 2005-08-15 | 2005-07-15 | 2005-06-15 | 2005-05-15 | 2005-04-15 | 2005-03-15 | 2005-02-15 | 2005-01-15 | 2004-12-15 | 2004-11-15 | 2004-10-15 | 2004-09-15 | 2004-08-15 | 2004-07-15 | 2004-06-15 | 2004-05-15 | 2004-04-15 | 2004-03-15 | 2004-02-15 | 2004-01-15 | 2003-12-15 | 2003-11-15 | 2003-10-15 | 2003-09-15 | 2003-08-15 | 2003-07-15 | 2003-06-15 | 2003-05-15 | 2003-04-15 | 2003-03-15 | 2003-02-15 | 2003-01-15 | 2002-12-15 | 2002-11-15 | 2002-10-15 | 2002-09-15 | 2002-08-15 | 2002-07-15 | 2002-06-15 | 2002-05-15 | 2002-04-15 | 2002-03-15 | 2002-02-15 | 2002-01-15 | 2001-12-15 | 2001-11-15 | 2001-10-15 | 2001-09-15 | 2001-08-15 | 2001-07-15 | 2001-06-15 | 2001-05-15 | 2001-04-15 | 2001-03-15 | 2001-02-15 | 2001-01-15 | 2000-12-15 | 2000-11-15 | 2000-10-15 | 2000-09-15 | 2000-08-15 | 2000-07-15 | 2000-06-15 | 2000-05-15 | 2000-04-15 | 2000-03-15 | 2000-02-15 | 2000-01-15 | 1999-12-15

Key: Value:

Key: Value:

MESSAGE
DATE 2010-03-21
FROM Ruben Safir
SUBJECT Subject: [NYLXS - HANGOUT] C++ Workshop - Syntax Basics -- functions

A function is a variable, like any other variable, that contains code
data instead of static numbers, binary data or characters. It
represents a body of code that forms a process. All processes have
input, output and side affects. The input of a function is its argument
list. In C and C++, under most conditions values are passed by value.
That means that the value of an argument of a function is copied into a
function. There are important exceptions to this rule. It's output,
like the output of any variable, is the type that is defined in the
function declaration. Finally, functions have side affects.

Their is an operator affiliated with function, called the call operator,
represented by the syntax "()", Functions are declared, defined and
then instantiated. We will look at this in a moment.

Declaring Functions:

Functions are declared like any other variable with a couple of caveats.
They are declared as a type and attached to a symbol, and like pointers
or arrays, needs an operator, the call operator which also contains
variable types that define the arguments:

int factorials(int, int);
char * match_text(const * char, const *char);
bool sort(double[], int);

These are all expectable function declarations.

It is usually important for functions to have broad scope so that it can
be called in multiple parts of of your program. As such, they are best
declared in large programs in your header files, which are then declared
at the top of you code files. When declaring functions within your
header file, unlike other variables, they do not need the keyword
"extern" to be made global. In small programs they are often declared
and defined simultaneously above main().

In most cases, functions are run time entities, that don't exist in your
program until called. Variables and such that are declared within your
function are not only local to the function, but but don't exist when
the function ends. In fact, when a function process runs, the rest of
your program most normally stops and the function exists as in its own
space, inheriting certain environmental properties from the parent
calling process, and then ends. This is called the runtime stack.

In traditional C programming, functions can only have one name,
definition and declaration in your program. In C++, functions can be
"overloaded", which means that they can have different parameter lists,
each one being a attached to a different definition. This is very
important for object oriented programming, as we will see.

A function definition includes a block of code that performs the tasks
that your function will be responsible for. In procedural programming
it is a good practice to define all the tasks of your program as
appropriate function declarations, and then write your functions as
needed.

Defining a function involves declaring the argument variables within the
call operator and creating a statement block in curly braces which ends
with the appropriate return type in a return statement. It's syntax
looks like this:



func.h - Defining a struct, a struct type variables, a global int,
and two functions.

#ifndef FUNC_H
#define FUNC_H
#endif /* FUNC_H */

struct flashcard {
char * question;
char * answer;
};

extern flashcard * stack[];
extern const int size_of_stack;

flashcard ** quiz_setup(flashcard * [], const int);
flashcard ** quiz_dump(flashcard * [], const int);

------------------------------------------------------
func.cpp - main() and the functions that define our problem

#include
#include "func.h"

using namespace std;

int main(int argc, char * argv[]){
flashcard * stack[25];
flashcard ** deck;
deck = quiz_setup(stack, size_of_stack);
quiz_dump(deck, size_of_stack);

return 0;

}
~

func_lib.cpp - The definition of our functions
________________________________________________________________________

include "func.h"
#include
#include
using namespace std;

const int size_of_stack=25;

flashcard ** quiz_setup(flashcard* stack[], const int size){
for(flashcard ** i = stack; i < stack + size; i++){
*i = new flashcard;
}

for(int i = 0; i < size; i++){
stack[i]->question = new char [1000];
stack[i]->answer = new char [1000];
cout << "Enter a Question: " << endl;
cin.getline(stack[i]->question, 1000,'\n');
cout << "Enter an Answer " << endl;
cin.getline(stack[i]->answer, 1000,'\n');
}
return stack;
}

flashcard ** quiz_dump(flashcard* fulldeck[], const int size){
char pause;
for(flashcard ** i = fulldeck; i < fulldeck + size; i++){
cout << "Question: " << (*i)->question << endl;
cin >> pause;
cout << "Answer: " << (*i)->answer << endl;
cin >> pause;
}
return fulldeck;
}


___________________________________________________________________

What is interesting about this program is it is the first time we are
beginning to put together a variety of the programming tools that we
have been studying. Look at the use of the global structure, and the
use of the variable stack which is an array of pointers to struct. See
if you can understand why we need to initialize the structures using the
keyword "new" that we haven't covered yet, or how we utilize the
variable "i" within the function
flashcard ** quiz_dump(flashcard * [], const int) .




  1. 2010-03-01 Paul Robert Marino <prmarino1-at-gmail.com> Re: [NYLXS - HANGOUT] this should not get through
  2. 2010-03-01 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Catching the streams from Flash Video
  3. 2010-03-02 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] [ruben-at-mrbrklyn.com: [jim-at-well.com: [conspire] open source
  4. 2010-03-02 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Phone Tech Wars
  5. 2010-03-02 Ron Guerin <ron-at-vnetworx.net> Subject: [NYLXS - HANGOUT] NYLUG Workshop / Hacking Society (Smalltalk, C++, Python) Tuesday March 2 6:00PM-8:00PM
  6. 2010-03-02 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] this should not get through
  7. 2010-03-02 Paul Robert Marino <prmarino1-at-gmail.com> Re: [NYLXS - HANGOUT] this should not get through
  8. 2010-03-02 Paul Robert Marino <prmarino1-at-gmail.com> Re: [NYLXS - HANGOUT] this should not get through
  9. 2010-03-03 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] C++ Workshop _ Syntax Basics - agregate data types
  10. 2010-03-03 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] C++ Workshop _ Syntax Basics - agregate data
  11. 2010-03-03 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] C++ Workshop _ Syntax Basics - agregate data
  12. 2010-03-04 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] C++ Workshop _ Syntax Basics
  13. 2010-03-05 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] C++ Workshop _ Syntax Basics
  14. 2010-03-05 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] AlphaOne Labs invited you to the event "Ask-a-Sysadmin
  15. 2010-03-06 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Professors Open Source Summer Experience -at-RIT
  16. 2010-03-07 Kevin Mark <kevin.mark-at-verizon.net> Re: [NYLXS - HANGOUT] Professors Open Source Summer Experience -at-RIT
  17. 2010-03-09 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] C++ Workshop _ Syntax Basics Structs Unions and
  18. 2010-03-09 From: "Beau Gould" <bg-at-capitalmarketsp.com> Subject: [NYLXS - HANGOUT] [JOB] System Administrator, NYC to 90k
  19. 2010-03-09 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] [JOB] System Administrator, NYC to 90k
  20. 2010-03-10 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] C++ Workshop _ Syntax Basics Structs Unions
  21. 2010-03-13 redpill <redpill-at-rcn.com> Subject: [NYLXS - HANGOUT] NYLXS Library?
  22. 2010-03-13 redpill <redpill-at-rcn.com> Subject: [NYLXS - HANGOUT] NYLXS Library?
  23. 2010-03-14 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] NYLXS Library?
  24. 2010-03-14 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] NYLXS Library?
  25. 2010-03-15 redpill <redpill-at-rcn.com> Re: [NYLXS - HANGOUT] NYLXS Library?
  26. 2010-03-15 redpill <redpill-at-rcn.com> Re: [NYLXS - HANGOUT] NYLXS Library?
  27. 2010-03-15 Contrarian <adrba-at-nyct.net> Re: [NYLXS - HANGOUT] NYLXS Library?
  28. 2010-03-15 Contrarian <adrba-at-nyct.net> Re: [NYLXS - HANGOUT] NYLXS Library?
  29. 2010-03-15 Contrarian <adrba-at-nyct.net> Re: [NYLXS - HANGOUT] NYLXS Library?
  30. 2010-03-15 Contrarian <adrba-at-nyct.net> Re: [NYLXS - HANGOUT] NYLXS Library?
  31. 2010-03-15 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] NYLXS Library?
  32. 2010-03-15 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] NYLXS Library?
  33. 2010-03-15 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] NYLXS Library?
  34. 2010-03-16 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] C++ Workshop _ Syntax Basic: Flow Control Structures
  35. 2010-03-16 Ron Guerin <ron-at-vnetworx.net> Subject: [NYLXS - HANGOUT] NYLUG Workshop / Hacking Society (Smalltalk, C++, Python) Tuesday March 16 6:00PM-8:00PM
  36. 2010-03-16 redpill <redpill-at-rcn.com> Re: [NYLXS - HANGOUT] NYLXS Library?
  37. 2010-03-16 redpill <redpill-at-rcn.com> Re: [NYLXS - HANGOUT] NYLXS Library?
  38. 2010-03-17 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] C++ Workshop - Switches and Break
  39. 2010-03-17 einker <eminker-at-gmail.com> Subject: [NYLXS - HANGOUT] Revolution OS at Darress Theatre
  40. 2010-03-20 Ron Guerin <ron-at-vnetworx.net> Subject: [NYLXS - HANGOUT] Free Software Round Table TONIGHT at 10PM (live streaming)
  41. 2010-03-21 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] C++ Workshop - Syntax Basics -- functions
  42. 2010-03-21 Kevin Mark <kevin.mark-at-verizon.net> Re: [NYLXS - HANGOUT] C++ Workshop - Syntax Basics -- functions
  43. 2010-03-21 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] C++ Workshop - Syntax Basics -- functions
  44. 2010-03-21 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] C++ Workshop - Syntax Basics -- functions
  45. 2010-03-21 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] NYLXS Library?
  46. 2010-03-21 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] NYLXS Library?
  47. 2010-03-21 Kevin Mark <kevin.mark-at-verizon.net> Re: [NYLXS - HANGOUT] C++ Workshop - Syntax Basics -- functions
  48. 2010-03-21 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] C++ Workshop - Syntax Basics -- functions
  49. 2010-03-21 Ruben Safir <mrbrklyn-at-panix.com> Subject: [NYLXS - HANGOUT] Tina Gasperson commented on Darin Gasperson's status...
  50. 2010-03-21 redpill <redpill-at-rcn.com> Re: [NYLXS - HANGOUT] NYLXS Library?
  51. 2010-03-22 From: "Beau Gould" <bg-at-capitalmarketsp.com> Subject: [NYLXS - HANGOUT] [JOB] Systems Engineer, NYC | 90-100k
  52. 2010-03-23 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] NYLXS Library?
  53. 2010-03-24 einker <eminker-at-gmail.com> Subject: [NYLXS - HANGOUT] Free Software Award Winners Announced
  54. 2010-03-24 einker <eminker-at-gmail.com> Subject: [NYLXS - HANGOUT] Free Software Award Winners Announced
  55. 2010-03-25 redpill <redpill-at-rcn.com> Re: [NYLXS - HANGOUT] NYLXS Library?
  56. 2010-03-25 Ruben Safir <mrbrklyn-at-panix.com> Re: [NYLXS - HANGOUT] NYLXS Library?
  57. 2010-03-25 swd <sderrick-at-optonline.net> RE: [NYLXS - HANGOUT] NYLXS Library?
  58. 2010-03-30 Ron Guerin <ron-at-vnetworx.net> Subject: [NYLXS - HANGOUT] NYLUG Workshop / Hacking Society (Smalltalk, C++, Python) Tuesday March 30 6:00PM-8:00PM

NYLXS are Do'ers and the first step of Doing is Joining! Join NYLXS and make a difference in your community today!