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

DATA ABSTRACTION · Part 3

Chapter 9: Front Matter · COMPUTER SCIENCE

as few assumptions about the data as possible. At the same time, a concrete data representation is defined as an independent part of the program. A concrete data type is a data type whose representation is known. Note Any program consist of two parts.

The two parts of a program are, the part that operates on abstract data and the part that defines a concrete representation , is connected by a small set of functions that implement abstract data in terms of the concrete representation. To illustrate this technique, let us consider an example to design a set of functions for manipulating rational numbers. Example A rational number is a ratio of integers, and rational numbers constitute an important sub-class of real numbers. A rational number such as / or / is typically written as: <numerator>/<denominator> where both the <numerator> and <denominator> are placeholders for integer values.

Both parts are needed to exactly characterize the value of the rational number. Actually dividing integers produces a float approximation, losing the exact precision of integers. 12th Computer Chapter - - / = .6666666666666665 However, you can create an exact representation for rational numbers by combining together the numerator and denominator. As we know from using functional abstractions, we can start programming productively before you have an implementation of some parts of our program.

Let us begin by assuming that you already have a way of constructing a rational number from a numerator and a denominator. You also assume that, given a rational number, you have a way of selecting its numerator and its denominator component. Let us further assume that the constructor and selectors are also available. We are using here a powerful strategy for designing programs: 'wishful thinking' .

We haven't yet said how a rational number is represented, or how the constructor and selectors should be implemented. Wishful Thinking is the formation of beliefs and making decisions according to what might be pleasing to imagine instead of by appealing to reality. Note - - constructor - - constructs a rational number with numerator x , denominator y

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 →