Hi guys

i spend 3 weeks doing this project , but i don't know how to start

implement the Delete and update , can u please help me guys .?

here is my attachment

and my code

#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
using namespace std;

class Library
{

      public:
      int number;
      char Title[40];
      char Author[40];
      char Publisher[40];
      int Year_of_Publication;
      
      //get number for ADD
      int num_check()
      {
           ifstream in("Database.txt");
           if(!in)
           {
                  cout<<"Cannot open ""Database.txt"" file.\n";
                  return 1;
           }
           int i=1;
           while(in>>number>>Title>>Author>>Publisher>>Year_of_Publication)
           {i=i+1;}
           number=i;
           in.close();
           return number;
      }

      void Search()
 {
		  int m=0;
          char Input_Title[40];
		  char Input_Author[40];
		  int Input_Year;
		  Library s;
		  ifstream in("Database.txt");
		  if(!in){
              return ;
		  }
			cout<<"\t 1. Title"<<endl;
			cout<<"\t 2. Author/Publisher"<<endl;
			cout<<"\t 3. Year of publication"<<endl;
			cout<<endl<<"Select:";
            cin>>m;

			switch(m)
			{	
  
			 case 1:
					cout<<"Input the title you want :";
				    cin>>Input_Title;
				while(in>>s.number>>s.Title>>s.Author>>s.Publisher>>s.Year_of_Publication)//get every class
				 {
					if(!strcmp(Input_Title,s.Title)){//when find
						cout<<"\nNO: "<<s.number<<endl;
						cout<<"\nTitle : "<<s.Title<<endl;
						cout<<"Author/Publisher : "<<s.Author<<"/"<<s.Publisher<<endl;
						cout<<"Year of publication : "<<s.Year_of_Publication<<endl<<endl; } }
					 break;
  
			   case 2:
					cout<<"Input the Author or Publisher you want :";
					cin>>Input_Author;
				while(in>>s.number>>s.Title>>s.Author>>s.Publisher>>s.Year_of_Publication)//get every class
				{
					if((!strcmp(Input_Author,s.Author)) || !strcmp(Input_Author,s.Publisher)){//when find
						cout<<"\nNO: "<<s.number<<endl;
						cout<<"\nTitle : "<<s.Title<<endl;
						cout<<"Author/Publisher : "<<s.Author<<"/"<<s.Publisher<<endl;
						cout<<"Year of publication : "<<s.Year_of_Publication<<endl<<endl;}
				}
			   break;
  
			   case 3:
					cout<<"Input the Year of publication you want :";
					 cin>>Input_Year;
				 while(in>>s.number>>s.Title>>s.Author>>s.Publisher>>s.Year_of_Publication)//get every class
				{{
					if(Input_Year==s.Year_of_Publication)//when find
						cout<<"\nNO: "<<s.number<<endl;
						cout<<"\nTitle : "<<s.Title<<endl;
				    	cout<<"Author/Publisher : "<<s.Author<<"/"<<s.Publisher<<endl;
						cout<<"Year of publication : "<<s.Year_of_Publication<<endl<<endl;   }}
				break;
				default :
                        cout<<"Error! use only 1~3";
                        break;
				}
				
				//error handling for charactor
				fflush(stdin);
                cin.clear();

		cout<<endl<<endl<<"1.Search again"<<endl<<"2.Back to home"<<endl<<"Select:";
        cin>>m;
        switch(m){
        case 1:
             Search();
             break;
        default:
                break;
             }
             //error handling for charator
             fflush(stdin);
             cin.clear();
        
	}

           
           
      int ADD()
      {
           char m;
		   Library s;
           ofstream out;
           out.open("Database.txt",ios::app);
           if(!out)
           {
                   cout<<"Can't open file.\n";
                   return 1;
           }
  
		    cout <<"**********Add the new record**********"<<endl;
            cout<<"Enter Title:";
            cin>>s.Title;
            cout<<"Enter Author:";
            cin>>s.Author;
            cout<<"Enter Publisher:";
            cin>>s.Publisher;
            cout<<"Enter Year of Publicaion:";
            number=num_check();
            cin>>Year_of_Publication;
            out<<number<<endl;
            out<<s.Title<<endl;
            out<<s.Author<<endl;
            out<<s.Publisher<<endl;
            out<<Year_of_Publication<<endl<<endl;
            out.close();
    		
            cout<<endl<<endl<<"1.Add another record"<<endl<<"2.Back to home"<<endl<<"Select:";
            cin>>m;
            switch(m){
            case 1:
                 ADD();
                 break;
                 }
            //error handling for charator
            fflush(stdin);
             cin.clear();
            return 0;
      }
      
	  int Show_database()
      {
           ifstream in("Database.txt");
           if(!in)
           {
                  cout<<"Can't open ""Database.txt"" file.\n";
                  return 1;
           }
           while(in>>number>>Title>>Author>>Publisher>>Year_of_Publication)
           {cout<<"No: "<<number<<endl;
            cout<<"Title :"<<Title<<endl;
            cout<<"Author/Publisher : "<<Author<<" / "<<Publisher<<endl;
            cout<<"Year of Publication : "<<Year_of_Publication<<endl<<endl;
            }
            in.close();
            return 0;
            }                  
      
	  void Exit()
      {
            return ;
      }
    

 void welcome()
 { 
  cout<<"*********WELCOME TO SUNGKYUNKWAN LIBRARY MANAGEMENT SYSTEM*********"<<endl;
  cout<<"_______________________________HOME PAGE___________________________"<<endl;
  cout<<"Please choose one of the following options :"<<endl;
  cout<<"\t 1. Search"<<endl;
  cout<<"\t 2. Add the new record"<<endl;
  cout<<"\t 3. Delete the existing record"<<endl;
  cout<<"\t 4. Update the existing record"<<endl;
  cout<<"\t 5. Display the full database"<<endl;
  cout<<"\t 6. Exit"<<endl;
 }
 

};

int main()
{
 int last;
 int n=0;
  Library a;
  
 
 while(1){
  a.welcome();
  cout<<endl<<"Select:";
  cin>>n;
  switch(n)
  {
  case 1:
   a.Search();
   break;
  case 2:
   a.ADD();
   break;
  case 3:

   break;
  case 4:
  
   break;
  case 5:
   a.Show_database();
   break;
  case 6:
   a.Exit();
   break;
  default:                                                                                
          cout<<"Error!! Enter 1~6"<<endl;
          break;
  }
  fflush(stdin);
  cin.clear();

 }

 cin>>last;
 return 0;
}

There are a couple of ways to delete a book from the library.
1. Rewrite the entire file, and omit the book that is to be deleted.

2. Mark the book to be deleted so that other functions just simply skip it when reading the file. One way to mark the book is to set one of its attributes to something that can not be used, such as change the value of number to -1.


To modify a book. Since you chose to write the file in text mode, where each field has variable length, you really have no choice but to rewrite the entire file and make the change(s) to the book as you write the file. This would have been a lot easier had you chosen to write the file in binary mode where the size of each book in the file is the exact same size.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.