📖 generic · 12th TN - English Medium · COMPUTER SCIENCE · Page 17definition

DATA ABSTRACTION · Part 5

Chapter 9: Front Matter · COMPUTER SCIENCE

can be called as Pairs. Representing Rational Numbers Using List You can now represent a rational number as a pair of two integers in pseudo code : a numerator and a denominator. rational(n, d): return [n, d] numer(x): r etu rn x[ ] denom(x): retu rn x[ ] . .

Tuple Remember, a pair is a compound data type that holds two other pieces of data. So far,we have provided you with two ways of representing the pair data type. The first way is using List construct and the second way with the tuple construct. A tuple is a comma-separated sequence of values surrounded with parentheses.

Tuple is similar to a list. The difference between the two is that you cannot change the elements of a tuple once it is assigned whereas in a list, elements can be changed. Example colour= ('red', 'blue', 'Green') Representation of Tuple as a Pair nums := ( , ) nums[ ] nums[ ] Note the square bracket notation is used to access the data you stored in the pair. To access the first element with nums[ ] and the second with nums[ ].

12th Computer Chapter - - Data Abstraction in Structure . List allow data abstraction in that you can give a name to a set of memory cells. For instance, in the game Mastermind, you must keep track of a list of four colors that the player guesses. Instead of using four separate variables (color1, color2, color3, and color4) you can use a single variable ‘Predict’, e.g., Predict:=['red', 'blue', 'green', 'green'] What lists do not allow us to do is name the various parts of a multi- item object.

In the case of a Predict, you don't really need to name the parts: using an index to get to each color suffices. But in the case of something more complex, like a person, we have a multi- item object where each 'item' is a named thing: the firstName, the lastName, the id, and the email. One could use a list to represent a person: person:=['Padmashri', 'Baskar', ' - - ', 'compsci@gmail.com'] but such a representation doesn't

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →