Practical No-03 Implementing a Library Management System Using Advanced C++ OOP Concepts
1.
Class: S.Y.B. Tech.Semester: III
Subject: Object Oriented Programming Laboratory (PCIT212)
Practical No.: 03
CO1: Develop C++ programs using fundamental programming constructs and object-oriented concepts
for solving practical problems. (BTL-Apply)
---------------------------------------------------------------------------------------------------------------------------------------
1. Aim
To implement a Library Management System using function overloading, operator overloading, abstract
classes, and pure virtual functions in C++.
2. Course Outcome Mapping
CO1: Develop C++ programs using fundamental programming constructs and object-oriented concepts for
solving practical problems.
3. Learning Objectives
After completing this experiment, students will be able to:
1. Understand the concept of function overloading.
2. Implement operator overloading in C++.
3. Understand abstract classes and pure virtual functions.
4. Develop reusable object-oriented programs.
5. Design a simple Library Management System.
6. Apply polymorphism in real-world applications.
4. Learning Outcomes
Upon successful completion of this experiment, students will be able to:
1. Implement overloaded functions.
2. Overload operators in C++.
3. Create abstract classes with pure virtual functions.
4. Develop a Library Management application.
5. Analyze and debug object-oriented programs.
Sanjivani Rural Education Society’s
Sanjivani College of Engineering, Kopargaon-423603
(An Autonomous Institute Affiliated to Savitribai Phule Pune University, Pune)
NAAC ‘A’ Grade Accredited, ISO 2001:2018 Certified
Department of Information Technology
NBA Accredited-UG Programme
2.
5. Software andHardware Requirements
1. Software Requirements
Operating System: Windows/Linux
Compiler: GCC, MinGW, Code::Blocks, Visual Studio Code
Programming Language: C++
2. Hardware Requirements
Intel Core i3 Processor or higher
4 GB RAM minimum
10 GB free disk space
6. Real-Time Industry Scenario
Modern libraries in colleges, universities, and public institutions use Library Management Systems to
maintain book records, issue books, and return books efficiently. Systems such as Koha and SOUL
automate library operations and improve record management. This experiment demonstrates a simplified
version of such a system using object-oriented programming concepts.
7. Theory
7.1 Function Overloading
Definition
Function overloading allows multiple functions to have the same name with different parameter lists.
Syntax:
display();
display(int);
Industry Usage
Used to perform similar operations with different inputs.
7.2 Operator Overloading
Definition
Operator overloading gives new meaning to existing operators for user-defined objects.
Syntax
returnType operator+(ClassName obj);
3.
Example
Compare two booksusing ==.
7.3 Abstract Class
Definition
A class containing at least one pure virtual function is called an abstract class.
Syntax
class Library
{
public:
virtual void display() = 0;
};
7.4 Pure Virtual Function
Definition
A pure virtual function has no implementation in the base class and must be implemented in the derived
class.
Syntax
virtual void display() = 0;
Advantages
Supports runtime polymorphism
Provides a common interface
Improves code reusability
8. Problem Statement
Design and implement a Library Management System using C++.
The system should:
1. Accept book details.
2. Display book details.
3. Demonstrate function overloading.
4. Compare book IDs using operator overloading.
5. Implement an abstract class with a pure virtual function.
4.
9. Algorithm
1. Start.
2.Create an abstract base class.
3. Declare a pure virtual function.
4. Create a derived class Book.
5. Read book details.
6. Overload the display() function.
7. Overload the == operator.
8. Display book details.
9. Compare two books.
10. Stop.
10. Pseudocode
BEGIN
Create abstract class Library
Create derived class Book
Input Book ID and Name
Display Book Details
Display Book Details with Author
(Function Overloading)
Compare two Book IDs
(Operator Overloading)
Display Comparison Result
END
11. Sample Code
#include <iostream>
#include <string>
using namespace std;
// Abstract Class
class Library
{
public:
virtual void display() = 0; // Pure Virtual Function
5.
};
// Derived Class
classBook : public Library
{
private:
int bookId;
string bookName;
string author;
public:
// Function to accept book details
void getData()
{
cout << "nEnter Book ID : ";
cin >> bookId;
cin.ignore();
cout << "Enter Book Name : ";
getline(cin, bookName);
cout << "Enter Author Name : ";
getline(cin, author);
}
// Function Overloading
void display()
{
cout << "nBook ID : " << bookId;
cout << "nBook Name : " << bookName;
}
// Overloaded display function
6.
void display(int)
{
display();
cout <<"nAuthor Name : " << author;
}
// Operator Overloading
bool operator==(Book b)
{
if(bookId == b.bookId)
return true;
else
return false;
}
};
int main()
{
Book book1, book2;
cout << "nEnter Details of Book 1";
book1.getData();
cout << "nEnter Details of Book 2";
book2.getData();
cout << "nn===== BOOK DETAILS =====";
cout << "nnBook 1";
book1.display(1); // Function Overloading
cout << "nnBook 2";
book2.display(1);
cout << "nn===== BOOK COMPARISON =====";
7.
if(book1 == book2)// Operator Overloading
cout << "nBoth Books have the Same Book ID.";
else
cout << "nBook IDs are Different.";
return 0;
}
Input:
Enter Details of Book 1
Enter Book ID : 101
Enter Book Name : Object Oriented Programming
Enter Author Name : E. Balagurusamy
Enter Details of Book 2
Enter Book ID : 102
Enter Book Name : C++ Primer
Enter Author Name : Stanley Lippman
Output
===== BOOK DETAILS =====
Book 1
Book ID : 101
Book Name : Object Oriented Programming
Author Name : E. Balagurusamy
Book 2
Book ID : 102
Book Name : C++ Primer
Author Name : Stanley Lippman
8.
===== BOOK COMPARISON=====
Book IDs are Different.
12. Conclusion
Thus, a Library Management System was successfully implemented using function overloading,
operator overloading, abstract classes, and pure virtual functions. The program demonstrated how
object-oriented programming concepts improve code reusability, extensibility, and maintainability in real-
world library applications.
9.
Text Books:
1. ObjectOriented Programming with C++, E. Balagurusamy, McGraw Hill Education, 8th Edition,
2023.
2. Mastering C++, K. R. Venugopal and Rajkumar Buyya, McGraw Hill Education, 2nd Edition,
2017.
3. Programming with C++, D. Ravichandran, McGraw Hill Education, 3rd Edition, 2018.
Reference Books:
1. Programming Principles and Practice Using C++, Pearson Education, 3rd Edition, 2024.
2. The C++ Programming Language, Bjarne Stroustrup, Addison-Wesley Professional, 4th Edition,
2013.
3. C++ Primer, Stanley B. Lippman, Josée Lajoie, and Barbara E. Moo, Pearson Education, 5th
Edition, 2012.
4. Object-Oriented Programming in C++, Robert Lafore, SAMS Publishing, 4th Edition, 2002.
Prepared By, Approved By,
Mr.A.S.Dalvi Dr. M. A. Jawale
Subject In-charge HOD-IT