You are required to create a Single-Level Indexing for the tables of a database management system. Your index contains four entries. Each entry points to a block of employee records. Each block can hold up to four employee records. Records in each block are linked together by a linked list as shown below. see image.

If more than 4 records (employee nodes) has to be stored in a block, the new record (employee node) is placed in an overflow block. Each block can only be given one overflow block if it needs to store more than 4 employee records. Otherwise, there is no reason to have the overflow block. If the overflow block also fills up, no more record should be accepted for that block and your program should report failure. The structure of your Single-Level indexing with the overflow blocks can be as: see image.

You need to create a class called SingleLevelIndex. The main attribute of this class is an array of four elements of type Block pointer (Block*) ie: each element is a pointer to a DiskBlock.

Each DiskBlock contains a top pointer (as shown in the above picture) that points to the first employee record (node) in that block. Each DiskBlock also requires two more attributes: one is a pointer to the overflow DiskBlock, and another field can be called BlockCapacity that is initialized to 0 (indicating that there is space in the block) and is set to 1 when the block becomes full.

Each employee node has four fields: id, username, password, and next that points to the next employee in the linked list of that block.

You can provide a method in your SingleLevelIndex class called Startup( ). This method is immediately called once the program starts and should place the users into a loop to interactively choose some options until the user decided to quit the program. The options are:

1: Read a Transaction file
2: Save Current Configuration
3: Quit the program

If the user chooses 1, you ask the user to enter a transaction file name, you open the file, read the commands and process each row one by one until the end of the file. The commands can be Insert, Delete, Modify, PrintABlock, PrintAll, and Save An example of Insert command is:

Insert 123450 ahadaegh CS211ah

Where 123450 is the employee id, ahadaegh is the username and CS211ah is the password.

An example of Delete command is:

Delete 123450

Where 123450 is the employee id. The node that contains this employee should be searched and if exists it should be deleted.

An example of PrintABlock command is:

PrintABlock 1

Where 1 is the block number. There are four blocks, 0, 1,2, and 3. For this example, the contents of the second block, the one that second element of the array links to it, should be printed.

Similarly,

PrintABlock 0

Means the content of the block 0 (first block) should be printed.

An example of Modify is:

Modify 123450 2 samy001

Where 123450 is the employee id, 2 indicates that the second field (username) should be changed to samy001.

Similarly,

Modify 123450 3 1235happy

Indicates that the third field (password) of record with employee id 123450 should be changed to 1235happy.

Notes to remember:

When you process an Insert command several things should be checked:

1) Ensure that the employee id is valid. A valid employee id must have 0, 1, 2, or 3 as its last digit

2) If the employee id is valid, you need to find where it should be inserted. All employee ids that have 0 as their last digit like 123450, 122310, or 328790, should be placed into Block 0 (first block). Similarly, All employee ids that have 1 as their last digit like 123451, 122211, or 165421, should be placed into Block 1 (second block) and so on

3) After finding appropriate block, you need to check the Capacity flag to see if the block is full.

a. If the block is not full, insert the new record by creating a node and attach it to the linked list. If after insertion, the block reaches its capacity, you need to set the Capacity flag in that block to true

b. If the block is full, create an overflow block (if not created already) and place the new node in there. If the overflow block is full, you should report appropriate failure message

When you process a Delete command several things should be checked:

1) Ensure that the employee id is valid.

2) If the employee id is valid, you need to search it in appropriate block (using the method explained above). If it is not in the block it might be in the associated overflow block.

3) After finding appropriate record, you should delete the record

a. If the record was the only record in the overflow area, the overflow block should be deleted as well

b. If the record was in the primary block ensure that the block capacity is set to false in case it was set to true before the delete.

An specific case of Modify command is when you attempt to change the employee id.

For example,

Modify 123450 1 123452

Note that nodes are placed in blocks based on the employee id. Now if the employee id changes, the modified record may have to be deleted from one block and placed into a new block. For example if we modify the employee id of employee 123450 to 123452, this employee should be deleted from block 0 and placed in block 2 instead.

Another interactive command is Save that saves the information of each block into a separate file. The records in block 0 should be placed in file 0.txt, the contents of block 1 should be placed into file 1.txt and so on.

You are required to have a function in your SingleLevelIndex class called LoadConfiguration that is called from the constructor of that class Note that right upon the start of your program, the LoadConfiguration should load the old configuration from the files 0.txt, 1.txt, 2.txt, and 3.txt into appropriate blocks.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.