diff --git a/Library Management System b/Library Management System new file mode 100644 index 0000000..b5350f4 --- /dev/null +++ b/Library Management System @@ -0,0 +1,809 @@ +#include +#include +#include + +using namespace std; + +class Date{ + private: + int dd; + int mm; + int yy; + void rectifyDate(){ + + if(dd>30){ + dd -= 30; + mm++; + } + + if(mm>12){ + mm -= 12; + yy++; + } + +} + +public: + Date(){ + dd = 1; + mm = 1; + yy = 2023; + + } + + void setDate(){ + cout<<"enter Date: "; + cin>>dd; + cout<<"enter Month: "; + cin>>mm; + cout<<"enter Year: "; + cin>>yy; + } + + void setDate(Date temp){ + dd = temp.dd + 15; + mm = temp.mm; + yy = temp.yy; + rectifyDate(); + } + + void showDate() + { + cout<>Book.title; + cout<<"enter book's author: "; + cin>>Book.author; + cout<<"enter book's publisher: "; + cin>>Book.publisher; + cout<<"enter book's price: "; + cin>>Book.price; + + file.write((char*)&Book, sizeof(BookData)); + file.close(); +} + +void Book :: modifyDetails(){ + fstream fsp; + fsp.open("bookDataBase.dat", ios :: binary | ios :: in | ios :: out | ios :: ate); + + if(!fsp){ + cout<<"Error"<>title; + + while(fsp.read((char*)&Book, sizeof(BookData))){ + if(strcmp(Book.title, title) == 0){ + int position = (-1)*sizeof(BookData); + fsp.seekp(position, ios :: cur); + + cout<<"enter new book's title: "; + cin>>Book.title; + cout<<"enter new book's author: "; + cin>>Book.author; + cout<<"enter new book's publisher: "; + cin>>Book.publisher; + cout<<" enter new book's price: "; + cin>>Book.price; + + cout<<"Record Updated"<>title; + + while(fsp.read((char*)&Book, sizeof(BookData))){ + if(strcmp(Book.title, title) == 0){ + cout<<"Book title: "<>title; + + while(fsp.read((char*)&Book, sizeof(BookData))){ + if(strcmp(Book.title, title) ==0) + { + Flag++; + continue; + } + + temp.write((char*)&Book, sizeof(BookData)); + } + + fsp.close(); + temp.close(); + remove("bookDataBase.dat"); + + if(Flag == 1) + cout<<"Record Deleted"; + + else{ + cout<<"Record Not Found"; + + } + + cin.get(); + cin.get(); + return; + +} + + + +void Book :: viewAllBookDetails(){ + fstream fsp; + fsp.open("bookDataBase.dat", ios :: binary | ios :: in); + + BookData Book; + int choice = 1; + + while(fsp.read((char*)&Book, sizeof(BookData) &&choice)){ + + system("clear"); + cout<<"Book Title: "<>choice; + } + + cin.get(); + cin.get(); + return; +} + +class Student { + public: + void inputDetails(); + void modifyDetails(); + void searchDetails(); + void deleteDetails(); + void viewAllStudentDetails(); +}; + + +void Student :: inputDetails(){ + + fstream file; + file.open("studentDataBase.dat", ios :: out | ios :: app | ios :: binary ); + + if(!file){ + cout<<"Error 404"<>Student.rollNo; + cout<<"enter student's name: "; + cin>>Student.name; + cout<<"enter student's address: "; + cin>>Student.address; + cout<<"enter student's branch: "; + cin>>Student.branch; + + cout<>target; + + StudentData Student; + + while(fp.read((char*)&Student, sizeof(StudentData))){ + if(target == Student.rollNo){ + int position = (-1) * sizeof(StudentData); + fp.seekp(position, ios :: cur); + + cout<<"enter student's new roll no. : "; + cin>>Student.rollNo; + cout<<"enter student's new name: "; + cin>>Student.name; + cout<<"enter student's new address: "; + cin>>Student.address; + cout<<"enter student's new branch: "; + cin>>Student.branch; + + fp.write((char*)&Student, sizeof(StudentData)); + fp.close(); + + cout<<"Record Updatted"<>target; + + StudentData Student; + + while(ofp.read((char*)&Student, sizeof(Student))){ + if(target == Student.rollNo) + { + cout<<"Record Found!"<>choice; + } + return; +} + +void Student :: deleteDetails(){ + + fstream file; + file.open("studentDataBase.dat", ios :: in | ios :: binary); + fstream temp; + temp.open("temp.dat", ios :: out | ios :: binary); + + StudentData Student; + int target; + int flag = 0; + + cout<<"enter roll no. to delete data: "; + cin>>target; + + while(file.read((char*)&Student, sizeof(Student))) + { + if(Student.rollNo == target) + { + flag++; + continue; + } + + temp.write((char*)&Student, sizeof(Student)); + } + + file.close(); + temp.close(); + remove("studentDataBase.dat"); + rename("temp.dat","studentDataBase.dat"); + + if(flag==1) + { + cout<<"Record Deleted"<>rollNo; + + while(sp.read((char*)&Student, sizeof(StudentData))) + { + if(Student.rollNo == rollNo) + { + position = (-1)*sizeof(StudentData); + sp.seekp(position, ios :: cur); + flagS++; + break; + } + } + + if(flagS != 1) + { + cout<<"Record Not Found"<>title; + + while(bp.read((char*)&Book, sizeof(BookData))) + { + if(strcmp(Book.title,title) == 0) + { + position = (-1)*sizeof(BookData); + bp.seekp(position, ios :: cur); + flagB++; + break; + } + } + + if(flagB != 1){ + cout<<"Record Not Found"<>rollNo; + + while(sp.read((char*)&Student, sizeof(StudentData))){ + if(Student.rollNo == rollNo){ + position = (-1)*sizeof(StudentData); + sp.seekp(position, ios :: cur); + flagS++; + break; + + } + } + + if(flagS != 1){ + cout<<"Record Not Found"<>choice; + switch(atoi(choice)) //*atoi() converts numbers in string to integers(i.e "23" to 23) to protect user from giving + // any character input + { + case 1: { + + menu.studentMenu(); + cout<<"Enter your choice: "<>choice; + Student S1; + switch(atoi(choice)) + { + case 1: S1.inputDetails(); + break; + + case 2: S1.modifyDetails(); + break; + + case 3: S1.searchDetails(); + break; + + case 4: S1.deleteDetails(); + break; + + case 5: S1.viewAllStudentDetails(); + break; + + case 6: break; + + default: cout<<"Wrong Input Recieved"<>choice; + Book B1; + switch(atoi(choice)) + { + + case 1: B1.inputDetails(); + break; + + case 2: B1.modifyDetails(); + break; + case 3: B1.searchDetails(); + break; + case 4: B1.deleteDetails(); + break; + + case 5: B1.viewAllBookDetails(); + break; + + case 6: break; + + default: cout<<"Wrong Input Recieved"<>choice; + } + + } + + return 0; + +}