logow

Library Management System in C++ With Simple Code..


C++ PROGRAM FOR LIBRARY MANAGEMENT SYSTEM......


C++ SOURCE CODE 

PROGRAM EXPLANATION--------
  • First we create class name books then we declare all function and variables inside the class.
  • Then we define function body of books and ask user to Enter book name , author name , publisher name , book price and Stock.
  • Then we declare function body of display and print details on screen like name of the book,author of the book,publisher of the book,price of the book,stock current availability or present .
  • Then we move to the main function and declare a Array ob[10],int ch for switch case to create user operation and int n for ask user to store number of books at particular time.
  • Then in switch case 3 searching of book char bname[20] for book name and aname[20] for author name .
  • After that we use strcmp() function to compare searching name and saved book name both for book name and author name.
  • If comparing success then we print Book Present otherwise we print Not Present.
  • For user's choice we using do-while loop.
  • So Read carefully Program Explanation before going to check source code...........

SOURCE CODE IS HERE......


#include<iostream>
#include<conio.h>
#include<string.h>
#include<process.h>
using namespace std;

class books {
public:
int stock;
char author[20], publisher[20];
char bookname[20];
float price;
void loadbooks();
void display();
};

void books::loadbooks() {
cout<<"\nEnter Book Name:";
cin>>bookname;
cout<<"\nEnter Author Name:";
cin>>author;
cout<<"\nEnter Publisher Name:";
cin>>publisher;
cout<<"\nEnter Price:";
cin>>price;
cout<<"\nEnter Stock:";
cin>>stock;
cout<<"\n-------------\n";
}

void books::display() {
cout<<"\nName of the Book:"<<bookname;
cout<<"\nAuthor of the Book:"<<author;
cout<<"\nPublisher of the Book:"<<publisher;
cout<<"\nPrice of the Book:"<<price;
cout<<"\nStock Present:"<<stock;
cout<<"\n-------------\n";
}

int main() {
books ob[10];
int ch, n;

do{
cout<<"\n****\n";
cout<<"\n1.Load Books\n2.Display\n3.Search\n4.Exit\n";
cout<<"\n\nEnter your Choice:";
cin>>ch;
switch(ch)
{
case 1: cout<<"Enter Number of Books:";
cin>>n;
for(int i=0;i<n;i++)
ob[i].loadbooks();
break;
case 2:
for(int i=0;i<n;i++)
ob[i].display();
break;
case 3:
char bname[20], aname[20];
cout<<"Enter name of the Book:";
cin>>bname;
cout<<"Enter name of the Author:";
cin>>aname;
for(int i=0;i<n;i++)
{
if(strcmp(bname, ob[i].bookname)==0&&strcmp(aname,ob[i].author))
{
cout<<"\nBook Present\n\n";
cout<<"\nName of the Book:"<<ob[i].bookname;
cout<<"\nAuthor of the Book:"<<ob[i].author;
cout<<"\nPublisher of the Book:"<<ob[i].publisher;
cout<<"\nPrice of the Book:"<<ob[i].price;
cout<<"\nStock Present:"<<ob[i].stock;
cout<<"\n-------------\n";
break;
}
else
{
cout<<"Not Present!!";
break;
}
}
break;
default: cout<<"Enter a valid choice!!";
case 4: exit(1);
}
}while(1);
}


OUTPUT IS GIVEN BELOW---------
**********************************************
 WELCOME TO THE LIBRARY MANAGEMENT SYSTEM
**********************************************

1.Add Books
2.Display
3.Search
4.Exit


Enter your Choice:1
Enter Number of Books:2

Enter Book Name:pc

Enter Author Name:ak

Enter Publisher Name:gold

Enter Price:234

Enter Stock:1

-------------

Enter Book Name:se

Enter Author Name:ag

Enter Publisher Name:bold

Enter Price:342

Enter Stock:2

-------------
**********************************************
 WELCOME TO THE LIBRARY MANAGEMENT SYSTEM
**********************************************

1.Add Books
2.Display
3.Search
4.Exit


Enter your Choice:3
Enter name of the Book:sety 
Enter name of the Author:ag
Not Present!!**********************************************
 WELCOME TO THE LIBRARY MANAGEMENT SYSTEM
**********************************************

1.Add Books
2.Display
3.Search
4.Exit


Enter your Choice:2

Name of the Book:pc
Author of the Book:ak
Publisher of the Book:gold
Price of the Book:234
Stock Present:1
-------------

Name of the Book:se
Author of the Book:ag
Publisher of the Book:bold
Price of the Book:342
Stock Present:2
-------------
**********************************************
 WELCOME TO THE LIBRARY MANAGEMENT SYSTEM
**********************************************

1.Add Books
2.Display
3.Search
4.Exit



Enter your Choice:4
compilation terminated..... 





Also Read--Java Hospital management with source code and output

Also Read--Java Airport Management System Project with Output

So Thanks............

Post a Comment

1 Comments

  1. The case 3 has error please remove else not present and use a flag in the for loop and check if flag changes outside the for loop to c if book was not found.. otherwise no matter how many enteries r present for loop will run only once
    Thank u

    ReplyDelete

Write your comments or feedback here.........