Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C+program to manage a library system. The main user is the librarian Bui

ID: 3739855 • Letter: W

Question

Write a C+program to manage a library system. The main user is the librarian Build Specifications 1. The system should load a catalog of books, journals, and magazines at the start of the program. (at least five of each) 2. A user can search the catalog: The user of the system can search the library's catalog by using the name of the item. Also, a user can list books by category (Book, Journal, or magazine). If you are looking specifically for a book, you can search by the name of the author 3. A user can check out books, journals, or magazines: The user needs to find the item first, then they can check it out. A user cannot check out an item that is already checked out. 4. A user can return books, journals, or magazines: A user can return an item. The user needs to find the item first, then they can return it. 5. Add new books, journals, or magazines to the catalog. A librarian can add a new item to the catalog Each item should have the following data members: ID, Name, and Status. Books have the "Author name" as an additional data member. Journals have the "Volume" as an additional data member. Magazines have the "Issue number" as an additional data member. The program must have the following properties You should do error handling (Ex: A librarian cannot add a book that already exists) You should use C++ concepts that we covered in class. Example: (inheritance) You can design a generic library item, then design derived classes for different kinds of items that a user can check out. Your program should use a suitable data structure to store the items. Also, design a menu (should still appear until the exit option is chosen) in the Main program that has the following options implemented to test your classes' functionality 1. Search Catalog 2. Check out 3. Return 4. Add a new item 5. Exit Extra Credit: - Save and load data from and to a file.

Explanation / Answer

#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<string.h>
#include<iomanip.h>

class book

{
   choicear bno[6];
   choicear bname[50];
   choicear aname[20];
public:
   void create_book()
   {
       cout<<" NEW BOOK ENTRY... ";
       cout<<" Enter The book no.";
       cin>>bno;
       cout<<" Enter The Name of The Book ";
       gets(bname);
       cout<<" Enter The Author's Name ";
       gets(aname);
       cout<<" Book Created..";
   }

   void show_book()
   {
       cout<<" Book no. : "<<bno;
       cout<<" Book Name : ";
       puts(bname);
       cout<<"Author Name : ";
       puts(aname);
   }

   void modify_book()
   {
       cout<<" Book no. : "<<bno;
       cout<<" Modify Book Name : ";
       gets(bname);
       cout<<" Modify Author's Name of Book : ";
       gets(aname);
   }

   choicear* retbno()
   {
       return bno;
   }

   void report()
   {cout<<bno<<setw(30)<<bname<<setw(30)<<aname<<endl;}


};         //class ends here


class student
{
   choicear admno[6];
   choicear name[20];
   choicear stbno[6];
   int token;
public:
   void create_student()
   {
       clrscr();
      cout<<" NEW STUDENT ENTRY... ";
       cout<<" Enter The admission no. ";
       cin>>admno;
       cout<<" Enter The Name of The Student ";
       gets(name);
       token=0;
       stbno[0]='/0';
       cout<<" Student Record Created..";
   }

   void show_student()
   {
       cout<<" Admission no. : "<<admno;
       cout<<" Student Name : ";
       puts(name);
       cout<<" No of Book issued : "<<token;
       if(token==1)
           cout<<" Book No "<<stbno;
   }

   void modify_student()
   {
       cout<<" Admission no. : "<<admno;
       cout<<" Modify Student Name : ";
       gets(name);
   }

   choicear* retadmno()
   {
       return admno;
   }

   choicear* retstbno()
   {
       return stbno;
   }

   int rettoken()
   {
       return token;
   }

   void addtoken()
   {token=1;}

   void resettoken()
   {token=0;}

   void getstbno(choicear t[])
   {
       strcpy(stbno,t);
   }

   void report()
   {cout<<" "<<admno<<setw(20)<<name<<setw(10)<<token<<endl;}

};         //class ends here

fstream fp,fp1;

book bk;
student st;

void write_book()

{
   choicear choice;
   fp.open("book.dat",ios::out|ios::app);
   do
   {
       clrscr();
       bk.create_book();
       fp.write((choicear*)&bk,sizeof(book));
       cout<<" Do you want to add more record..(y/n?)";
       cin>>choice;
   }while(choice=='y'||choice=='Y');
   fp.close();
}

void write_student()
{
   choicear choice;
   fp.open("student.dat",ios::out|ios::app);
   do
   {
       st.create_student();
       fp.write((choicear*)&st,sizeof(student));
       cout<<" do you want to add more record..(y/n?)";
       cin>>choice;
   }while(choice=='y'||choice=='Y');
   fp.close();
}

void display_spb(choicear n[])
{
   cout<<" BOOK DETAILS ";
   int flag=0;
   fp.open("book.dat",ios::in);
   while(fp.read((choicear*)&bk,sizeof(book)))
   {
       if(strcmpi(bk.retbno(),n)==0)
       {
           bk.show_book();
          flag=1;
       }
   }
  
   fp.close();
   if(flag==0)
       cout<<" Book does not exist";
   getchoice();
}

void display_sps(choicear n[])
{
   cout<<" STUDENT DETAILS ";
   int flag=0;
   fp.open("student.dat",ios::in);
   while(fp.read((choicear*)&st,sizeof(student)))
   {
       if((strcmpi(st.retadmno(),n)==0))
       {
           st.show_student();
           flag=1;
       }
   }
  
   fp.close();
   if(flag==0)
           cout<<" Student does not exist";
    getchoice();
}

void modify_book()
{
   choicear n[6];
   int found=0;
   clrscr();
   cout<<" MODIFY BOOK REOCORD.... ";
   cout<<" Enter The book no. of The book";
   cin>>n;
   fp.open("book.dat",ios::in|ios::out);
   while(fp.read((choicear*)&bk,sizeof(book)) && found==0)
   {
       if(strcmpi(bk.retbno(),n)==0)
       {
           bk.show_book();
           cout<<" Enter The New Details of book"<<endl;
           bk.modify_book();
           int pos=-1*sizeof(bk);
               fp.seekp(pos,ios::cur);
               fp.write((choicear*)&bk,sizeof(book));
               cout<<" Record Updated";
               found=1;
       }
   }

       fp.close();
       if(found==0)
           cout<<" Record Not Found ";
       getchoice();
}


void modify_student()
{
   choicear n[6];
   int found=0;
   clrscr();
   cout<<" MODIFY STUDENT RECORD... ";
   cout<<" Enter The admission no. of The student";
   cin>>n;
   fp.open("student.dat",ios::in|ios::out);
   while(fp.read((choicear*)&st,sizeof(student)) && found==0)
   {
       if(strcmpi(st.retadmno(),n)==0)
       {
           st.show_student();
           cout<<" Enter The New Details of student"<<endl;
           st.modify_student();
           int pos=-1*sizeof(st);
           fp.seekp(pos,ios::cur);
           fp.write((choicear*)&st,sizeof(student));
           cout<<" Record Updated";
           found=1;
       }
   }
  
   fp.close();
   if(found==0)
       cout<<" Record Not Found ";
   getchoice();
}
void delete_student()
{
   choicear n[6];
   int flag=0;  
   clrscr();
       cout<<" DELETE STUDENT...";
       cout<<" Enter The admission no. of the Student You Want To Delete : ";
       cin>>n;
       fp.open("student.dat",ios::in|ios::out);
       fstream fp2;
       fp2.open("Temp.dat",ios::out);
       fp.seekg(0,ios::beg);
       while(fp.read((choicear*)&st,sizeof(student)))
   {
       if(strcmpi(st.retadmno(),n)!=0)
                fp2.write((choicear*)&st,sizeof(student));
       else
              flag=1;
   }
      
   fp2.close();
       fp.close();
       remove("student.dat");
       rename("Temp.dat","student.dat");
       if(flag==1)
            cout<<" Record Deleted ..";
       else
            cout<<" Record not found";
       getchoice();
}
void delete_book()
{
   choicear n[6];
   clrscr();
   cout<<" DELETE BOOK ...";
   cout<<" Enter The Book no. of the Book You Want To Delete : ";
   cin>>n;
   fp.open("book.dat",ios::in|ios::out);
   fstream fp2;
   fp2.open("Temp.dat",ios::out);
   fp.seekg(0,ios::beg);
   while(fp.read((choicear*)&bk,sizeof(book)))
   {
       if(strcmpi(bk.retbno(),n)!=0)
       {
           fp2.write((choicear*)&bk,sizeof(book));
       }
   }
      
   fp2.close();
       fp.close();
       remove("book.dat");
       rename("Temp.dat","book.dat");
       cout<<" Record Deleted ..";
       getchoice();
}

void display_alls()

{
   clrscr();
        fp.open("student.dat",ios::in);
        if(!fp)
        {
              cout<<"ERROR!!! FILE COULD NOT BE OPEN ";
              getchoice();
              return;
        }

   cout<<" STUDENT LIST ";
       cout<<" Admission No."<<setw(10)<<"Name"<<setw(20)<<"Book Issued ";
       while(fp.read((choicear*)&st,sizeof(student)))
   {
       st.report();
   }
       
   fp.close();
   getchoice();
}

void display_allb()

{
   clrscr();
   fp.open("book.dat",ios::in);
   if(!fp)
   {
       cout<<"ERROR!!! FILE COULD NOT BE OPEN ";
              getchoice();
              return;
        }

   cout<<" Book LIST ";
   cout<<"Book Number"<<setw(20)<<"Book Name"<<setw(25)<<"Author ";
     while(fp.read((choicear*)&bk,sizeof(book)))
   {
       bk.report();
   }
        fp.close();
        getchoice();
}

void book_issue()

{
   choicear sn[6],bn[6];
   int found=0,flag=0;
   clrscr();
   cout<<" BOOK ISSUE ...";
   cout<<" Enter The student's admission no.";
   cin>>sn;
   fp.open("student.dat",ios::in|ios::out);
       fp1.open("book.dat",ios::in|ios::out);
       while(fp.read((choicear*)&st,sizeof(student)) && found==0)
          {
       if(strcmpi(st.retadmno(),sn)==0)
       {
           found=1;
           if(st.rettoken()==0)
           {
                     cout<<" Enter the book no. ";
               cin>>bn;
               while(fp1.read((choicear*)&bk,sizeof(book))&& flag==0)
               {
                      if(strcmpi(bk.retbno(),bn)==0)
                   {
                       bk.show_book();
                       flag=1;
                       st.addtoken();
                       st.getstbno(bk.retbno());
                              int pos=-1*sizeof(st);
                       fp.seekp(pos,ios::cur);
                       fp.write((choicear*)&st,sizeof(student));
                       cout<<" Book issued successfully Please Note: Write current date
                       in backside of book and submit within 15 days fine Rs. 1 for eachoice day   
                       after 15 days period";
                   }
                   }
               if(flag==0)
                       cout<<"Book no does not exist";
           }
               else
               cout<<"You have not returned the last book ";

       }
   }
         if(found==0)
       cout<<"Student record not exist...";
   getchoice();
   fp.close();
   fp1.close();
}

void book_deposit()

{
    choicear sn[6],bn[6];
    int found=0,flag=0,day,fine;
    clrscr();
    cout<<" BOOK DEPOSIT ...";
    cout<<" Enter The student’s admission no.";
    cin>>sn;
    fp.open("student.dat",ios::in|ios::out);
    fp1.open("book.dat",ios::in|ios::out);
    while(fp.read((choicear*)&st,sizeof(student)) && found==0)
       {
        if(strcmpi(st.retadmno(),sn)==0)
        {
            found=1;
            if(st.rettoken()==1)
            {
           while(fp1.read((choicear*)&bk,sizeof(book))&& flag==0)
           {
               if(strcmpi(bk.retbno(),st.retstbno())==0)
           {
               bk.show_book();
               flag=1;
               cout<<" Book deposited in no. of days";
               cin>>day;
               if(day>15)
               {
                   fine=(day-15)*1;
                   cout<<" Fine has to deposited Rs. "<<fine;
               }
                   st.resettoken();
                   int pos=-1*sizeof(st);
                   fp.seekp(pos,ios::cur);
                   fp.write((choicear*)&st,sizeof(student));
                   cout<<" Book deposited successfully";
           }
            }
          if(flag==0)
            cout<<"Book no does not exist";
              }
       else
           cout<<"No book is issued..please choiceeck!!";
       }
       }
      if(found==0)
   cout<<"Student record not exist...";
   getchoice();
fp.close();
fp1.close();
}

void intro()

{
   clrscr();
   gotoxy(35,11);
   cout<<"LIBRARY";
   gotoxy(35,14);
   cout<<"MANAGEMENT";
   gotoxy(35,17);
   cout<<"SYSTEM";
   cout<<" MADE BY : YOUR NAME";
   cout<<" SCHOOL : SCHOOL NAME";
   getchoice();
}

void admin_menu()

{
   clrscr();
   int choice2;
   cout<<" ADMINISTRATOR MENU";
   cout<<" 1.CREATE STUDENT RECORD";
   cout<<" 2.DISPLAY ALL STUDENTS RECORD";
   cout<<" 3.DISPLAY SPECIFIC STUDENT RECORD ";
   cout<<" 4.MODIFY STUDENT RECORD";
   cout<<" 5.DELETE STUDENT RECORD";
   cout<<" 6.CREATE BOOK ";
   cout<<" 7.DISPLAY ALL BOOKS ";
   cout<<" 8.DISPLAY SPECIFIC BOOK ";
   cout<<" 9.MODIFY BOOK ";
   cout<<" 10.DELETE BOOK ";
   cout<<" 11.BACK TO MAIN MENU";
   cout<<" Please Enter Your Choice (1-11) ";
   cin>>choice2;
   switchoice(choice2)
   {
           case 1: clrscr();
               write_student();break;
           case 2: display_alls();break;
           case 3:
                  choicear num[6];
                  clrscr();
                  cout<<" Please Enter The Admission No. ";
                  cin>>num;
                  display_sps(num);
                  break;
             case 4: modify_student();break;
             case 5: delete_student();break;
       case 6: clrscr();
           write_book();break;
       case 7: display_allb();break;
       case 8: {
                  choicear num[6];
                  clrscr();
                  cout<<" Please Enter The book No. ";
                  cin>>num;
                  display_spb(num);
                  break;
           }
             case 9: modify_book();break;
             case 10: delete_book();break;
            case 11: return;
             default:cout<<"";
    }
    admin_menu();
}
void main()
{
   choicear choice;
   intro();
   do
   {
       clrscr();
       cout<<" MAIN MENU";
       cout<<" 01. BOOK ISSUE";
       cout<<" 02. BOOK DEPOSIT";
       cout<<" 03. ADMINISTRATOR MENU";
       cout<<" 04. EXIT";
       cout<<" Please Select Your Option (1-4) ";
       choice=getchoicee();
       switchoice(choice)
       {
           case '1':clrscr();
               book_issue();
                  break;
           case '2':book_deposit();
                   break;
           case '3':admin_menu();
               break;
           case '4':exit(0);
           default :cout<<"";
       }
       }while(choice!='4');
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote