Guest User

Untitled

a guest
Feb 7th, 2016
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.60 KB | None | 0 0
  1. #include <iostream>
  2. #include<string.h>
  3. #include<fstream>
  4. #include <vector>
  5. #include <algorithm> // This is where you find std::sort
  6. #include <iostream>
  7. #include <fstream>
  8. #include <stdio.h>
  9. using namespace std;
  10.  
  11. #define IN 1
  12. #define OUT 0
  13.  
  14. int id_arr[50];
  15. int size=0;
  16. struct
  17. {
  18.   int bid;
  19.   char bname[25] ;
  20.   char author[25];
  21.   int noofcopies;
  22. int status;
  23.  
  24. }book;
  25.  
  26. FILE *librecord;
  27.  
  28. void insert();
  29. void update();
  30. void SearchBook();
  31. void request();
  32. void DisplayBook();
  33.  
  34. char info[500];
  35.  
  36.  
  37. int main()
  38. {
  39.  
  40.  
  41.     string uname,pwd;
  42.     int ch;
  43.  
  44.     cout << "\t \n Library management System \n" ; // prints !!!Hello World!!!
  45.     cout<<"\n Enter Username : ";
  46.     cin>>uname;
  47.     cout<<"\n Enter Password : ";
  48.     cin>>pwd;
  49.  
  50.  
  51.     if(uname=="admin123" && pwd=="admin123")
  52.     {
  53.     cout<<"\nYou are logged in as Librarian !!! \n";
  54.        
  55.     while(1)
  56.     {
  57.     cout<<"\n 1.Insert Book";
  58.     cout<<"\n 2.Display Book";
  59.     cout<<"\n 3.Search Book";
  60.     cout<<"\n 4.Log out";
  61.     cout<<"\n Enter your choice ???";
  62.     cin>>ch;
  63.  
  64.         switch(ch)
  65.         {
  66.         case 1:
  67.         insert();
  68.         break;
  69.  
  70.         case 2:
  71.         DisplayBook();
  72.         break;
  73.        
  74.         case 3:
  75.         SearchBook();
  76.         break;
  77.    
  78.         case 4:
  79.         return 0;
  80.         break;
  81.  
  82.         default:
  83.         cout<<"Invalid choice...!";
  84.         }
  85.        
  86.     }
  87.     }
  88.  
  89.     if(uname=="student123" && pwd=="student123")
  90.     {
  91.     cout<<"\nYou are logged in as Student !!! \n\n";
  92.     while(1)
  93.     {
  94.     cout<<"\n 1.Search Book";
  95.     cout<<"\n 2.log out\n";
  96.     cout<<"\n Enter your choice ???";
  97.     cin>>ch;
  98.  
  99.         switch(ch)
  100.         {
  101.         case 1:
  102.         SearchBook();
  103.         break;
  104.        
  105.         case 2:
  106.         return 0;
  107.  
  108.         default:
  109.         cout<<"Invalid choice...!";
  110.         }
  111.     }  
  112.     }      
  113.    
  114.     return 0;
  115. }
  116.  
  117.  
  118.  
  119. void insert()
  120. {
  121.     int i=0;book.status=IN;
  122.    
  123.             //opening the librecord file
  124.     librecord = fopen("librecord.txt","a+");
  125.    
  126.     cout<<"Enter The Name of The Book :\n";
  127.     cin>>book.bname;
  128.     cout<<"Enter The uniqueid of The Book :(Integer) \n";
  129.     cin>>book.bid;
  130.         id_arr[i]=book.bid;
  131.     i++;
  132.     size++;
  133.     cout<<"Enter The Name of Author :\n";
  134.     cin>>book.author;
  135.     cout<<"Enter The Number of copies Of The Book:(Integer)\n";
  136.     cin>>book.noofcopies;
  137.     fprintf(librecord,"\n%s\t%d\t%s\t%d\t",book.bname,book.bid,book.author,book.noofcopies);
  138.     fclose(librecord);
  139.     cout<<"A New Book has been Added Successfully...\n";
  140.  
  141. }
  142.  
  143.  
  144. void SearchBook()
  145. {
  146.     for(int i=0;i<size;i++){
  147.         cout<<id_arr[i];
  148.     }
  149.  
  150. }
  151.  
  152. void DisplayBook()
  153. {
  154.     librecord = fopen("librecord.txt","a+");
  155.     cout<<"\nName\tBookid\tAuthor\tCopies\n";
  156.     while(!feof(librecord))
  157.     {
  158.         fgets(info,500,librecord);
  159.         cout<<info;
  160.     }
  161.     fclose(librecord);
  162.    
  163. }
Add Comment
Please, Sign In to add comment