Đang chuẩn bị liên kết để tải về tài liệu:
A Complete Guide to Programming in C++ part 69

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

A Complete Guide to Programming in C++ part 69. This book provides both novice and experienced programmers with a comprehensive resource manual for the C++ programming language. Readers gain experience in all aspects of programming, from elementary language concepts to professional software development, with in depth coverage of all the language elements en route. These elements are carefully ordered to help the reader create useful programs every step of the way. | EXERCISES 659 Exercise 2 A hash file is required for speed of access to customer data.The concept of hash files is explained on the opposite page.To keep things simple each record in the hash file contains only a customer id and a name.The customer id is the key used by the hash function opposite to compute the address of the record. Use linear solution as collision resolution technique. Note Linear solution provides for adequate access times if the address space is sufficiently large and not too full. It is also important to distribute the record numbers yielded by the hash function evenly throughout the available address space.The hash function opposite will guarantee a good distribution if b is a sufficiently large prime number. Develop the HashEntry class used to represent customer data.You need to store the customer id as an unsigned long value and the name of the customer as a char array with a length of 30. Supply default values for the constructor declaration and additionally declare the read_at and write_at methods that read customer information at a given position in a stream or write information at that position. Both methods expect the position and the stream as arguments. Define the HashFile class to represent a hash file.The private members of the class comprise an fstream type file stream a string used to store the file name an int variable used to store the number b and the hash function shown opposite as a method.The public members comprise a constructor that expects a file name and a number b as arguments. It opens the corresponding file for read and write access.The destructor closes the file. Additionally declare the methods insert and retrieve to insert or retrieve single records. Both methods use a call to the hash function to compute the appropriate record number in the hash file. If a collision occurs the methods perform a sequential search to locate the next free slot in the address space mod of address space size or the desired customer .