CPSC 100, Fall 1995, Quiz #6

This is Quiz #6 from CPSC 100: Principles of Computer Science, Fall 1995. The answers given would receive full credit, but in many cases, there are variations or even completely different answers that would also receive full credit. The "Notes" are meant to clarify the answer or to provide some interesting extra information.

Question 1: Explain what is meant by abstraction and what it means to say that a programming language should provide support for abstraction.

Answer: An abstraction is essentially an idea in a programmer's mind. To say that a language should provide support for abstraction means that it should be possible for a programmer to express such ideas directly and naturally in the language, rather than having to implement them using lower-level concepts.

Note: An example of this would be "loops." In assembly language, a programmer has to build a loop using only jump and conditional jump instructions--which in themselves have nothing to do with looping. In the high level language xTurtle, the programmer can just say loop ... end loop. Thus, the idea of looping is expressed directly in the program, not just in the programmer's mind.

Question 2: Choose any two of the following programming languages and briefly discuss the role that each played in the history of programming languages: FORTRAN, ALGOL, COBOL, Pascal, Ada.

Answer: FORTRAN was the first high-level programming language to be created; it is still widely used in scientific and engineering programming. ALGOL, which was created shortly after FORTRAN, is important because it introduced many ideas that have been used in most languages designed since then, such as structured loop and if statements, recursive subroutines, and the distinction between local and global variables.

Note: COBOL was designed by a committee sponsered by the government. It introduced the important data-structuring abstractions, records and files. It was for many years the most widely-used language in government and business. (There has probably been more COBOL written than any other language, although C and C++ are now more commonly used for new programs.) Pascal, which is similar to ALGOL but introduced a high level of support for data structures, is a small and elegant language that has been widely used for teaching programming. Ada is based on Pascal, but is a much larger language. It includes modern programming concepts like modules and parallel processing. It is used mainly for certain types of military programming.

Question 3: Define the terms data type and data structure and explain the difference.

Answer: A data structure is an organized collection of bits in the computer's memory. A data type is used to specify the organization of a data structure; that is, it can be used a blueprint for constructing data structures and as a road map for interpreting them. A data type can be used to specify many different data structures. Those data structures can hold different bits, but they will share the same structure.

Note: A programming language like Pascal provides a number of built-in data types, such as "integer" and "real". These are usually thought of as specifying simple data items, rather than data structures. But the fact is that even an integer or a real is represented in the computer's memory as a sequence of bits, and the data type specifies how those bits are to be interpreted. (Recall from all the way back in Chapter 1 that the exact same sequence of bits can mean many different things, depending on how it is interpreted.)

Question 4: Records and arrays are two ways of structuring data. What are some of the basic differences between records and arrays?

Answer: Both records and arrays are structured collections of simpler data items. But the items in an array must all be of the same type, while the items in a record can be of different types. Furthermore, the individual items in an array are referred to by their number, or position, in the list of items, while the individual items in a record are referred to by names associated with each position in the list.

Question 5: Many versions of the programming language Pascal support the use of units. Explain briefly what is meant by a unit in Pascal, and explain what units have to do with the more general concept of modules.

Answer: A unit is a kind of module that can contain both data and subroutines. Like any module, a unit has an interface and an implementation. (In a Pascal unit, this distinction is made explicit by labeling the interface and the implementation as such.) And like any module, a unit is meant to be used as a component in a larger system--in this case, a complete program.

[by David Eck]