DELETION


In this blog we are going to see how a user can delete a specific data that is a particular book from the database.This is a operation which can only be performed by special user so this is user specific and can only be performed by the admin.


So before jumping directly on to the deletion operation we are going to discuss a pre-required step that is to copy the data from the secondary memory or the hard disk of the system to the program memory.This is an important step in the whole project as from this operation we can perform the rest of the operations.

The data from the text file in c++ cannot be deleted directly as we do in normal writing that is just to enter back space and the required data is deleted.This cannot happen because the user cannot directly access the file directly.The files in cpp are handled using streams and this stream is attached to a particular file.The stream is the one which performs 
the required operation on the file that is reading or writing.

The data now has to be copied from the file to the program.So for doing this we use the array data structure for storing the data.we declare a class named books which has the attributes of a particular book in the database.

class books
  {
     public:
     string name;
     string author;
     string publication;
     int counti;
     int pages;

  };
 books yash[50];

This is the array used for storing the data from the database.Just for demonstartion purpose we have kept the length of the array 50.You are independent to chose the size accordin to the requirements.

We need a marker to check how many elements of the database are copied to the array.So we declare a integer variable named top to point to the topmost element of the array yash.

int top=-1;

It is initialised to -1 so that initially it shows that there are no elements in the array.

Now coming to the deletion operation the data cannot be erased from the file so the remedy for this is that we copy the 
data from the database in to the array then delete the specific information and then write the new data in to the file.This would ensure deletion of the required book.Finally for deletion we take care that while copying the data from the file we dont copy the data to be deleted from the database to the file.

So we are going to implement a copying function which copies the data from the datbase and stores it into the yash array but only for deletion operation it omits the required information.
   
Lets declare the copying function step by step:- 

1.It would not return anything so the return type of the function would be void.
2.It omits the required info for deletion so a flag to ensure normal copying and deletion.
3.We declare the flag t for this purpose and set it to 1 for normal copying and 0 for deletion.

Keeping into consideration the above points the declaration of the function would be
   
   void copying(int t=1);

Here we have kept t as default argument and while deletion copying would be called with t=0 as its argument.

So in this blog we have got an idea of how the copying function must be constructed.Further implementation would be discussed in the next one.Stay tuned for further implementation of the project as we are going to build an awesome project.

WRITTEN BY-
PUSHKAR SADAPHAL(L 59)
Email id-pushkar.sadaphal17@vit.edu

Comments

Post a Comment

Popular posts from this blog

SEARCHING

ORDER BY PART-2

GROUP BY