Professional Documents
Culture Documents
#include <iomanip>
#include <fstream>
#include <string>
// Forward declarations
class EmailSender;
class SMSSender;
class EmailSender {
public:
void sendEmail(const string& recipient, const string& subject, const string& message) {
cout << "Email sent to: " << recipient << endl;
};
class SMSSender {
public:
cout << "SMS sent to: " << phoneNumber << endl;
}
};
class LibraryItem {
protected:
string id;
string name;
public:
id = itemId;
name = itemName;
return id;
return name;
};
string author;
public:
void setAuthor(const string& bookAuthor) {
author = bookAuthor;
return author;
void createBook() {
cin.ignore();
getline(cin, name);
getline(cin, author);
void showBook() {
void modifyBook() {
getline(cin, author);
};
class LibraryMember {
protected:
string admissionNo;
string name;
int token;
public:
LibraryMember() : token(0) {}
return token;
void addToken() {
token = 1;
void resetToken() {
token = 0;
admissionNo = admNo;
}
name = userName;
return admissionNo;
return name;
EmailSender emailSender;
SMSSender smsSender;
smsSender.sendSMS(admissionNo, message);
};
class Student : public LibraryMember {
string bookId;
public:
bookId = bookItemId;
return bookId;
void resetToken() {
token = 0;
bookId = "";
void createStudent() {
cin.ignore();
getline(cin, name);
token = 0;
bookId = "";
}
void showStudent() {
cout << "No of Books issued : " << token << endl;
if (token == 1)
void modifyStudent() {
getline(cin, name);
};
Book book;
Student student;
class CreateRecord{
public:
void writeBook() {
char ch;
do {
system("cls");
book.createBook();
bookFile.write(reinterpret_cast<char*>(&book), sizeof(Book));
cout << "Do you want to add more records? (y/n): ";
cin >> ch;
cin.ignore();
bookFile.close();
void writeStudent() {
char ch;
do {
system("cls");
student.createStudent();
studentFile.write(reinterpret_cast<char*>(&student), sizeof(Student));
cout << "Do you want to add more records? (y/n): ";
cin.ignore();
studentFile.close();
};
class Modify{
public:
void modifyBook() {
string bookNo;
system("cls");
cin.ignore();
if (book.getId() == bookNo) {
book.showBook();
book.modifyBook();
bookFile.seekp(pos, ios::beg);
bookFile.write(reinterpret_cast<char*>(&book), sizeof(Book));
found = true;
bookFile.close();
if (!found)
system("pause");
void modifyStudent() {
string admissionNo;
system("cls");
cin.ignore();
if (student.getAdmissionNo() == admissionNo) {
student.showStudent();
student.modifyStudent();
studentFile.seekp(pos, ios::beg);
studentFile.write(reinterpret_cast<char*>(&student), sizeof(Student));
found = true;
studentFile.close();
if (!found)
system("pause");
};
class Deletion{
public:
void deleteStudent() {
string admissionNo;
system("cls");
cin.ignore();
fstream tempFile;
tempFile.open("Temp.dat", ios::out);
if (student.getAdmissionNo() != admissionNo)
tempFile.write(reinterpret_cast<char*>(&student), sizeof(Student));
else
found = true;
tempFile.close();
studentFile.close();
remove("student.dat");
rename("Temp.dat", "student.dat");
if (found)
else
system("pause");
void deleteBook() {
string bookNo;
system("cls");
cout << "\nEnter The Book id of the Book You Want To Delete: ";
cin.ignore();
fstream tempFile;
tempFile.open("Temp.dat", ios::out);
if (book.getId() != bookNo)
tempFile.write(reinterpret_cast<char*>(&book), sizeof(Book));
tempFile.close();
bookFile.close();
remove("book.dat");
rename("Temp.dat", "book.dat");
system("pause");
};
class DeleteAll {
public:
void deleteAllStudents() {
char confirm;
system("cls");
cout << "Are you sure you want to delete all student records? (y/n): ";
cin.ignore();
remove("student.dat");
else {
system("pause");
void deleteAllBooks() {
char confirm;
system("cls");
cout << "Are you sure you want to delete all book records? (y/n): ";
cin.ignore();
remove("book.dat");
cout << "All book records have been deleted.\n";
else {
system("pause");
};
class Display{
public:
void displayAllStudents() {
system("cls");
studentFile.open("student.dat", ios::in);
if (!studentFile) {
system("pause");
return;
cout <<
"===============================================================================\n";
cout << setw(15) << left << "Admission No." << setw(20) << "Name" << setw(15) << "Book Issued" <<
setw(15) << "Book ID\n";
cout <<
"===============================================================================\n";
student.showStudent();
}
studentFile.close();
system("pause");
system("cls");
void displayAllBooks() {
system("cls");
bookFile.open("book.dat", ios::in);
if (!bookFile) {
system("pause");
return;
cout << setw(10) << "Book Number" << setw(30) << "Book Name" << setw(30) << "Author\n";
book.showBook();
bookFile.close();
system("pause");
system("cls");
};
class BookHandling{
public:
void bookIssue() {
system("cls");
cin.ignore();
if (student.getAdmissionNo() == admissionNo) {
studentFound = true;
if (student.getToken() == 0) {
cin.ignore();
if (book.getId() == bookNo) {
bookFound = true;
if (student.getToken() == 0) {
student.addToken();
student.setBookId(book.getId());
studentFile.seekp(pos, ios::beg);
studentFile.write(reinterpret_cast<char*>(&student), sizeof(Student));
cout << "\nBook Issued Successfully\n";
} else {
if (!bookFound) {
bookFile.clear();
bookFile.seekg(0, ios::beg);
} else {
studentFile.close();
bookFile.close();
system("pause");
void bookDeposit() {
system("cls");
if (student.getAdmissionNo() == admissionNo) {
studentFound = true;
if (student.getToken() == 1) {
cin.ignore();
if (book.getId() == bookNo) {
bookFound = true;
student.resetToken();
student.setBookId("");
studentFile.seekp(pos, ios::beg);
studentFile.write(reinterpret_cast<char*>(&student), sizeof(Student));
if (!bookFound) {
bookFile.clear();
bookFile.seekg(0, ios::beg);
} else {
studentFile.close();
bookFile.close();
system("pause");
};
class Search{
public:
void searchStudent() {
string admissionNo;
system("cls");
cin.ignore();
studentFile.open("student.dat", ios::in);
if (student.getAdmissionNo() == admissionNo) {
student.showStudent();
found = true;
break;
}
studentFile.close();
if (!found)
system("pause");
void searchBook() {
string bookNo;
system("cls");
cin.ignore();
bookFile.open("book.dat", ios::in);
if (book.getId() == bookNo) {
book.showBook();
found = true;
break;
bookFile.close();
if (!found)
system("pause");
}
};
int main() {
int choice;
Search s;
Display d;
BookHandling bh;
CreateRecord cr;
Modify m;
Deletion del;
DeleteAll da;
while (true) {
system("cls");
switch (choice) {
case 1:
bh.bookIssue();
break;
case 2:
bh.bookDeposit();
break;
case 3:
s.searchBook();
break;
case 4:
s.searchStudent();
break;
case 5:
cr.writeStudent();
break;
case 6:
cr.writeBook();
break;
case 7:
d.displayAllBooks();
break;
case 8:
d.displayAllStudents();
break;
case 9:
m.modifyBook();
break;
case 10:
m.modifyStudent();
break;
case 11:
del.deleteBook();
break;
case 12:
del.deleteStudent();
break;
case 13:
exit(0);
case 14:
da.deleteAllStudents();
break;
case 15:
da.deleteAllBooks();
break;
return 0;