csenotes12

Library Managment System

Apr 14th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 16.33 KB | None | 0 0
  1. //***************************************************************
  2. //                   HEADER FILE USED IN PROJECT
  3. //****************************************************************
  4.  
  5. #include<fstream.h>
  6. #include<conio.h>
  7. #include<stdio.h>
  8. #include<process.h>
  9. #include<string.h>
  10. #include<iomanip.h>
  11.  
  12. //***************************************************************
  13. //                   CLASS USED IN PROJECT
  14. //****************************************************************
  15.  
  16.  
  17. class book
  18. {
  19.     char bno[6];
  20.     char bname[50];
  21.     char aname[20];
  22.   public:
  23.     void create_book()
  24.     {
  25.         cout<<"\nNEW BOOK ENTRY...\n";
  26.         cout<<"\nEnter The book no.";
  27.         cin>>bno;
  28.         cout<<"\n\nEnter The Name of The Book ";
  29.         gets(bname);
  30.         cout<<"\n\nEnter The Author's Name ";
  31.         gets(aname);
  32.         cout<<"\n\n\nBook Created..";
  33.     }
  34.  
  35.     void show_book()
  36.     {
  37.         cout<<"\nBook no. : "<<bno;
  38.         cout<<"\nBook Name : ";
  39.         puts(bname);
  40.         cout<<"Author Name : ";
  41.         puts(aname);
  42.     }
  43.  
  44.     void modify_book()
  45.     {
  46.         cout<<"\nBook no. : "<<bno;
  47.         cout<<"\nModify Book Name : ";
  48.         gets(bname);
  49.         cout<<"\nModify Author's Name of Book : ";
  50.         gets(aname);
  51.     }
  52.  
  53.     char* retbno()
  54.     {
  55.         return bno;
  56.     }
  57.  
  58.     void report()
  59.     {cout<<bno<<setw(30)<<bname<<setw(30)<<aname<<endl;}
  60.  
  61.  
  62. };         //class ends here
  63.  
  64.  
  65.  
  66.  
  67. class student
  68. {
  69.     char admno[6];
  70.     char name[20];
  71.     char stbno[6];
  72.     int token;
  73. public:
  74.     void create_student()
  75.     {
  76.         clrscr();
  77.          cout<<"\nNEW STUDENT ENTRY...\n";
  78.         cout<<"\nEnter The admission no. ";
  79.         cin>>admno;
  80.         cout<<"\n\nEnter The Name of The Student ";
  81.         gets(name);
  82.         token=0;
  83.         stbno[0]='/0';
  84.         cout<<"\n\nStudent Record Created..";
  85.     }
  86.  
  87.     void show_student()
  88.     {
  89.         cout<<"\nAdmission no. : "<<admno;
  90.         cout<<"\nStudent Name : ";
  91.         puts(name);
  92.         cout<<"\nNo of Book issued : "<<token;
  93.         if(token==1)
  94.             cout<<"\nBook No "<<stbno;
  95.     }
  96.  
  97.     void modify_student()
  98.     {
  99.         cout<<"\nAdmission no. : "<<admno;
  100.         cout<<"\nModify Student Name : ";
  101.         gets(name);
  102.     }
  103.  
  104.     char* retadmno()
  105.     {
  106.         return admno;
  107.     }
  108.  
  109.     char* retstbno()
  110.     {
  111.         return stbno;
  112.     }
  113.  
  114.     int rettoken()
  115.     {
  116.         return token;
  117.     }
  118.  
  119.     void addtoken()
  120.     {token=1;}
  121.  
  122.     void resettoken()
  123.     {token=0;}
  124.  
  125.     void getstbno(char t[])
  126.     {
  127.         strcpy(stbno,t);
  128.     }
  129.  
  130.     void report()
  131.     {cout<<"\t"<<admno<<setw(20)<<name<<setw(10)<<token<<endl;}
  132.  
  133. };         //class ends here
  134.  
  135.  
  136.  
  137.  
  138. //***************************************************************
  139. //        global declaration for stream object, object
  140. //****************************************************************
  141.  
  142. fstream fp,fp1;
  143. book bk;
  144. student st;
  145.  
  146.  
  147. //***************************************************************
  148. //        function to write in file
  149. //****************************************************************
  150.  
  151. void write_book()
  152. {
  153.     char ch;
  154.     fp.open("book.dat",ios::out|ios::app);
  155.     do
  156.     {
  157.         clrscr();
  158.         bk.create_book();
  159.         fp.write((char*)&bk,sizeof(book));
  160.         cout<<"\n\nDo you want to add more record..(y/n?)";
  161.         cin>>ch;
  162.     }while(ch=='y'||ch=='Y');
  163.     fp.close();
  164. }
  165.  
  166. void write_student()
  167. {
  168.     char ch;
  169.     fp.open("student.dat",ios::out|ios::app);
  170.     do
  171.     {
  172.         st.create_student();
  173.         fp.write((char*)&st,sizeof(student));
  174.         cout<<"\n\ndo you want to add more record..(y/n?)";
  175.         cin>>ch;
  176.     }while(ch=='y'||ch=='Y');
  177.     fp.close();
  178. }
  179.  
  180.  
  181. //***************************************************************
  182. //        function to read specific record from file
  183. //****************************************************************
  184.  
  185.  
  186. void display_spb(char n[])
  187. {
  188.     cout<<"\nBOOK DETAILS\n";
  189.     int flag=0;
  190.     fp.open("book.dat",ios::in);
  191.     while(fp.read((char*)&bk,sizeof(book)))
  192.     {
  193.         if(strcmpi(bk.retbno(),n)==0)
  194.         {
  195.             bk.show_book();
  196.              flag=1;
  197.         }
  198.     }
  199.    
  200.     fp.close();
  201.     if(flag==0)
  202.         cout<<"\n\nBook does not exist";
  203.     getch();
  204. }
  205.  
  206. void display_sps(char n[])
  207. {
  208.     cout<<"\nSTUDENT DETAILS\n";
  209.     int flag=0;
  210.     fp.open("student.dat",ios::in);
  211.     while(fp.read((char*)&st,sizeof(student)))
  212.     {
  213.         if((strcmpi(st.retadmno(),n)==0))
  214.         {
  215.             st.show_student();
  216.             flag=1;
  217.         }
  218.     }
  219.    
  220.     fp.close();
  221.     if(flag==0)
  222.             cout<<"\n\nStudent does not exist";
  223.      getch();
  224. }
  225.  
  226.  
  227. //***************************************************************
  228. //        function to modify record of file
  229. //****************************************************************
  230.  
  231.  
  232. void modify_book()
  233. {
  234.     char n[6];
  235.     int found=0;
  236.     clrscr();
  237.     cout<<"\n\n\tMODIFY BOOK REOCORD.... ";
  238.     cout<<"\n\n\tEnter The book no. of The book";
  239.     cin>>n;
  240.     fp.open("book.dat",ios::in|ios::out);
  241.     while(fp.read((char*)&bk,sizeof(book)) && found==0)
  242.     {
  243.         if(strcmpi(bk.retbno(),n)==0)
  244.         {
  245.             bk.show_book();
  246.             cout<<"\nEnter The New Details of book"<<endl;
  247.             bk.modify_book();
  248.             int pos=-1*sizeof(bk);
  249.                 fp.seekp(pos,ios::cur);
  250.                 fp.write((char*)&bk,sizeof(book));
  251.                 cout<<"\n\n\t Record Updated";
  252.                 found=1;
  253.         }
  254.     }
  255.  
  256.         fp.close();
  257.         if(found==0)
  258.             cout<<"\n\n Record Not Found ";
  259.         getch();
  260. }
  261.  
  262.  
  263. void modify_student()
  264. {
  265.     char n[6];
  266.     int found=0;
  267.     clrscr();
  268.     cout<<"\n\n\tMODIFY STUDENT RECORD... ";
  269.     cout<<"\n\n\tEnter The admission no. of The student";
  270.     cin>>n;
  271.     fp.open("student.dat",ios::in|ios::out);
  272.     while(fp.read((char*)&st,sizeof(student)) && found==0)
  273.     {
  274.         if(strcmpi(st.retadmno(),n)==0)
  275.         {
  276.             st.show_student();
  277.             cout<<"\nEnter The New Details of student"<<endl;
  278.             st.modify_student();
  279.             int pos=-1*sizeof(st);
  280.             fp.seekp(pos,ios::cur);
  281.             fp.write((char*)&st,sizeof(student));
  282.             cout<<"\n\n\t Record Updated";
  283.             found=1;
  284.         }
  285.     }
  286.    
  287.     fp.close();
  288.     if(found==0)
  289.         cout<<"\n\n Record Not Found ";
  290.     getch();
  291. }
  292.  
  293. //***************************************************************
  294. //        function to delete record of file
  295. //****************************************************************
  296.  
  297.  
  298. void delete_student()
  299. {
  300.     char n[6];
  301.     int flag=0;    
  302.     clrscr();
  303.         cout<<"\n\n\n\tDELETE STUDENT...";
  304.         cout<<"\n\nEnter The admission no. of the Student You Want To Delete : ";
  305.         cin>>n;
  306.         fp.open("student.dat",ios::in|ios::out);
  307.         fstream fp2;
  308.         fp2.open("Temp.dat",ios::out);
  309.         fp.seekg(0,ios::beg);
  310.         while(fp.read((char*)&st,sizeof(student)))
  311.     {
  312.         if(strcmpi(st.retadmno(),n)!=0)
  313.                  fp2.write((char*)&st,sizeof(student));
  314.         else
  315.                flag=1;
  316.     }
  317.        
  318.     fp2.close();
  319.         fp.close();
  320.         remove("student.dat");
  321.         rename("Temp.dat","student.dat");
  322.         if(flag==1)
  323.              cout<<"\n\n\tRecord Deleted ..";
  324.         else
  325.              cout<<"\n\nRecord not found";
  326.         getch();
  327. }
  328.  
  329.  
  330. void delete_book()
  331. {
  332.     char n[6];
  333.     clrscr();
  334.     cout<<"\n\n\n\tDELETE BOOK ...";
  335.     cout<<"\n\nEnter The Book no. of the Book You Want To Delete : ";
  336.     cin>>n;
  337.     fp.open("book.dat",ios::in|ios::out);
  338.     fstream fp2;
  339.     fp2.open("Temp.dat",ios::out);
  340.     fp.seekg(0,ios::beg);
  341.     while(fp.read((char*)&bk,sizeof(book)))
  342.     {
  343.         if(strcmpi(bk.retbno(),n)!=0)  
  344.         {
  345.             fp2.write((char*)&bk,sizeof(book));
  346.         }
  347.     }
  348.        
  349.     fp2.close();
  350.         fp.close();
  351.         remove("book.dat");
  352.         rename("Temp.dat","book.dat");
  353.         cout<<"\n\n\tRecord Deleted ..";
  354.         getch();
  355. }
  356.  
  357.  
  358.  
  359. //***************************************************************
  360. //        function to display all students list
  361. //****************************************************************
  362.  
  363. void display_alls()
  364. {
  365.     clrscr();
  366.          fp.open("student.dat",ios::in);
  367.          if(!fp)
  368.          {
  369.                cout<<"ERROR!!! FILE COULD NOT BE OPEN ";
  370.                getch();
  371.                return;
  372.          }
  373.  
  374.     cout<<"\n\n\t\tSTUDENT LIST\n\n";
  375.     cout<<"==================================================================\n";
  376.     cout<<"\tAdmission No."<<setw(10)<<"Name"<<setw(20)<<"Book Issued\n";
  377.     cout<<"==================================================================\n";
  378.  
  379.     while(fp.read((char*)&st,sizeof(student)))
  380.     {
  381.         st.report();
  382.     }
  383.          
  384.     fp.close();
  385.     getch();
  386. }
  387.  
  388.  
  389. //***************************************************************
  390. //        function to display Books list
  391. //****************************************************************
  392.  
  393. void display_allb()
  394. {
  395.     clrscr();
  396.     fp.open("book.dat",ios::in);
  397.     if(!fp)
  398.     {
  399.         cout<<"ERROR!!! FILE COULD NOT BE OPEN ";
  400.                getch();
  401.                return;
  402.          }
  403.  
  404.     cout<<"\n\n\t\tBook LIST\n\n";
  405.     cout<<"=========================================================================\n";
  406.     cout<<"Book Number"<<setw(20)<<"Book Name"<<setw(25)<<"Author\n";
  407.     cout<<"=========================================================================\n";
  408.  
  409.     while(fp.read((char*)&bk,sizeof(book)))
  410.     {
  411.         bk.report();
  412.     }
  413.          fp.close();
  414.          getch();
  415. }
  416.  
  417.  
  418.  
  419. //***************************************************************
  420. //        function to issue book
  421. //****************************************************************
  422.  
  423. void book_issue()
  424. {
  425.     char sn[6],bn[6];
  426.     int found=0,flag=0;
  427.     clrscr();
  428.     cout<<"\n\nBOOK ISSUE ...";
  429.     cout<<"\n\n\tEnter The student's admission no.";
  430.     cin>>sn;
  431.     fp.open("student.dat",ios::in|ios::out);
  432.         fp1.open("book.dat",ios::in|ios::out);
  433.         while(fp.read((char*)&st,sizeof(student)) && found==0)
  434.            {
  435.         if(strcmpi(st.retadmno(),sn)==0)
  436.         {
  437.             found=1;
  438.             if(st.rettoken()==0)
  439.             {
  440.                       cout<<"\n\n\tEnter the book no. ";
  441.                 cin>>bn;
  442.                 while(fp1.read((char*)&bk,sizeof(book))&& flag==0)
  443.                 {
  444.                        if(strcmpi(bk.retbno(),bn)==0)
  445.                     {
  446.                         bk.show_book();
  447.                         flag=1;
  448.                         st.addtoken();
  449.                         st.getstbno(bk.retbno());
  450.                                int pos=-1*sizeof(st);
  451.                         fp.seekp(pos,ios::cur);
  452.                         fp.write((char*)&st,sizeof(student));
  453.                         cout<<"\n\n\t Book issued successfully\n\nPlease Note: Write current date
  454.                        in backside of book and submit within 15 days fine Rs. 1 for each day    
  455.                        after 15 days period";
  456.                     }
  457.                     }
  458.                   if(flag==0)
  459.                         cout<<"Book no does not exist";
  460.             }
  461.                 else
  462.                   cout<<"You have not returned the last book ";
  463.  
  464.         }
  465.     }
  466.           if(found==0)
  467.         cout<<"Student record not exist...";
  468.     getch();
  469.       fp.close();
  470.       fp1.close();
  471. }
  472.  
  473. //***************************************************************
  474. //        function to deposit book
  475. //****************************************************************
  476.  
  477. void book_deposit()
  478. {
  479.     char sn[6],bn[6];
  480.     int found=0,flag=0,day,fine;
  481.     clrscr();
  482.     cout<<"\n\nBOOK DEPOSIT ...";
  483.     cout<<"\n\n\tEnter The student’s admission no.";
  484.     cin>>sn;
  485.     fp.open("student.dat",ios::in|ios::out);
  486.     fp1.open("book.dat",ios::in|ios::out);
  487.     while(fp.read((char*)&st,sizeof(student)) && found==0)
  488.        {
  489.         if(strcmpi(st.retadmno(),sn)==0)
  490.         {
  491.             found=1;
  492.             if(st.rettoken()==1)
  493.             {
  494.             while(fp1.read((char*)&bk,sizeof(book))&& flag==0)
  495.             {
  496.                if(strcmpi(bk.retbno(),st.retstbno())==0)
  497.             {
  498.                 bk.show_book();
  499.                 flag=1;
  500.                 cout<<"\n\nBook deposited in no. of days";
  501.                 cin>>day;
  502.                 if(day>15)
  503.                 {
  504.                    fine=(day-15)*1;
  505.                    cout<<"\n\nFine has to deposited Rs. "<<fine;
  506.                 }
  507.                     st.resettoken();
  508.                     int pos=-1*sizeof(st);
  509.                     fp.seekp(pos,ios::cur);
  510.                     fp.write((char*)&st,sizeof(student));
  511.                     cout<<"\n\n\t Book deposited successfully";
  512.             }
  513.             }
  514.           if(flag==0)
  515.             cout<<"Book no does not exist";
  516.               }
  517.          else
  518.             cout<<"No book is issued..please check!!";
  519.         }
  520.        }
  521.       if(found==0)
  522.     cout<<"Student record not exist...";
  523.     getch();
  524.   fp.close();
  525.   fp1.close();
  526.   }
  527.  
  528.  
  529.  
  530.  
  531. //***************************************************************
  532. //        INTRODUCTION FUNCTION
  533. //****************************************************************
  534.  
  535. void intro()
  536. {
  537.     clrscr();
  538.     gotoxy(35,11);
  539.     cout<<"LIBRARY";
  540.     gotoxy(35,14);
  541.     cout<<"MANAGEMENT";
  542.     gotoxy(35,17);
  543.     cout<<"SYSTEM";
  544.     cout<<"\n\nMADE BY : YOUR NAME";
  545.     cout<<"\n\nSCHOOL : SCHOOL NAME";
  546.     getch();
  547. }
  548.  
  549.  
  550.  
  551. //***************************************************************
  552. //        ADMINISTRATOR MENU FUNCTION
  553. //****************************************************************
  554.  
  555. void admin_menu()
  556. {
  557.     clrscr();
  558.     int ch2;
  559.     cout<<"\n\n\n\tADMINISTRATOR MENU";
  560.     cout<<"\n\n\t1.CREATE STUDENT RECORD";
  561.     cout<<"\n\n\t2.DISPLAY ALL STUDENTS RECORD";
  562.     cout<<"\n\n\t3.DISPLAY SPECIFIC STUDENT RECORD ";
  563.     cout<<"\n\n\t4.MODIFY STUDENT RECORD";
  564.     cout<<"\n\n\t5.DELETE STUDENT RECORD";
  565.     cout<<"\n\n\t6.CREATE BOOK ";
  566.     cout<<"\n\n\t7.DISPLAY ALL BOOKS ";
  567.     cout<<"\n\n\t8.DISPLAY SPECIFIC BOOK ";
  568.     cout<<"\n\n\t9.MODIFY BOOK ";
  569.     cout<<"\n\n\t10.DELETE BOOK ";
  570.     cout<<"\n\n\t11.BACK TO MAIN MENU";
  571.     cout<<"\n\n\tPlease Enter Your Choice (1-11) ";
  572.     cin>>ch2;
  573.     switch(ch2)
  574.     {
  575.             case 1: clrscr();
  576.                 write_student();break;
  577.             case 2: display_alls();break;
  578.             case 3:
  579.                    char num[6];
  580.                    clrscr();
  581.                    cout<<"\n\n\tPlease Enter The Admission No. ";
  582.                    cin>>num;
  583.                    display_sps(num);
  584.                    break;
  585.               case 4: modify_student();break;
  586.               case 5: delete_student();break;
  587.         case 6: clrscr();
  588.             write_book();break;
  589.         case 7: display_allb();break;
  590.         case 8: {
  591.                    char num[6];
  592.                    clrscr();
  593.                    cout<<"\n\n\tPlease Enter The book No. ";
  594.                    cin>>num;
  595.                    display_spb(num);
  596.                    break;
  597.             }
  598.               case 9: modify_book();break;
  599.               case 10: delete_book();break;
  600.              case 11: return;
  601.               default:cout<<"\a";
  602.        }
  603.        admin_menu();
  604. }
  605.  
  606.  
  607. //***************************************************************
  608. //        THE MAIN FUNCTION OF PROGRAM
  609. //****************************************************************
  610.  
  611.  
  612. void main()
  613. {
  614.     char ch;
  615.     intro();
  616.     do
  617.     {
  618.         clrscr();
  619.         cout<<"\n\n\n\tMAIN MENU";
  620.         cout<<"\n\n\t01. BOOK ISSUE";
  621.         cout<<"\n\n\t02. BOOK DEPOSIT";
  622.           cout<<"\n\n\t03. ADMINISTRATOR MENU";
  623.           cout<<"\n\n\t04. EXIT";
  624.           cout<<"\n\n\tPlease Select Your Option (1-4) ";
  625.           ch=getche();
  626.           switch(ch)
  627.           {
  628.             case '1':clrscr();
  629.                  book_issue();
  630.                     break;
  631.               case '2':book_deposit();
  632.                      break;
  633.               case '3':admin_menu();
  634.                  break;
  635.               case '4':exit(0);
  636.               default :cout<<"\a";
  637.         }
  638.         }while(ch!='4');
  639. }
  640.  
  641. //***************************************************************
  642. //                END OF PROJECT
  643. //
Add Comment
Please, Sign In to add comment