14.10.1. rolodexdb.cpp(1): Random and Direct Access Example
A Rolodex again serves as the example for the next demonstration program. However, we make two significant changes as we move forward. First, the program forms a simple database with a few basic operations. Second, we implement our program with classes that span four files:
card.h
Contains the card class specification. All member functions are inline, so there isn't a source code file.
rolodex.h
Contains the rolodex class specification. Member functions are prototyped.
rolodex.cpp
Contains the rolodex class member function definitions.
rolodexdb.cpp
Contains main and other application functions.
Each file isolates and organizes some basic program functionality. All four files, the complete working program, are available at the bottom of the page. As only the Rolodex member functions contain code about this chapter, they are the only functions described in detail here. The functions contained in the other files are prototype below to provide a context for the Rolodex member functions.
rolodex.h. Specifies class rolodex. An instance of the rolodex class represents a simple Rolodex database. All of the class's member functions, prototyped here, are public. Notice that the database doesn't include a delete operation: once an object is written to a file, it's difficult to physically remove it (unless it's a the end of the file). So, a data record may be logically empty (flagged in some way) in the sense that it doesn't contain active or valid data, but it still takes space in the file.
Feature
Description
int main();
Creates an instance of the rolodex class. In an infinite loop, calls the menu function and carries out the user-selected operation by calling one of the rolodex functions.
char menu();
Prints a menu, prompts the user to select an operation, and returns the selected operation to main.
void input(char* prompt, char* field, int size);
Prompts the user for and reads from the console. Input values are stored in the C-string field, which has a length of size.
void pause();
A system independent console pause function.
rolodexdb.cpp: Defines the program start and the user interface functions.