Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Programming Fundamentals/Function Examples

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

Overview The following pseudocode and flowchart examples take the Temperature program from the previous chapter and separate the functionality into independent functions for input, processing, and output, as GetFahrenheit, CalculateCelsius, and DisplayResult, respectively. Discussion As independent functions, each function acts as a miniature program, with its own input, processing, and output. As you review the following code, note which functions have parameters (input) and which functions have return values (output). Parameters and return values will be discussed in the next few pages. FunctionPurposeParameters (input)Return Value (output)Mainmain programnonenoneGetFahrenheitinputnonefahrenheitCalculateCelsiusprocessingfahrenheitcelsiusDisplayResultoutputfahrenheit, celsiusnone Pseudocode Function Main ... This program asks the user for a Fahrenheit temperature, ... converts the given temperature to Celsius, ... and displays the results. Declare Real fahrenheit Declare Real celsius Assign fahrenheit = GetFahrenheit() Assign celsius = CalculateCelsius(fahrenheit) Call DisplayResult(fahrenheit, celsius) End Function GetFahrenheit Declare Real fahrenheit Output "Enter Fahrenheit temperature:" Input fahrenheit Return Real fahrenheit Function CalculateCelsius (Real fahrenheit) Declare Real celsius Assign celsius = (fahrenheit - 32) * 5 / 9 Return Real celsius Function DisplayResult (Real fahrenheit, Real celsius) Output fahrenheit & "° Fahrenheit is " & celsius & "° Celsius" End Output Enter Fahrenheit temperature: 100 100° Fahrenheit is 37.7777777777778° Celsius Flowchart 225px|top|Main function flowchart 275px|top|GetFahrenheit function flowchart 225px|top|CalculateCelsius function flowchart 260px|top|DisplayResult function flowchart References Wikiversity: Computer Programming Flowgorithm – Flowchart Programming Language