Many simple programs that you have written up to now have undoubtedly consisted only of a main() function that performed all the necessary steps to solve that problem. Yet, you were always encouraged to break the problem down into one or more subprograms or functions. When you break a program down into a series of functions, you are doing what is called functional abstraction. This book begins with a formalization of this process of functional abstraction: its methods, techniques, benefits, and so on.
A program also has another form of abstraction — data abstraction. At a low level, we define two variables to “hold” the user’s entered cost and quantity values and define another variable to hold the total cost of their order which can subsequently be calculated. In essence, these variables can be considered an abstraction as well. When the program executes and the user enters a quantity of 10 and cost of 42.00, the variables then hold a “real” value. However, from a program design point of view, most all of the variables you have defined and used in programs to this point are instances of the intrinsic built-in C++ data types, such as int, double, and long. (If you have studied the C++ structures, those are not intrinsic data types.) Now when we speak of data abstraction, we normally do not mean this low level way of thinking about data. Rather the term data abstraction refers to larger scale ways and means of organizing and using data. To get a better idea of what we mean by data abstraction, consider writing a program to analyze the length of the lines of ticket buyers trying to get into the latest Star Wars movie. Certainly each potential buyer can be represented by several intrinsic variables such as ages and the number of people in that party trying to get tickets. But a program to analyze
the line length must always process the current first group in the line; all newcomers must be added to the end of the line. (It is not nice to cut into a ticket line; it sometimes can be hazardous to your health.) Here we need a way to organize the sets of data and process them in the correct order. There is, in fact, just such a data abstraction that is totally designed for this precise application; it is called a queue. We examine queues and their operations in a later chapter. Next, suppose that you needed to write a program to manage the patients coming to visit a doctor. Here again comes a queue operation. When a patient arrives, he/she is placed at the end of the queue; when the doctor is ready for another patient, he/she generally comes from the head of the queue. Do we really want to invent and write all the coding for the ticket queue and then turn around and reinvent it all for the patient queue? If we learn how to properly build a queue data structure, then we only need to reuse it in this case. In fact, if you think about it for a minute, you can easily find other examples where a queue approach would be idea — just about any application that requires first in = first out type of processing.
€ pdf Beginning Data Structures in C++
Related Searches: intrinsic data types, c data types, functional abstraction, data abstraction, data structures in c
RSS feed for comments on this post · TrackBack URI
Leave a reply