In this article I would show you how you can carry out elementary operations on a database. For example, how to add records, list them out, modify them, delete them, undelete them etc. Naturally these operations should be implemented using a menu system. Hence I have built a simple menu system through which the appropriate member functions of the class group get called. To be able to recall the records that have been deleted an additional field called flag has been used in the structure person. Any time a record is deleted a `*' is placed in this field of the record. During recalling of a record the `*' is replaced by a space. All other member functions of the class have been written taking into account the presence of this flag field in the structure. In the constructor the file is opened for reading and writing in binary mode. To ensure that the file operations are carried out efficiently we propose to open the file only once, perform all possible operations on it and finally close it. In the addrec( ) member function using the seekp( ) function firstly the put pointer is positioned at the end so that writing takes place at the end of the existing records, rather than overwriting them.
Download source code
No comments:
Post a Comment