Library Management System using Single Link list

 Library Management System using Link list


#include<iostream>

#include<string>

using namespace std;

class Books{

public:

	int ISBN;

	string Name, AName, PName, IDate, RDate;

	Books *next;

	Books()

	{

		ISBN = 0;

		Name, AName, PName, IDate, RDate = " ";

	}

}; 

class Library{

public:

	Books *head = NULL; int size;

	void CreateBook()

	{	

		cout << "How many books do you want to enter:"; cin >> size; cin.ignore();

		for (int i = 0; i < size; i++)

		{

			cout << endl << endl;

			Books *tempBook = new Books;

			cout << "Enter the isbn number of book(in int):"; cin >> tempBook->ISBN; cin.ignore();

			cout << "Enter the name of the book:"; getline(cin, tempBook->Name);

			cout << "Enter the auther name of the book:"; getline(cin, tempBook->AName);

			cout << "Enter the publisher name of the author:"; getline(cin, tempBook->PName);

			cout << "Enter the issue date of the book:"; getline(cin, tempBook->IDate);

			cout << "Enter the return date of the book:"; getline(cin, tempBook->RDate);

			if (head == NULL)

			{

				tempBook->next = NULL;

				head = tempBook;

			}

			else

			{

				tempBook->next = head;

				head = tempBook;

			}

		}

		cout << "Books created successfully" << endl;

	}

	void insertBook()

	{

		cout << "How many books do you want to insert:"; cin >> size; cin.ignore();

		for (int i = 0; i < size; i++)

		{

			cout << endl << endl;

			Books *tempBook = new Books;

			cout << "Enter the isbn number of book to insert(in int):"; cin >> tempBook->ISBN; cin.ignore();

			cout << "Enter the name of the book to insert:"; getline(cin, tempBook->Name);

			cout << "Enter the auther name of the book to insert:"; getline(cin, tempBook->AName);

			cout << "Enter the publisher name of the author to insert:"; getline(cin, tempBook->PName);

			cout << "Enter the issue date of the book to insert:"; getline(cin, tempBook->IDate);

			cout << "Enter the return date of the book to insert:"; getline(cin, tempBook->RDate);

			if (head == NULL)

			{

				tempBook->next = NULL;

				head = tempBook;

			}

			else

			{

				tempBook->next = head;

				head = tempBook;

			}

			cout << "Books inserted successfully" << endl;

		}

	}

	void retrieveBook()

	{

		Books *temp = new Books;

		temp = head;

		system("pause");

		while (temp != NULL)

		{

			cout << endl << endl;

			cout << "Isbn number of the book is(in int):" << temp->ISBN << endl;

			cout << "Name of the book is:" << temp->Name << endl;

			cout << "Author name of the book is:" << temp->AName << endl;

			cout << "Publisher name of the book is:" << temp->PName << endl;

			cout << "Issue date of the book is:" << temp->IDate << endl;

			cout << "Return date of the book is:" << temp->RDate << endl;

			temp = temp->next;

		}

	}

	void updateBook()

	{

		int isb; int flag=0;

		cout << endl;

		cout << "Enter the isbn number to update the book:"; cin >> isb; cin.ignore();

		Books *temp = new Books;

		temp = head;

		while (temp != NULL)

		{

			if (isb == temp->ISBN)

			{

				cout << "Enter the name of the book to update:"; getline(cin, temp->Name);

				cout << "Enter the auther name of the book to update:"; getline(cin, temp->AName);

				cout << "Enter the publisher name of the author to update:"; getline(cin, temp->PName);

				cout << "Enter the issue date of the book to update:"; getline(cin, temp->IDate);

				cout << "Enter the return date of the book to update:"; getline(cin, temp->RDate);

				flag = 1;

			}

		

			temp = temp->next;

		}

		if (flag == 0)

		{

			cout << "Book not found" << endl;

		}

	}

	void searchBook()

	{

		int isb; int flag = 0;

		cout << endl;

		cout << "Enter the isbn number to search the book:"; cin >> isb; cin.ignore();

		Books *temp = new Books;

		temp = head;

		while (temp != NULL)

		{

			if (isb == temp->ISBN)

			{

				cout << "Name of the book to search:" << temp->Name << endl;

				cout << "Author name of the book to search:" << temp->AName << endl;

				cout << "Publisher name of the book to search:" << temp->PName << endl;

				cout << "Issue date of the book to search:" << temp->IDate << endl;

				cout << "Return date of the book to search:" << temp->RDate << endl;

				cout << endl;

				cout << "press enter to contineue" << endl;

				cin.get();

				flag = 1;

			}



			temp = temp->next;

		}

		if (flag == 0)

		{

			cout << "Book not found" << endl;

		}

	}

};

int main()

{

	Library l1;

	l1.CreateBook();

	int a = 0;

while (a != 5){

			system("cls");

			cout << "***************************************" << endl;

			cout << "Enter the Manu" << endl;

			cout << "Enter 1 to insert book" << endl;

			cout << "Enter 2 to update book" << endl;

			cout << "Enter 3 to search book" << endl;

			cout << "Enter 4 to retrieve book" << endl;

			cout << "Enter 5 to cancel book" << endl;

			cout << "***************************************" << endl;

			cin >> a; cin.ignore();

			switch (a)

			{

			case 1:

			{

					  l1.insertBook();

					  break;

			}

			case 2:

			{

					  l1.updateBook();

					  break;

			}

			case 3:

			{

					  l1.searchBook();

					  break;

			}

			case 4:

			{

					  l1.retrieveBook();

					  break;

			}

			case 5:

			{

					  cout << "Thank you so Much for our services" << endl;

					  cout << "Press Enter to cancel" << endl;

					  system("pause");

					  break;

			}

			default:

			{

					   cout << "Option Not availabale" << endl;

					   cout << "Sorry!!!" << endl;

					   a = 5;

					   break;

			}

			}

		}

	getchar();

	getchar();

	return 0;

}     

          

       
 

Comments

Popular posts from this blog

Multiple inheritance,friend function and multiple file in oop(object oriented programming)

Concepts of OOP (object oriented programming)

Concepts in c++........