0% found this document useful (0 votes)
2K views

Pseudocode BuiltIn Functions P2 PDF

The document describes built-in functions in pseudocode including functions to calculate remainders, integer parts, string lengths, string substrings, character cases, random numbers, and more. It provides examples for each function. Errors are returned if functions are called incorrectly. Operators for string concatenation and boolean logic are also described.

Uploaded by

Salman Ijaz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Pseudocode BuiltIn Functions P2 PDF

The document describes built-in functions in pseudocode including functions to calculate remainders, integer parts, string lengths, string substrings, character cases, random numbers, and more. It provides examples for each function. Errors are returned if functions are called incorrectly. Operators for string concatenation and boolean logic are also described.

Uploaded by

Salman Ijaz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Pseudocode Built-in functions

In each function, if the function call is not properly formed, the function returns an error.

MODULUS(x : INTEGER, y : INTEGER) RETURNS INTEGER

returns the remainder when x is divided by y using integer arithmetic.


Example: MODULUS(5, 2) returns 1

INT(x : REAL) RETURNS INTEGER

returns the integer part of x.


Example: INT(27.5415) returns 27

LENGTH(ThisString : STRING) RETURNS INTEGER

returns the integer value representing the length of string ThisString.


Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING

returns leftmost x characters from ThisString.


Example: LEFT("ABCDEFGH", 3) returns string "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING

returns rightmost x characters from ThisString.


Example: RIGHT("ABCDEFGH", 3) returns string "FGH"

TONUM(ThisString : STRING) RETURNS INTEGER

returns a numeric value equivalent to ThisString.


Example: TONUM("1201") returns integer value 1201

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING

returns string of length y starting at position x from ThisString.


Example: MID("ABCDEFGH", 2, 3) returns string "BCD"

LCASE(ThisChar : CHAR) RETURNS CHAR

returns the character value representing the lower case equivalent of ThisChar.
If ThisChar is not an upper-case alphabetic character then it is returned unchanged.
Example: LCASE('W') returns 'w'

1
MOD(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER

returns the integer value representing the remainder when ThisNum is divided by ThisDiv.
Example: MOD(10,3) returns 1

DIV(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER

returns the integer value representing the whole number part of the result when ThisNum is divided
by ThisDiv.
Example: DIV(10,3) returns 3

ONECHAR(ThisString : STRING, Position : INTEGER) RETURNS CHAR

returns the single character at position Position (counting from the start of the string with
value 1) from the string ThisString.

For example: ONECHAR("New York", 5) returns 'Y'

CHARACTERCOUNT(ThisString : STRING) RETURNS INTEGER

returns the number of characters in ThisString.

For example: CHARACTERCOUNT("New York") returns 8

ASC(ThisCharacter : CHAR) RETURNS INTEGER

returns an integer which is the ASCII character code for the character ThisCharacter.

For example: ASC('A') returns integer 65

SUBSTR(ThisString : STRING, Value1 : INTEGER, Value2 : INTEGER) RETURNS


STRING

returns a sub-string from within ThisString.


Value1 is the start index position (counting from the left, starting with 1).
Value2 is the final index position.

For example: SUBSTR("art nouveau", 5, 11) returns "nouveau"

TONUM(ThisString : STRING) RETURNS INTEGER or REAL

returns the integer or real equivalent of the string ThisString.

For example: TONUM("502") returns the integer 502


TONUM("56.36") returns the real number 56.36

2
CHR(Value : INTEGER) RETURNS CHAR

returns the character that ASCII code number Value represents.

For example: CHR(65) returns 'A'

RND() RETURNS REAL

returns a random number in the range 0 to 0.99999

For example: RND() returns 0.67351

UCASE(ThisChar : CHAR) RETURNS CHAR

returns the character value representing the upper case equivalent of ThisChar.
If ThisChar is not a lower case alphabetic character then it is returned unchanged.
Example: UCASE('h') returns 'H'

Errors

For any function, if the program calls the function incorrectly, the function returns an error.

Operators (pseudocode)

Operator Description

Concatenates (joins) two strings.


&
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"

Performs a logical AND on two Boolean values.


AND
Example: TRUE AND FALSE produces FALSE

Performs a logical OR on two Boolean values.


OR
Example: TRUE OR FALSE produces TRUE

Concatenation operator

& – Concatenates two expressions of STRING or CHAR data type.

For example: "South" & " " & "Pole" produces "South Pole"
'B' & "000654" produces "B000654"

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy