Course Note 5
Course Note 5
4.1 STORAGE
Computers require a set of instructions and data to be stored in their memory to perform a
specific task. In programming languages, data are identified by name rather than by their location
addresses in main storage. The names that associate stored data values are called identifiers.
An identifier: is the name by which the data value may be identified. It is a constant if it is
always associated with the same data value and it is a variable if its associated data value is
allowed to change. Names are literals or identifiers. When names or letters are used literally
they are called literals, and they are distinguished from identifiers by placing them within
quotation marks. So the instruction PRINT “N” means print the letter N, meaning print the
value associated with N.
Purpose of Declarations:
i. Choice of storage representation: Translator determine the best storage representation of
data types that is why it needs to know primarily the information of data type and
attribute of a data object.
ii. Storage Management: It helps the computer to make best use of memory for data object
by providing its information so that computer can allocate the optimum size of memory
for the data.
In pseudocode form:
If condition is true
Then do task A
else
Do Task-B
In this example, the condition is evaluated, if the condition is true Task-A is evaluated
and if it is false, then Task-B is executed
A variation of the construct of the above figure is shown below
The if statement together with logical operators will be used to test for true or false as
shown below. If a = b
print “a = b” The action is only taken when the test is true.
Example 5: The program is to input an examination mark and test it for the award of a grade.
The mark is a whole number between 1 and 100. Grades are awarded according to the following
criteria:
>= 80 Distinction
>= 60 Merit
>= 40 Pass
< 39 fail
The pseudo-code is
Use variables: mark of type integer
If mark >= 80 display “distinction”
If mark >= 60 and mark < 80 display “merit”
If mark >= 40 and mark < 60 display “pass”
If mark < 39 display “fail”
Example 8: A program segment repeatedly asks for entry of a number in the range 1 to
100 until a valid number is entered.
REPEAT
DISPLAY “Enter a number between 1 and 100” ACCEPT number
UNTIL number < 1 OR number > 100