Input, Output & String Handling Flashcards

All 12 cards in this deck

In AQA pseudo-code, how do you get a value from the keyboard and display a message that uses it?

e.g. ask for a name then greet the user

  1. Store the input in a variable: name ← USERINPUT
  2. Display the message with OUTPUT: OUTPUT 'Hello ' + name

What is a string conversion (casting)?

Converting a value from one data type to another, e.g. STRING_TO_INT('25') converts the string '25' to the integer 25.

Why does keyboard input often need converting before it is used in a calculation?

In most languages keyboard input is read as a string, so it must be converted to an integer or real (e.g. with STRING_TO_INT) before arithmetic is done on it.

Which AQA pseudo-code functions convert between strings and numbers?

STRING_TO_INT and STRING_TO_REAL convert a string to a number; INT_TO_STRING and REAL_TO_STRING convert a number to a string.

In AQA pseudo-code, how do you join two strings together?

e.g. join firstName and surname with a space between them

With the + operator (concatenation):

fullName ← firstName + ' ' + surname

In AQA pseudo-code, how do you find the number of characters in a string?

e.g. word ← 'computer'

LEN(word), which gives 8.

What does SUBSTRING(start, end, s) return in AQA pseudo-code?

e.g. SUBSTRING(3, 7, 'computer')

The characters of s from position start to position end, with both included and positions counted from 0. Here it returns 'puter'.

What do CHAR_TO_CODE and CODE_TO_CHAR do?

e.g. given that the character code for 'A' is 65: CHAR_TO_CODE('A') and CODE_TO_CHAR(66)

CHAR_TO_CODE returns the character code of a character and CODE_TO_CHAR returns the character for a code, giving 65 and 'B'.

True or false? LEN counts spaces and punctuation when finding the number of characters in a string.

True. LEN counts every character, including spaces and punctuation, e.g. LEN('Hi, Sam') is 7.

In AQA pseudo-code, how do you output more than one value in a single OUTPUT statement?

e.g. a name and a score

Separate the values with commas: OUTPUT name, score

What does POSITION(s, c) return in AQA pseudo-code?

e.g. POSITION('keyboard', 'b')

The position of the first occurrence of the character c in the string s, counting from 0. Here it returns 3.

In AQA pseudo-code, how do you get a single character from a string?

e.g. the first letter of name

Use SUBSTRING with the same start and end position, counting from 0: SUBSTRING(0, 0, name)