0% found this document useful (0 votes)
37 views

Document 5

This document defines classes for a library management system including Book, Student, LibraryMember, and others. It includes methods to create, read, update, and delete records for books and students stored in external data files. Other classes handle various administrative tasks like adding, modifying, and deleting records from the data files.

Uploaded by

honey.qazi33
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Document 5

This document defines classes for a library management system including Book, Student, LibraryMember, and others. It includes methods to create, read, update, and delete records for books and students stored in external data files. Other classes handle various administrative tasks like adding, modifying, and deleting records from the data files.

Uploaded by

honey.qazi33
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

#include <iostream>

#include <iomanip>

#include <fstream>

#include <string>

using namespace std;

// Forward declarations

class EmailSender;

class SMSSender;

class EmailSender {

public:

void sendEmail(const string& recipient, const string& subject, const string& message) {

// Placeholder code for sending an email

cout << "Email sent to: " << recipient << endl;

cout << "Subject: " << subject << endl;

cout << "Message: " << message << endl;

cout << "==============================" << endl;

};

class SMSSender {

public:

void sendSMS(const string& phoneNumber, const string& message) {

// Placeholder code for sending an SMS

cout << "SMS sent to: " << phoneNumber << endl;

cout << "Message: " << message << endl;

cout << "==============================" << endl;

}
};

class LibraryItem {

protected:

string id;

string name;

public:

void setId(const string& itemId) {

id = itemId;

void setName(const string& itemName) {

name = itemName;

string getId() const {

return id;

string getName() const {

return name;

};

class Book : public LibraryItem {

string author;

public:
void setAuthor(const string& bookAuthor) {

author = bookAuthor;

string getAuthor() const {

return author;

void createBook() {

cout << "\nNEW BOOK ENTRY...\n";

cout << "Enter The book id: ";

cin >> id;

cin.ignore();

cout << "Enter The Name of The Book: ";

getline(cin, name);

cout << "Enter The Author's Name: ";

getline(cin, author);

cout << "\nBook Created..\n";

void showBook() {

cout << "Book ID: " << id << endl;

cout << "Book Name: " << name << endl;

cout << "Author Name: " << author << endl;

void modifyBook() {

cout << "Book ID: " << id << endl;

cout << "Modify Book Name: ";


getline(cin, name);

cout << "Modify Author's Name of Book: ";

getline(cin, author);

};

class LibraryMember {

protected:

string admissionNo;

string name;

int token;

public:

LibraryMember() : token(0) {}

int getToken() const {

return token;

void addToken() {

token = 1;

void resetToken() {

token = 0;

void setAdmissionNo(const string& admNo) {

admissionNo = admNo;
}

void setName(const string& userName) {

name = userName;

string getAdmissionNo() const {

return admissionNo;

string getName() const {

return name;

void sendEmail(const string& subject, const string& message) {

// Code for sending an email notification using an EmailSender class

// Replace the placeholders with the actual implementation

EmailSender emailSender;

emailSender.sendEmail(admissionNo, subject, message);

void sendSMS(const string& message) {

// Code for sending an SMS notification using an SMSSender class

// Replace the placeholders with the actual implementation

SMSSender smsSender;

smsSender.sendSMS(admissionNo, message);

};
class Student : public LibraryMember {

string bookId;

public:

void setBookId(const string& bookItemId) {

bookId = bookItemId;

string getBookId() const {

return bookId;

void resetToken() {

token = 0;

bookId = "";

void createStudent() {

cout << "\nNEW STUDENT ENTRY...\n";

cout << "Enter The admission no.: ";

cin >> admissionNo;

cin.ignore();

cout << "Enter The Name of The Student: ";

getline(cin, name);

token = 0;

bookId = "";

cout << "\nStudent Record Created..\n";

}
void showStudent() {

cout << "Admission no. : " << admissionNo << endl;

cout << "Student Name : " << name << endl;

cout << "No of Books issued : " << token << endl;

if (token == 1)

cout << "Book ID: " << bookId << endl;

void modifyStudent() {

cout << "Admission no. : " << admissionNo << endl;

cout << "Modify Student Name : ";

getline(cin, name);

};

fstream bookFile, studentFile;

Book book;

Student student;

class CreateRecord{

public:

void writeBook() {

char ch;

bookFile.open("book.dat", ios::out | ios::app);

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();

} while (ch == 'y' || ch == 'Y');

bookFile.close();

void writeStudent() {

char ch;

studentFile.open("student.dat", ios::out | ios::app);

do {

system("cls");

student.createStudent();

studentFile.write(reinterpret_cast<char*>(&student), sizeof(Student));

cout << "Do you want to add more records? (y/n): ";

cin >> ch;

cin.ignore();

} while (ch == 'y' || ch == 'Y');

studentFile.close();

};

class Modify{

public:

void modifyBook() {

string bookNo;

bool found = false;

system("cls");

cout << "\nMODIFY BOOK RECORD....\n";


cout << "\nEnter The book id of The book: ";

cin >> bookNo;

cin.ignore();

bookFile.open("book.dat", ios::in | ios::out);

while (bookFile.read(reinterpret_cast<char*>(&book), sizeof(Book)) && !found) {

if (book.getId() == bookNo) {

book.showBook();

cout << "\nEnter The New Details of book" << endl;

book.modifyBook();

int pos = static_cast<int>(bookFile.tellg()) - static_cast<int>(sizeof(Book));

bookFile.seekp(pos, ios::beg);

bookFile.write(reinterpret_cast<char*>(&book), sizeof(Book));

cout << "\nRecord Updated\n";

found = true;

bookFile.close();

if (!found)

cout << "Record Not Found\n";

system("pause");

void modifyStudent() {

string admissionNo;

bool found = false;

system("cls");

cout << "\nMODIFY STUDENT RECORD...\n";

cout << "\nEnter The admission no. of The student: ";


cin >> admissionNo;

cin.ignore();

studentFile.open("student.dat", ios::in | ios::out);

while (studentFile.read(reinterpret_cast<char*>(&student), sizeof(Student)) && !found) {

if (student.getAdmissionNo() == admissionNo) {

student.showStudent();

cout << "\nEnter The New Details of student\n";

student.modifyStudent();

int pos = static_cast<int>(studentFile.tellg()) - static_cast<int>(sizeof(Student));

studentFile.seekp(pos, ios::beg);

studentFile.write(reinterpret_cast<char*>(&student), sizeof(Student));

cout << "\nRecord Updated\n";

found = true;

studentFile.close();

if (!found)

cout << "Record Not Found\n";

system("pause");

};

class Deletion{

public:

void deleteStudent() {

string admissionNo;

bool found = false;

system("cls");

cout << "\nDELETE STUDENT...\n";


cout << "\nEnter The admission no. of The student You Want To Delete: ";

cin >> admissionNo;

cin.ignore();

studentFile.open("student.dat", ios::in | ios::out);

fstream tempFile;

tempFile.open("Temp.dat", ios::out);

while (studentFile.read(reinterpret_cast<char*>(&student), sizeof(Student))) {

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)

cout << "Record Deleted\n";

else

cout << "Record not found\n";

system("pause");

void deleteBook() {
string bookNo;

system("cls");

cout << "\nDELETE BOOK...\n";

cout << "\nEnter The Book id of the Book You Want To Delete: ";

cin >> bookNo;

cin.ignore();

bookFile.open("book.dat", ios::in | ios::out);

fstream tempFile;

tempFile.open("Temp.dat", ios::out);

while (bookFile.read(reinterpret_cast<char*>(&book), sizeof(Book))) {

if (book.getId() != bookNo)

tempFile.write(reinterpret_cast<char*>(&book), sizeof(Book));

tempFile.close();

bookFile.close();

remove("book.dat");

rename("Temp.dat", "book.dat");

cout << "Record Deleted\n";

system("pause");

};

class DeleteAll {

public:
void deleteAllStudents() {

char confirm;

system("cls");

cout << "\nDELETE ALL STUDENTS...\n";

cout << "Are you sure you want to delete all student records? (y/n): ";

cin >> confirm;

cin.ignore();

if (confirm == 'y' || confirm == 'Y') {

remove("student.dat");

cout << "All student records have been deleted.\n";

else {

cout << "Deletion canceled.\n";

system("pause");

void deleteAllBooks() {

char confirm;

system("cls");

cout << "\nDELETE ALL BOOKS...\n";

cout << "Are you sure you want to delete all book records? (y/n): ";

cin >> confirm;

cin.ignore();

if (confirm == 'y' || confirm == 'Y') {

remove("book.dat");
cout << "All book records have been deleted.\n";

else {

cout << "Deletion canceled.\n";

system("pause");

};

class Display{

public:

void displayAllStudents() {

system("cls");

studentFile.open("student.dat", ios::in);

if (!studentFile) {

cout << "Student record is empty\n";

system("pause");

return;

cout << "\nSTUDENT LIST\n";

cout <<
"===============================================================================\n";

cout << setw(15) << left << "Admission No." << setw(20) << "Name" << setw(15) << "Book Issued" <<
setw(15) << "Book ID\n";

cout <<
"===============================================================================\n";

while (studentFile.read(reinterpret_cast<char*>(&student), sizeof(Student))) {

student.showStudent();

}
studentFile.close();

system("pause");

system("cls");

void displayAllBooks() {

system("cls");

bookFile.open("book.dat", ios::in);

if (!bookFile) {

cout << "Book record is empty\n";

system("pause");

return;

cout << "\nBOOK LIST\n";

cout << "=========================================================================\n";

cout << setw(10) << "Book Number" << setw(30) << "Book Name" << setw(30) << "Author\n";

cout << "=========================================================================\n";

while (bookFile.read(reinterpret_cast<char*>(&book), sizeof(Book))) {

book.showBook();

bookFile.close();

system("pause");

system("cls");

};

class BookHandling{

public:

void bookIssue() {

string admissionNo, bookNo;


bool studentFound = false, bookFound = false;

system("cls");

cout << "\nBOOK ISSUE...\n";

cout << "\nEnter The student's admission no.: ";

cin >> admissionNo;

cin.ignore();

studentFile.open("student.dat", ios::in | ios::out);

bookFile.open("book.dat", ios::in | ios::out);

while (studentFile.read(reinterpret_cast<char*>(&student), sizeof(Student)) && !studentFound) {

if (student.getAdmissionNo() == admissionNo) {

studentFound = true;

if (student.getToken() == 0) {

cout << "Enter the book id: ";

cin >> bookNo;

cin.ignore();

while (bookFile.read(reinterpret_cast<char*>(&book), sizeof(Book)) && !bookFound) {

if (book.getId() == bookNo) {

bookFound = true;

if (student.getToken() == 0) {

student.addToken();

student.setBookId(book.getId());

int pos = static_cast<int>(studentFile.tellg()) - static_cast<int>(sizeof(Student));

studentFile.seekp(pos, ios::beg);

studentFile.write(reinterpret_cast<char*>(&student), sizeof(Student));
cout << "\nBook Issued Successfully\n";

} else {

cout << "You have already issued a book\n";

if (!bookFound) {

cout << "Book does not exist\n";

bookFile.clear();

bookFile.seekg(0, ios::beg);

} else {

cout << "You have already issued a book\n";

studentFile.close();

bookFile.close();

system("pause");

void bookDeposit() {

string admissionNo, bookNo;

bool studentFound = false, bookFound = false;

system("cls");

cout << "\nBOOK DEPOSIT...\n";

cout << "\nEnter The student's admission no.: ";

cin >> admissionNo;


cin.ignore();

studentFile.open("student.dat", ios::in | ios::out);

bookFile.open("book.dat", ios::in | ios::out);

while (studentFile.read(reinterpret_cast<char*>(&student), sizeof(Student)) && !studentFound) {

if (student.getAdmissionNo() == admissionNo) {

studentFound = true;

if (student.getToken() == 1) {

cout << "Enter the book id: ";

cin >> bookNo;

cin.ignore();

while (bookFile.read(reinterpret_cast<char*>(&book), sizeof(Book)) && !bookFound) {

if (book.getId() == bookNo) {

bookFound = true;

student.resetToken();

student.setBookId("");

int pos = static_cast<int>(studentFile.tellg()) - static_cast<int>(sizeof(Student));

studentFile.seekp(pos, ios::beg);

studentFile.write(reinterpret_cast<char*>(&student), sizeof(Student));

cout << "\nBook Deposited Successfully\n";

if (!bookFound) {

cout << "Book does not exist\n";

bookFile.clear();
bookFile.seekg(0, ios::beg);

} else {

cout << "No book is issued to this student\n";

studentFile.close();

bookFile.close();

system("pause");

};

class Search{

public:

void searchStudent() {

string admissionNo;

bool found = false;

system("cls");

cout << "\nSEARCH STUDENT...\n";

cout << "\nEnter The admission no. of The student: ";

cin >> admissionNo;

cin.ignore();

studentFile.open("student.dat", ios::in);

while (studentFile.read(reinterpret_cast<char*>(&student), sizeof(Student))) {

if (student.getAdmissionNo() == admissionNo) {

student.showStudent();

found = true;

break;
}

studentFile.close();

if (!found)

cout << "Student does not exist\n";

system("pause");

void searchBook() {

string bookNo;

bool found = false;

system("cls");

cout << "\nSEARCH BOOK...\n";

cout << "\nEnter The book id: ";

cin >> bookNo;

cin.ignore();

bookFile.open("book.dat", ios::in);

while (bookFile.read(reinterpret_cast<char*>(&book), sizeof(Book))) {

if (book.getId() == bookNo) {

book.showBook();

found = true;

break;

bookFile.close();

if (!found)

cout << "Book does not exist\n";

system("pause");
}

};

int main() {

int choice;

Search s;

Display d;

BookHandling bh;

CreateRecord cr;

Modify m;

Deletion del;

DeleteAll da;

while (true) {

system("cls");

cout << "\n\n\n\tMAIN MENU";

cout << "\n\n\t01. BOOK ISSUE";

cout << "\n\n\t02. BOOK DEPOSIT";

cout << "\n\n\t03. SEARCH BOOK";

cout << "\n\n\t04. SEARCH STUDENT";

cout << "\n\n\t05. CREATE STUDENT RECORD";

cout << "\n\n\t06. CREATE BOOK RECORD";

cout << "\n\n\t07. DISPLAY ALL BOOKS";

cout << "\n\n\t08. DISPLAY ALL STUDENTS";

cout << "\n\n\t09. MODIFY BOOK RECORD";

cout << "\n\n\t10. MODIFY STUDENT RECORD";

cout << "\n\n\t11. DELETE BOOK RECORD";

cout << "\n\n\t12. DELETE STUDENT RECORD";

cout << "\n\n\t13. EXIT";


cout << "\n\n\t14. DELETE ALL STUDENTS";

cout << "\n\n\t15. DELETE ALL BOOKS";

cout << "\n\n\tPlease Select Your Option (1-13): ";

cin >> choice;

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;

You might also like