For a book such as this, PreTEX’s treatment of computer programs is its most important feature. Computer programs are not included with the main body of the text; instead, they are placed in separate, secondary files, along with any desired explanatory text, and with any desired typesetting markup in place. By placing tags at appropriate places in the secondary files, PreTEX can extract arbitrary parts of a secondary file, in any desired order, for typesetting with the text. Another utility removes all the tags, text, and markup, producing as its output a program ready to be compiled. The same input file thus automatically produces both type- set program listings and compiled program code. In this way, the reader gains increased confidence in the accuracy of the computer program listings appearing in the text. In fact, with just two exceptions, all of the programs developed in this book have been compiled and succesfully tested under the g++ and Borland C++ compilers (versions 18.104.22.168 and 5.0, respectively). The two exceptions are the first program in Chapter 2 (which requires a compiler with a full ANSI C++ standard library) and the last program of Chapter 13 (which requires a compiler with certain Borland graphics routines).
We wish to design a class Fraction that correctly represents the properties and definition for rational numbers. Additionally, we wish to provide commands and queries that make instances of class Fraction useful. Since this example is not intended as a commercial product we will not add methods for every possible use of fractions. Our Fraction class will override some of the methods inherited from its parent class(es) as desired. Table 9.1 gives a general specification of the properties we desire for class Fraction . Since the JDK (Java development kit) has an abstract class, java.lang.Number, with the wrapper classes for the primitive number types as extensions, it seems logical to let Fraction also extend Number . A Fraction is a kind of Number . For consistency, our general specification shows the inclusion and redefinition of methods inherited from Number and from Object. Class Fraction is a final class. The access modifier, final, designates a Java class as one that cannot be extended. This choice makes sense for Fraction because there are no extensions to the concept of a rational number. Other subclasses of Number in the Java platform are also specified as final.
cause the test program to fail during the call to the getCursor operation. The source of the fail- ure does not lie in the implementation of the Point List ADT, nor is the test program flawed. The failure occurs because this sequence of operations creates a state that violates the precondi- tions of the getCursor operation (the list must not be empty when the getCursor operation is invoked). The speed with which you can create and evaluate test cases using an interactive, command-driven test program makes it very easy to produce this kind of error. It is very tempt- ing to just sit down and start entering commands. A much better strategy, however, is to create a test plan listing the test cases you wish to check and then to write out command sequences that generate these test cases.
In the Java examples we've shown so far, we've stored primitive variables of type double in our datastructures. This simplifies the program examples, but it's not repre sentative of how you use data storage structures in the real world. Usually, the data items (records) you want to store are combinations of many fields. For a personnel record, you would store last name, first name, age, Social Security number, and so forth. For a stamp collection, you'd store the name of the country that issued the stamp, its catalog number, condition, current value, and so on.
other—a book using today’s technology that could live up to my high stan- dards. So I set out to find the perfect author and finally Ron Penton came along to take on the challenge. Ron, too, had my same vision for a datastructures book. We couldn’t do something that had been done—there are a zillion boring data structure books—but if we could apply gaming tech- nology and graphics to teach the subject, we would have something unique. Moreover, this book is for anyone who wants to learn data struc- tures and related important algorithms. Sure, if you’re a game program- mer then you will feel at home, but if you’re not, then believe me, put down that hardbound college text and pick this book up because not only will you absolutely know this stuff inside and out by the time you’re done, but you will have an image in your mind like you have never had before. All right, now I want to talk about what you’re going to find inside.
In the next phase identifiers are encountered in the body of the program. We must locate the identifiers in the hash table to retrieve information associated with them. But what is the expected time to locate an identifier? If the element searched for is equally likely to be any element in the table, then the expected time to search for it is just the average time spent inserting an element. To see this, observe that in searching once for each element in the table, the time spent is exactly the same as the time spent inserting each element, assuming that elements are always appended to the end of the list for the appropriate bucket. Thus the expected time for a search is also 0(1 + N/B). The above analysis assumes that a hash function distributes elements uniformly over the buckets. Do such functions exist? We can regard a function such as that of Fig. 4.11 (convert characters to integers, sum and take the remainder modulo B) as a typical hash function. The following example examines the performance of this hash function.
Chapter 1 outlines the basic goals of high-quality software and the basic principles of software engineering for designing and implementing programs to meet these goals. Abstraction, stepwise refinement, and object-oriented design are discussed. Some princi- ples of object-oriented programming—encapsulation and inheritance—are introduced here. The UML class diagram is used as a tool for visualizing class characteristics and relationships. CRC cards are used in an introductory design example. This chapter also addresses what we see as a critical need in software education: the ability to design and implement correct programs and to verify that they are actually correct. Topics covered include the concept of “life-cycle” verification; designing for correctness using precon- ditions and postconditions; the use of deskchecking and design/code walk-throughs and inspections to identify errors before testing; debugging techniques, data coverage (black box), and code coverage (clear or white box) approaches; and test plans. As we develop ADTs in subsequent chapters, we discuss the construction of an appropriate test plan for each. The chapter culminates with the development of a test driver to aid in the testing of a simple programmer-defined class. The test driver has the additional benefit of introducing the basic I/O techniques used throughout the rest of the text.
At Data Miners, the analytic marketing consultancy I founded in 1997, we firmly believe that data mining projects succeed or fail on the basis of the quality of the data mining process and the suitability of the data used for mining. The choice of particular data mining techniques, algorithms, and software is of far less importance. It follows that the most important part of a data mining project is the careful selection and preparation of the data, and one of the most important skills for would-be data miners to develop is the ability to make connections between customer behavior and the tracks and traces that behavior leaves behind in the data. A good cook can turn out gourmet meals on a wood stove with a couple of cast iron skillets or on an electric burner in the kitchenette of a vacation condo, while a bad cook will turn out mediocre dishes in a fancy kitchen equipped with the best and most expensive restaurant-quality equipment. Olivia Parr Rud understands this. Although she provides a brief introduction to some of the trendier data mining techniques, such as neural networks and genetic algorithms, the modeling examples in this book are all built in the SAS programming language using its logistic regression procedure. These tools prove to be more than adequate for the task.
The main goal of this book is to teach fundamental programming principles using C, one of the most widely used programming languages in the world today. C is considered a ‘modern’ language even though its roots date back to the 1970s. Originally, C was designed for writing ‘systems’ programs—things like operating systems, editors, compilers, assemblers and input/ output utility programs. But, today, C is used for writing all kinds of applications programs as well—word processing programs, spreadsheet programs, database management programs, accounting programs, games, educational software—the list is endless.
In total, therefore, a software package is “packaged” to perform a specific series of calculations and operations and to provide the results in a defined format. A lan- guage permits an expanded level of flexibility but also fails to benefit from the ex- tensive testing and research normally devoted to the development of a “trusted” pack- age. The user must define which approach best fits the needs of the moment. Obviously, if a package exists for the desired analysis or synthesis, it should be considered be- fore turning to the many hours required to develop a reliable, efficient program. In addition, one may acquire the data needed for a particular analysis from a software package and then turn to a language to define the format of the output. In many ways, the two approaches go hand in hand. If one is to depend on computer analysis on a continuing basis, knowledge of the use and limits of both languages and software packages is a necessity. The choice of which language or software package to become familiar with is primarily a function of the area of investigation. Fortunately, how- ever, a fluent knowledge of one language or a particular software package will usu- ally help the user become familiar with other languages and software packages. There is a similarity in purpose and procedures that ease the transition from one approach to another.
Let’s examine one of the major ways in which linked lists differ from arrays. In an array each item occupies a particular position. This position can be directly accessed using an index number. It’s like a row of houses: you can find a particular house using its address. In a list the only way to find a particular element is to follow along the chain of links. It’s more like human relations. Maybe you ask Harry where Bob is. Harry doesn’t know, but he thinks Jane might know, so you go and ask Jane. Jane saw Bob leave the office with Sally, so you call Sally’s cell phone. She dropped Bob off at Peter’s office, so…but you get the idea. You can’t access a data item directly; you must use relationships between the items to locate it. You start with the first item, go to the second, and then the third, and so on, until you find what you’re looking for. Let’s see how a Workshop applet demonstrates lists.
Let’s look at each of these types from our three perspectives. First, we examine the abstract view of the structure—how we construct variables of that type and how we access individual components in our programs. Next, from an application perspective, we discuss what kinds of things can be modeled using each structure. These two points of view are important to you as a C++ programmer. Finally, we look at how some of the structures may be implemented—how the “logical” accessing function is turned into a location in memory. For built-in constructs, the abstract view is the syntax of the con- struct itself, and the implementation level remains hidden within the compiler. So long as you know the syntax, you as a programmer do not need to understand the imple- mentation view of predefined composite data types. As you read through the implemen- tation sections and see the formulas needed to access an element of a composite type, you should appreciate why information hiding and encapsulation are necessary.
Figure 6-8 illustrates the basic parts explosion in IDEF1X notation. Each gun component is a part of another, with the top-level ones (the air-gun in the above quotation, for example) having a null relationship (no parent). This structure represents a forest of mechanical trees, a one-to-many relationship between mechanisms and parts. There is a case for making the relationship many-to-many, representing a forest of graphs or networks instead of hierarchical trees. The aggregation adornment is the diamond shape at one end of the relationship line. The relationship is strong, or "nonidentifying," so the entity gets a foreign key attribute that is not part of the primary key ("is part of") and a dashed line (see the later section "Strong and Weak Relationships" for more information about nonidentifying relationships). While aggregation can be interesting and useful, it seldom has many consequences for the underlying database design. The main consequence is to couple the design more tightly. When you design a system, you break the system into subsystems, uncoupling the elements as much as possible. This permits the reuse of the elements in different situations. When you identify an aggregate, you are usually saying that you can't separate the aggregate from the entity it aggregates. That generally means you can't break the two apart into separate subsystems. Often, genericity (templates or generics) provides a way to gain reuse while still allowing for the tight coupling of the entities (as instantiated templates or generics). As ER diagramming has no concept of genericity, however, the concept isn't of much value in ER aggregation situations.
Sometimes it matters what happens to data items that happen to have equal keys. For example, you may have employee data arranged alphabetically by last names. (That is, the last names were used as key values in the sort.) Now you want to sort the data by zip code, but you want all the items with the same zip code to continue to be sorted by last names. You want the algorithm to sort only what needs to be sorted, and leave everything else in its original order. Some sorting algorithms retain this secondary ordering; they’re said to be stable. All the algorithms in this chapter are stable. For example, notice the output of the objectSort.java program. There are three persons with the last name of Smith. Initially the order is Doc Smith, Lorraine Smith, and Paul Smith. After the sort, this ordering is preserved, despite the fact that the various Smith objects have been moved to new locations.
One of the challenges of working with persistent data is that it is per- sistent. The structures stored in the database might change every time you run the program. If you mess something up in the database, you will have to fix it or start over before you can proceed. To help you keep things under control, I’ve provided methods called deleteURLSets, deleteTermCounters, and deleteAllKeys, which you can use to clean out the database and start fresh. You can also use printIndex to print the contents of the index.
AFL-CIO, another strong U.S. lobby, opposes changes to U.S. “wet lease” rules that the EC wishes to abolish in order to circumvent the U.S. workforce and their collective bargaining agreement protections. Wet-leasing requires U.S. carriers to use U.S. crews when leasing foreign aircraft. 63 The EC also seeks changes to the “Fly America Act” which stipulates that only U.S. airlines may provide transportation paid for by the U.S. government. The U.S Dept. of Transportation claims that national defense considerations play a central role in the evaluation of EC proposals with respect to the “Fly America Act” which is tied to the Civil Reserve Air Fleet (CRAF) program. 64 Airlines that participate CRAF voluntarily commit to provide aircraft, crews, fuel, maintenance, and ground-support equipment in support of U.S. military operations in times of national emergency or conflict. In return, participating carriers are eligible to receive peacetime government business, a market totaling $2 billion annually. This program has been restricted to U.S. carriers. 65
/** Task: Searches entry[first] through entry[last] for desiredItem, where the array entry is a data field. *@param first an integer index >= 0 and < Length of list *@param last an integer index >= 0 and < Length of list *@param desiredItem the object to be found in the array *@return true if desiredItem is found */