Library Management System Project for Students of XI, CBSE

//Library Management System
//As per the knowledge limit upto 11 Std. CBSE
//Limit upto structure

#include<iostream.h>
#include<string.h>
#include<conio.h>
#include<dos.h>
#include<process.h>
#include<iomanip.h>
#include<stdlib.h>
#define max 100

//Global Variables
//used for personal information, setting username and password.
char developer[]="Narendra Aliani";
char school[]="Pragati Computers, Ahmedabad";
char std[]="(2015-16)";
int roll=10;
char user[]="admin", pwd[]="admin";


//Variable for adding the no. of books
static int n=0;
int m=0;

//Function prototyping area

//Functions for display presentations
void line();
void stars();
void header();
void footer();
void intro();
void login();
void conclude();
void programmer();

//Functions related to data handling
void menu();
void Add();
void Displayall();
void SearchBookID();
void SearchAuthor();
void SearchCategory();
void PriceRange();

//Structure of Book with properties of book
struct Book
{
int BookId;
char Title[20];
char Author[20];
char Category[20];
int Pages;
float Price;

//For adding the books records
void addbook()
{
cout<<"\tEnter Book Id : ";
cin>>BookId;
cout<<"\tEnter Book Title : ";
cin.get();
cin.getline(Title,20);
cout<<"\tEnter Book Author: ";
cin.getline(Author,20);
cout<<"\tEnter Book Category: ";
cin.getline(Category,20);
cout<<"\tEnter No. of Pages : ";
cin>>Pages;
cout<<"\tEnter Price of Book: ";
cin>>Price;
cout<<endl;
}

//For displaying the book details in individual form
void display()
{
cout<<endl;
cout<<"Book ID      : "<<BookId<<endl;
cout<<"Book Title   : "<<Title<<endl;
cout<<"Author Name  : "<<Author<<endl;
cout<<"Category     : "<<Category<<endl;
cout<<"No. of Pages : "<<Pages<<endl;
cout<<"Price of Book: "<<Price<<endl;
}

//For displaying in the tabular form used in Display all function
void show()
{
cout<<endl
   <<setw(5)<<BookId
   <<setw(20)<<Title
   <<setw(20)<<Author
   <<setw(15)<<Category
   <<setw(6)<<Pages
   <<setw(6)<<Price;
}
      }s[max];

//For drawing the random color random design line
void line()
{
randomize();
for(int i=1;i<=80;i++)
{
textcolor(random(15));
if(random(10)%2)
cprintf("=");
else
cprintf("-");
}
}

//For displaying the blinking stars in color
void stars()
{
textcolor(10+BLINK);
for(int i=1;i<=80;i++)
cprintf("*");
textcolor(7);
}

//Setting the header of the page
void header()
{
cout<<"\n\n";
textbackground(4);
textcolor(10);
cprintf("      P R A G A T I   C O M P U T E R S ,  A H M E D A B A D ,  I N D I A .     ");
textcolor(7);
textbackground(0);
cout<<"\n";
}

//Setting the footer to display the information of developer at bottom of page
void footer()
{
textbackground(4);
textcolor(10);
gotoxy(6,24);
cprintf("Made By: %s, %s, %s, Roll No. %d.",developer,school,std,roll);
textcolor(7);
textbackground(0);
}

//Displaying the first page on the screen.
void intro()
{
header();
cout<<endl<<endl;
line();
stars();
line();
gotoxy(15,14);
textcolor(11);
cprintf("L I B R A R Y   M A N A G E M E N T   S Y S T E M");
cout<<"\n\n\n\n";
line();
stars();
line();
footer();
textcolor(7);
getch();
}

void login()
{
//Declared for verifying the password
char usr[20], pwd2[20];
int chance=1,i=0;
//Label assigned for taking input
start:
i=0;
char ch=0;
clrscr();
header();
gotoxy(15,5);
cout<<"Enter User Name    : ";
cin>>usr;
gotoxy(15,6);
cout<<"Enter the password : ";
do
{
ch=getch();
if(ch!=13)
{
pwd2[i++]=ch;
cout<<"*";
}
else
pwd2[i++]='\0';
}while(ch!=13);

if(strcmp(usr,user)==0 && strcmp(pwd2,pwd)==0)
{
gotoxy(15,8);
cout<<"Password Matched....";
for(int i=1;i<=100;i++)
{
delay(10);
gotoxy(15,11);

if(i<100)
cout<<i<<"% Loading...";
else
cout<<i<<"% Loading completed....";
}
gotoxy(15,15);
cout<<"Welcome : "<<user<<" to Library Management System...";
gotoxy(45,25);
textcolor(14);
cprintf("Press any key to continue...");
footer();
textcolor(7);
getch();
}
else
{
gotoxy(15,8);
cout<<"Password Wrong....";
gotoxy(15,10);
cout<<chance<<" used of 3 chances...";
gotoxy(15,12);
cout<<"Enter the correct credentials";
chance++;
getch();
if(chance<=3) goto start;
else
{
gotoxy(15,14);
textcolor(4);
cprintf("You are Unauthorized to access....");
getch();
exit(0);
}
textcolor(7);
}
}

void conclude()
{
clrscr();
header();
line();
stars();
line();
gotoxy(34,10);
textcolor(12+BLINK);
cprintf("T H A N K S");
gotoxy(34,12);
cprintf("   F O R   ");
gotoxy(34,14);
cprintf(" U S I N G ");
cout<<endl<<endl<<endl;
line();
stars();
line();
footer();
getch();
}

void Add()
{
int x;
cout<<"\tEnter the No. of Books you want to enter: ";
cin>>x;
n+=x;
for(int i=m;i<n;i++)
s[i].addbook();
m=m+x;
clrscr();
menu();
}

void SearchBookID()
{
int id;
char found='n';
cout<<"\tEnter the Book ID to be searched in the Lirary: ";
cin>>id;
for(int i=0;i<n;i++)
{
if(s[i].BookId==id)
{
s[i].display();
found='y';
}
}
if(found=='n')
cout<<"\tThe Book ID : "<<id<<" is not in the Library...\n";
getch();
menu();
}

void SearchAuthor()
{
char name[20], found='n';
cout<<"\tEnter the Author to be searched in the Lirary: ";
cin.get();
cin.getline(name,20);
for(int i=0;i<n;i++)
{
if(strcmp(s[i].Author,name)==0)
{
s[i].display();
found='y';
}
}
if(found=='n')
cout<<"\tThe Author "<<name<<" is not in the Library...\n";
getch();
textcolor(7);
menu();
}

void SearchCategory()
{
char name[20], found='n';
cout<<"\tEnter the Category to be searched in the Lirary: ";
cin.get();
cin.getline(name,20);
for(int i=0;i<n;i++)
{
if(strcmp(s[i].Category,name)==0)
{
s[i].display();
found='y';
}
}
if(found=='n')
cout<<"\tThe Category : "<<name<<" is not in the Library...\n";
getch();
textcolor(7);
menu();
}

void PriceRange()
{
float rate1, rate2;
char found='n';
cout<<"\tEnter the Minimum Price of Book: ";
cin>>rate1;
cout<<"\tEnter the Maximum Price of Book: ";
cin>>rate2;
for(int i=0;i<n;i++)
{
if(s[i].Price>=rate1 && s[i].Price<=rate2)
{
s[i].display();
found='y';
}
}
if(found=='n')
cout<<"\tThe Book price between "<<rate1
<<" and " <<rate2<<" is not in the Library...\n";
getch();
clrscr();
menu();
}

void Displayall()
{
clrscr();
header();
cout<<endl
   <<setw(5)<<"I.D."
   <<setw(20)<<"Title"
   <<setw(20)<<"Author"
   <<setw(15)<<"Category"
   <<setw(6)<<"Pages"
   <<setw(6)<<"Price";

for(int i=0;i<n;i++)
{
s[i].show();
}
getch();
clrscr();
textcolor(7);
menu();
}

void menu()
{
clrscr();
int ch;
header();
textcolor(11+BLINK);
gotoxy(15,5);
cprintf("L I B R A R Y   M A N A G E M E N T   S Y S T E M");
cout<<endl;
textcolor(7);
gotoxy(7,7);
cout<<"0. EXIT.";
gotoxy(7,8);
cout<<"1. Add Book Details.";
gotoxy(7,9);
cout<<"2. Search Book by Book ID.";
gotoxy(7,10);
cout<<"3. Search Book by Price Range.";
gotoxy(7,11);
cout<<"4. Search Book by Author.";
gotoxy(7,12);
cout<<"5. Search by Category.";
gotoxy(7,13);
cout<<"6. Display all Books.";
gotoxy(7,14);
cout<<"Enter Your Choice : ";
cin>>ch;
cout<<endl;
switch(ch)
{
case 0: conclude();
exit(0); break;
case 1: Add(); break;
case 2: SearchBookID(); break;
case 3: PriceRange(); break;
case 4: SearchAuthor(); break;
case 5: SearchCategory(); break;
case 6: Displayall(); break;
default: menu();
}
}

void main()
{
textbackground(0);
clrscr();
intro();
footer();
login();
menu();
getch();
}
Powered by Blogger.