Pages

29.9.11

Data and processes in computing: At the supermarket: Objectives for Section 1


Objectives for Section 1

After studying this section you should be able to do the following.
· Recognise the terminology: character; string; integer; sequence; element (of a sequence); variable; identifier (of a variable); state (of a variable).
· Use and interpret the notational conventions:
o  single inverted commas to show a character;
o  double inverted commas to show a string (sequence of characters);
o  ’ to make explicit a space character;
o  the brackets [ and ] to delimit a sequence.

Exercises on Section 1

Exercise 1

(a) How many characters are there in the string “This text.”?
(b) Which of the following are integers: 3, 0, 98, 4, –22,, ‘7’, [56]?
(c) How many integers are there in the sequence [11, 23, 4, 56, 32]?

Answer

Solution

(a) There are ten characters: four in each word, a space, and a full stop.
(b) Each of 3, 0, 98, 4 and −22 is an integer. is not an integer because it is not a whole number. ‘7’ is a character, and is not an integer. [56] is a sequence containing one integer, but is not an integer.
(c) There are five integers in the sequence.
End of answer

Exercise 2

Suppose that the variable till2 holds data in the form of a sequence of barcodes. When an item is read at the checkout, the state of till2 is changed by appending the barcode of the item to the end of the sequence giving the state of till2. Suppose that till2 currently has the state [50222, 50345], and that an item with barcode 50111 is read, and then an item with barcode 50456 is read. Write out the state of the variable till2 at each stage.

Answer

Solution

In turn, the state takes the following values:
[50222, 50345]
(at the start).
[50222, 50345, 50111]
(after 50111 is read).
[50222, 50345, 50111, 50456]
(after 50456 is read).
End of answer

Exercise 3

With item prices as given in Table 1, what is the sequence of prices corresponding to the sequence of barcodes [33050, 33050, 77502, 53151, 77502]? What is the total price of the items given by this sequence?

Answer

Solution

The sequence of prices (given as integer numbers of pence, as in Table 1) is: [299, 299, 89, 440, 89]. The total price (in pence) is 1216 (or £12.16).
End of answer

No comments:

Post a Comment