0% found this document useful (0 votes)
12 views

Pre-Defined Functions Notes

Pre-defined functions are built-in functions in programming languages that simplify tasks like mathematical calculations and text manipulation. They save time for programmers by providing tested code and reducing the amount of code that needs to be written. The document lists various pre-defined functions, their purposes, examples, and descriptions, including functions for rounding, generating random numbers, and string manipulation.

Uploaded by

mashac
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Pre-Defined Functions Notes

Pre-defined functions are built-in functions in programming languages that simplify tasks like mathematical calculations and text manipulation. They save time for programmers by providing tested code and reducing the amount of code that needs to be written. The document lists various pre-defined functions, their purposes, examples, and descriptions, including functions for rounding, generating random numbers, and string manipulation.

Uploaded by

mashac
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Software Design & Development

Pre-Defined Functions

A pre-defined function is a function already built into the programming language which performs
mathematical calculations, manipulates text, and formats values. Most programming languages have
hundreds of pre-defined functions that can be used at any time to perform a specific task.

Advantages of pre-defined functions


 Saves the programmer lots of time, this is because
o the code has already been written, therefore programmers have less code to create
o the code has already been tested, therefore less time spent debugging

Pre-Defined Functions for N5

Function Purpose Example Description


ROUND Round a numeric Math.round(average, 0) Rounds average to 0 decimal
value to a specified places
number of decimal Math.round(weight, 2) Rounds weight to 2 decimal
places places
RANDOM Generates a random Randomize Generates a random number
number RandomNumber = Int ( RND * 10) between 0 and 9

Randomize Generates a random number


RandomNumber = Int ( RND * 9) + 1 between 1 and 10

Randomize Generates a random number


RandomNumber = Int(Rnd * 50) between 0 and 50

LENGTH Returns the length of LEN(“Jessica”) returns 7 Returns the number of


a string characters the string
Checks if the number of
If LEN(ID) <> 5
characters in ID IS NOT equal to
5
Pre-Defined Functions for Higher

Function Purpose Example Description Notes


MID$ Substring Mid$(string, start, number of Extracts a substring from a
characters) string

Mid$(“Word”, 2, 3) returns ord

Mid$(“computer, 4, 3) returns
put

ASC ASCII Asc(“A”) returns 65 Returns the ASCII value of A-Z (upper case)
a character ASCII values between 65
and 90
CHARACTER CHR Chr(97) returns a Takes an ASCII value and
returns the corresponding a – z(lower case)
character ASCII values between 97
and 122
INTEGER INT INT(3.7556) returns 3 Returns the whole
number part of a real
number
CONVERSION CINT CINT(3.7556) returns 4 Rounds a real number to
INTEGER the nearest integer
MODULUS MOD First MOD second Returns the remainder of
first divided by second
7 MOD 3 returns 1

Other Useful Functions

Function Purpose Example Description


LCASE Converts a string to Name = LCASE(JENNIFER) Name would now store
lower case jennifer
UCASE Converts a string to Name = UCASE(Jennifer) Name would now store
upper case JENNIFER
SQRT Returns the square root Number = SQRT(49) Number would store the
of a numeric value value 7

Parameters

Parameters are variables or values that are passed in to be used by a function.

Function Parameters
Round(weight, 0) Weight and 0
Len(pupil_ID) Pupil_ID
SQRT(number) Number

You might also like