Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<string.h>
- #include<fstream>
- #include <vector>
- #include <algorithm> // This is where you find std::sort
- #include <iostream>
- #include <fstream>
- #include <stdio.h>
- using namespace std;
- #define IN 1
- #define OUT 0
- int id_arr[50];
- int size=0;
- struct
- {
- int bid;
- char bname[25] ;
- char author[25];
- int noofcopies;
- int status;
- }book;
- FILE *librecord;
- void insert();
- void update();
- void SearchBook();
- void request();
- void DisplayBook();
- char info[500];
- int main()
- {
- string uname,pwd;
- int ch;
- cout << "\t \n Library management System \n" ; // prints !!!Hello World!!!
- cout<<"\n Enter Username : ";
- cin>>uname;
- cout<<"\n Enter Password : ";
- cin>>pwd;
- if(uname=="admin123" && pwd=="admin123")
- {
- cout<<"\nYou are logged in as Librarian !!! \n";
- while(1)
- {
- cout<<"\n 1.Insert Book";
- cout<<"\n 2.Display Book";
- cout<<"\n 3.Search Book";
- cout<<"\n 4.Log out";
- cout<<"\n Enter your choice ???";
- cin>>ch;
- switch(ch)
- {
- case 1:
- insert();
- break;
- case 2:
- DisplayBook();
- break;
- case 3:
- SearchBook();
- break;
- case 4:
- return 0;
- break;
- default:
- cout<<"Invalid choice...!";
- }
- }
- }
- if(uname=="student123" && pwd=="student123")
- {
- cout<<"\nYou are logged in as Student !!! \n\n";
- while(1)
- {
- cout<<"\n 1.Search Book";
- cout<<"\n 2.log out\n";
- cout<<"\n Enter your choice ???";
- cin>>ch;
- switch(ch)
- {
- case 1:
- SearchBook();
- break;
- case 2:
- return 0;
- default:
- cout<<"Invalid choice...!";
- }
- }
- }
- return 0;
- }
- void insert()
- {
- int i=0;book.status=IN;
- //opening the librecord file
- librecord = fopen("librecord.txt","a+");
- cout<<"Enter The Name of The Book :\n";
- cin>>book.bname;
- cout<<"Enter The uniqueid of The Book :(Integer) \n";
- cin>>book.bid;
- id_arr[i]=book.bid;
- i++;
- size++;
- cout<<"Enter The Name of Author :\n";
- cin>>book.author;
- cout<<"Enter The Number of copies Of The Book:(Integer)\n";
- cin>>book.noofcopies;
- fprintf(librecord,"\n%s\t%d\t%s\t%d\t",book.bname,book.bid,book.author,book.noofcopies);
- fclose(librecord);
- cout<<"A New Book has been Added Successfully...\n";
- }
- void SearchBook()
- {
- for(int i=0;i<size;i++){
- cout<<id_arr[i];
- }
- }
- void DisplayBook()
- {
- librecord = fopen("librecord.txt","a+");
- cout<<"\nName\tBookid\tAuthor\tCopies\n";
- while(!feof(librecord))
- {
- fgets(info,500,librecord);
- cout<<info;
- }
- fclose(librecord);
- }
Add Comment
Please, Sign In to add comment