C programming Create a system managing a mini library syste

// C programming

Create a system managing a mini library system. Every book corresponds to a record (line) in a text file named \"mylibrary.txt\". Each record consists of 6 fields (Book ID, Title, Author, Possession, checked out Date, Due Date) separated by comma: No comma \" \"in title or author name. This mini library keeps the record for each book in the library. Different books can share the book \"Title\". But the \"Book ID\" for each book is unique. One author may have multiple books. Eg. Both book2 and book3 are written by author Possession field is \"Library\" means this book is kept in library, such as book #001. Otherwise, this book is checked out by the corresponding user. E.g. book #3 is checked out by User. A user is allowed to check out up to 3 books. The \"Checked out Date\" field specifies the time of the latest checked out date. The loan period for each book is 30 days. \"The Due Data\" filed specifies the time the book should be returned. This system should provide a menu with following functionalities that the bookkeeper can choose from at the top-level menu: Ask for title (read). Ask for author. Generate a book ID by adding one to the current largest book ID. Add the record of the new book into library with generated book ID, title, author, possession=\"library\", checked out date=\"null\" and due date=\"null\". After that, print message \"book*** added successfully!\" and go to step 5). Provide options \"t\" for \"\" and \"b\" for \"Back to main menu\". (If \"\", go to step 1))

Solution

#include <windows.h>
#include<stdio.h>                
#include<conio.h>                   //contains delay(),getch()etc.
#include <stdlib.h>
#include<string.h>                  //contains strcmp(),strcpy(),strlen(),etc
#include<ctype.h>                   //contains toupper(), tolower(),etc
#include<dos.h>                     //contains _dos_getdate
#include<time.h>

#define RETURNTIME 15

FILE *fp,*ft,*fs;

struct l_Date
{
    int mm,dd,yy;
};


struct record
{
    int bookid;
    char title[20];
    char Author[20];
    char possession[20];
    struct l_Date checkedout_date;
    struct l_Date due_date;
};
struct record r;

void main()
{
  
       clrscr();
    int i;

    printf(\" a. Add Books   \");

    printf(\"b. Delete books\");
  
    printf(\"c. Search Books\");
  
    printf(\"d. Issue Books\");

    printf(\"e. View Book list\");

    printf(\"f. Edit Book\'s Record\");
  
    printf(\"g. Close Application\");

    printf(\"Enter your choice:\");

    switch(getch())
    {
        case \'a\':
        addbooks();
        break;

        case \'b\':
        deletebooks();
        break;

        case \'c\':
        searchbooks();
        break;
      
        case \'d\':
        issuebooks();
        break;

        case \'e\':
        viewbooks();
        break;
        case \'f\':
        editbooks();
        break;

        case \'g\':
        {
        clrscr();
    
        printf(\"application is closing..\ \");
        exit(0);
        }

        default:
        {
        printf(\"\ Please re-entered correct option\");
      
        }

    }
}
void addbooks(void)    //funtion to add books
{
    int i;
    fp=fopen(\"Bibek.dat\",\"ab+\");
    fseek(fp,0,SEEK_END);
    fwrite(&r,sizeof(r),1,fp);
    fclose(fp);
    printf(\"The record is sucessfully saved\");
  
    printf(\"add any more?(t / b):\");//t to try again and b to back
    if(getch()==\'b\')
     
    else
     
        addbooks();
    }
}
void deletebooks()    //function delete record from file fp
{
    int d;
    char another=\'y\';
    while(another==\'y\') //infinite loop
    {
  
    printf(\"Enter the Book ID to delete:\");                                       
    scanf(\"%d\",&d);
    fp=fopen(\"Bibek.dat\",\"rb+\");
    rewind(fp);
    while(fread(&r,sizeof(r),1,fp)==1)
    {
        if(r.bookid==d)
        {

      
        printf(\"The book record is available\");
      
        printf(\"Book name is %s\",r.title);
     
        }
    }
    if(findbook!=\'t\')
    {
        gotoxy(10,10);
        printf(\"No record is found modify the search\");
      
    }
    if(findbook==\'t\' )
    {
     
        printf(\"Do you want to delete it?(Y/N):\");
        if(getch()==\'y\')
        {
        ft=fopen(\"test.dat\",\"wb+\"); //temporary file for delete
        rewind(fp);
        while(fread(&r,sizeof(r),1,fp)==1)
        {
            if(r.id!=d)
            {
            fseek(ft,0,SEEK_CUR);
            fwrite(&r,sizeof(r),1,ft); //write all in tempory file except that
            }                              //we want to delete
        }
        fclose(ft);
        fclose(fp);
        remove(\"Bibek.dat\");
        rename(\"test.dat\",\"Bibek.dat\"); //copy all item from temporary file to fp except that
        fp=fopen(\"Bibek.dat\",\"rb+\");    //we want to delete
        if(findbook==\'t\')
        {
         
            printf(\"The record is sucessfully deleted\");
          
            printf(\"Delete another record?(Y/N)\");
        }
        }
    else

    another=getch();
    }
    }
  
}
void searchbooks()
{
  
    int d;
    printf(\"*****************************Search Books*********************************\");

    printf(\" 1. Search By ID\");

    printf(\"2. Search By Name\");

    printf(\"Enter Your Choice\");

    fp=fopen(\"Bibek.dat\",\"rb+\"); //open file for reading propose
    rewind(fp);   //move pointer at the begining of file
    switch(getch())
    {
      case \'1\':
    {
     
        printf(\"****Search Books By Id****\");
      
        printf(\"Enter the book id:\");
        scanf(\"%d\",&d);
     
        printf(\"Searching........\");
        while(fread(&r,sizeof(r),1,fp)==1)
        {
        if(r.id==d)
        {
          
            printf(\"The Book is available\");
          
        
            printf(\"\ ID:%d\",r.bookid);
          
            printf(\"\ Name:%s\",r.title);
          
            printf(\"\ %s \",r.Author);
          
         
            findbook=\'t\';
        }

        }
        if(findbook!=\'t\') //checks whether conditiion enters inside loop or not
        {
       printf(\"\\aNo Record Found\");
        }
      
        printf(\"Try another search?(Y/N)\");
        if(getch()==\'y\')
        searchbooks();
        else
     
        break;
    }
    case \'2\':
    {
        char s[15];
     
        printf(\"****Search Books By Name****\");

        printf(\"Enter Book Name:\");
        scanf(\"%s\",s);
        int d=0;
        while(fread(&r,sizeof(r),1,fp)==1)
        {
        if(strcmp(r.title,(s))==0)
        {
          
            printf(\"The Book is available\");
          
         
            printf(\"\ ID:%d\",r.bookid);
          
            printf(\"\ Name:%s\",r.title);gotoxy(47,10);
          
            printf(\"\ Author:%s\",r.Author);
         
            printf(\"\\possession:%s\",r.possession);
         
          
            d++;
        }

        }
        if(d==0)
        {printf(\"\\aNo Record Found\");
        }
  
        printf(\"Try another search?(Y/N)\");
        if(getch()==\'y\')
        searchbooks();
        else

        break;
    }
    default :
    getch();
    searchbooks();
    }
    fclose(fp);
}


void editbooks(void) //edit information about book
{

    int c=0;
    int d,e;
  
    printf(\"****Edit Books Section****\");
    char another=\'y\';
    while(another==\'y\')
    {
     
        printf(\"Enter Book Id to be edited:\");
        scanf(\"%d\",&d);
        fp=fopen(\"Bibek.dat\",\"rb+\");
        while(fread(&r,sizeof(r),1,fp)==1)
        {
            if(checkid(d)==0)
            {
              
                printf(\"The book is availble\");
             
                printf(\"The Book ID:%d\",r.bookid);
              
                printf(\"Enter new name:\");scanf(\"%s\",r.title);
             
                printf(\"Enter new Author:\");scanf(\"%s\",r.Author);
             
                printf(\"The record is modified\");
                fseek(fp,ftell(fp)-sizeof(r),0);
                fwrite(&r,sizeof(r),1,fp);
                fclose(fp);
                c=1;
            }
            if(c==0)
            {
             
                printf(\"No record found\");
            }
        }
      
        printf(\"Modify another Record?(Y/N)\");
        fflush(stdin);
        another=getch() ;
    }
        returnfunc();
}
void returnfunc(void)
{
    {
    printf(\" Press ENTER to return to main menu\");
    }

    if(getch()==13) //allow only use of enter
    mainmenu();
    else
    goto r;
}
int getdata()
{
    int t;
  
    printf(\"Enter the Information Below\");

    printf(\"Category:\");

    printf(\"%s\",catagories[s-1]);

    printf(\"Book ID:\\t\");

    scanf(\"%d\",&t);
    if(checkid(t) == 0)
    {
     
        printf(\"\\aThe book id already exists\\a\");
        getch();
     
        return 0;
    }
    r.bookid=t;
  
    printf(\"Book Name:\");
    scanf(\"%s\",r.title);

    printf(\"Author:\");
    scanf(\"%s\",r.Author);
  
    printf(\"Possession:\");
    scanf(\"%d\",&r.possession);
  
    return 1;
}
int checkid(int t) //check whether the book is exist in library or not
{
    rewind(fp);
    while(fread(&r,sizeof(r),1,fp)==1)
    if(r.id==t)
    return 0; //returns 0 if book exits
      return 1; //return 1 if it not
}
int t(void) //for time
{
time_t t;
time(&t);
printf(\"Date and time:%s\ \",ctime(&t));

return 0 ;
}

void Password(void)
{

   char d[25]=\"Password Protected\";
   char ch,pass[10];
   int i=0,j;

    for(j=0;j<20;j++)
    {
    delay(50);
    printf(\"*\");
    }
    for(j=0;j<20;j++)
   {
   delay(50);
   printf(\"%c\",d[j]);
   }
   for(j=0;j<20;j++)
   {
   delay(50);
   printf(\"*\");
   }
   gotoxy(10,10);
   gotoxy(15,7);
   printf(\"Enter Password:\");

   while(ch!=13)
   {
    ch=getch();

    if(ch!=13 && ch!=8){
    putch(\'*\');
    pass[i] = ch;
    i++;
    }
   }
   pass[i] = \'\\0\';
   if(strcmp(pass,password)==0)
   {

    ;
    printf(\"Password match\");

    printf(\"Press any key to countinue.....\");
  
    mainmenu();
   }
   else
   {
  
     printf(\"\\aWarning!! Incorrect Password\");
     getch();
     Password();
   }
}
void issuerecord() //display issued book\'s information
{
       
         printf(\"The Book has taken by Mr. %s\",a.stname);
    
         printf(\"Issued Date:%d-%d-%d\",r.issued.dd,r.checkout_date.mm,r.checkout_date.yy);

         printf(\"Returning Date:%d-%d-%d\",r.due_date.dd,r.due_date.mm,r.due_date.yy);
}

// C programming Create a system managing a mini library system. Every book corresponds to a record (line) in a text file named \
// C programming Create a system managing a mini library system. Every book corresponds to a record (line) in a text file named \
// C programming Create a system managing a mini library system. Every book corresponds to a record (line) in a text file named \
// C programming Create a system managing a mini library system. Every book corresponds to a record (line) in a text file named \
// C programming Create a system managing a mini library system. Every book corresponds to a record (line) in a text file named \
// C programming Create a system managing a mini library system. Every book corresponds to a record (line) in a text file named \
// C programming Create a system managing a mini library system. Every book corresponds to a record (line) in a text file named \
// C programming Create a system managing a mini library system. Every book corresponds to a record (line) in a text file named \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site