19 Beginners' Class
Chapter 17 illustrated a few applications of structs. The first was a reworking of an
earlier example, from Section 13.2, where data on pupils and their marks had to be
sorted. In the original example, the names and marks for pupils were in separate arrays.
Logically, a pupil's name and mark should be kept together; the example in Section 17.1
showed how this could be done using a struct. The marks data in these structs were
only examined by the sort function, and about the only other thing that happened to the
structs was that they got copied in assignment statements. In this example, the structs
were indeed simply things that kept together related data.
In all the other examples from Chapter 17, the structs were used by many functions.
Thus the Points could be combined with an AddPoint() function, while the Customer
records in 17.3 were updated, transferred to and from disk, and printed. Although they
used arrays rather than structs, the examples in Chapter 18 also had data structures that
had many associated functions. Thus, the different forms of "hash table" all had
functions for initialization, searching for a key, inserting a key, along with associated
support functions (like the check for a "null" hash table entry). Similarly, the "bit
maps" for the information retrieval system in Section 18.3 had a number of associated
functions that could be used to do things like set specific bits.
You would have difficulties if you were asked "Show me how this code represents a
'Customer' (or a 'Hash Table', or a 'Bit map')". The program's representation of these
concepts includes the code manipulating the structures as well as the structures
This information is scattered throughout the program code. There is nothing to
group the functions that manipulate Customer records. In fact, any function can
manipulate Customer records. There may have been a PrintDetails(Customer&)
function for displaying the contents of a Customer record but there was nothing to stop
individual data m