Question:
Explain Programming functions?
ben
2013-02-22 19:27:30 UTC
Hi, I'm trying to understand the concept of functions for a Psuedocode i doing for school.

I understand the basics of a functions but i have a few problems i need to clarify.

Okay lets say i have a function that lets me populate an Array that looks something like this'

¬Function PopulateArray ()
Declare variable I as integer
Declare constant NSSbSize=20
Declare Array CustomerID to hold 20 Integer Values
Declare Integer Array NSSBorder of size NSSbSize
I=0
For I=0 to NSSbSize-1
Display “Please enter the ID of the Customer”
Read CustomerID[i]
Display “Please enter Order.”
Input NSSBOrder[i]
End Function'

When i get to my next array i want to Populate.. How do i declare my variables? for eg The next array i need to populate only has to go up to 10.. so when i call the function, where will i set the variable to equal to 10? :S
Three answers:
Michael
2013-02-22 19:43:20 UTC
You pass the value during the call to the function.



For example let us say you use a variable called number to equal the size of the array. Each time you get to an array that needs to be populated you set the value of number to equal the size of the array. In the case of your example the next array is 10 so you set number = 10



Then you call the function, adding the variable so it passes the data to the function":



PopulateArray (Number)



the first part of your function would be changed to something like this:



¬Function PopulateArray ()

Declare variable I as integer

Declare constant NSSbSize=20

Declare Array CustomerID = Number
2016-11-29 07:05:55 UTC
It relies upon on what you like the function for. a million. //function without return form and yet with arguments kind of a "black hollow" function. You throw documents in and ever get any effects lower back. The caller assumes something is completed with that documents, yet won't be able to ever comprehend. no longer very functional for a commonplace case, the place it may be sturdy to a minimum of get a standing lower back indicating no count if the operation replaced into useful. 2. //function with return form and arguments greater effective in a commonplace case. for occasion, in case a million, the function constantly prints the sq. of the parameter to stdout. What if the caller would not choose it revealed to stdout? What if the caller needs the outcomes to be utilized in a greater equation? Case a million can no longer take care of those, yet case 2 can. think of in case you will, you call the case a million function interior a loop, when you consider which you like the entire of the squares of thousands of integers. the only element you like to print is the entire, yet using case a million you get a printout for each and each variety being squared. Case 2 could desire to be located into its very own compilation unit and stated as from a sort of different purposes. It takes an arbitrary enter, performs its obligations, then returns a result. you are able to print the result when you get it, if that's what you like, print it to a report rather of stdout if that's what you like, or never in case you do no longer choose it. 3. //function without return form and no arguments much greater "black hollow" than case a million. it won't purely constantly print to stdout and no the place else, it is going to additionally constantly print the sq. of three and not the rest. it may desire to honestly be replaced with here: void sq.(void) { printf("9"); } nice if it is the only element you like in a given difficulty, yet circumstances constantly replace. this occasion can't be adapted to the different application without recoding.
Jim
2013-02-22 19:47:55 UTC
the definition of the word "function"has many meanings. and in the case of computer languages, it depends (naturally) on which language you are using, because each has a selection from about 1 of 3 definitions.



C/C++ - a function returns a void (nothing) or it can return a different type. there are limits on what you can return due to using pointers, references, and the compiler's use of the cpu's internal stack, and the like. the compiler will bark if you forget to return something and it's not a void function. does stuff inside the function which is encapsulated in a function name with arguments.



basic/autoit - a function always returns something. in the case of basic, there are is also the sub [routine] which returns nothing. it just does useful stuff inside. for autoit, there is no sub. both are like basic.does stuff inside the function which is encapsulated in a function name with arguments.



math - a function always returns something. I think. well, maybe it can return the null set. so that would be equivalent to returning NULL in c++/c or a void function. computer languages are based on the mathematical idea of a function. so that's where the name I think comes from most likely. same model. does stuff inside the function which is encapsulated in a function name with arguments.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...