Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » ProjectsRSS Feeds

Book Store Management

Posted By: Easy Tutor     Category: C Programming     Views: 21544

PROGRAM WHICH WOULD STORE THE DETAILS OF THE BOOK SUCH AS THE BOOKNAME,AUTHOR NAME,PUBLISHER,PRICE AND NUMBER OF COPIES IN THE DATABASE.IT HAS THE FACILITY OF ALLOWING THE USERS WHO GIVES THE CORRECT PASSWORD. IF THE PASSWORD IS NOT RIGHT THEY WILL NOT BE ALLOWED. AFTER LOGIN THE USER CAN INSERT THE DETAILS OF AN NEW BOOK OR UPDATE THE EXISTING RECORD OR SEARCH FOR A PARTICULAR BOOK OR DISPLAY ALL THE RECORDS OR DELETE ANY RECORD.

Code for Book Store Management in C Programming

/*        Password to run this program is 1234*/

#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<iomanip.h>
#include<dos.h>

class group
{
    protected:
    struct books
    {
     char flag;
     char bname[50];
     char aname[50];
     char pubname[50];
     int price;
     int noofbooks;
    }b;
     fstream file;
    public:
    group();
    void insert();
    void display();
    void update();
    void search();
    void deletion();
    void exit();
};

void main()
{
    int choice;
    char pass[20]; 
    clrscr(); 
    group g; 
y:      clrscr(); 
    gotoxy(12,12); 
    cout<<"ENTER THE PASSWORD  :"; 
    cin>>pass; 
    if(strcmp(pass,"1234")==0) 
    goto z; 
    else 
    { 
        gotoxy(12,12); 
        cout<<"INCORRECT PASSWORD"; 
        sound(1000); 
        delay(1000); 
        nosound(); 
        clrscr(); 
        goto y; 
    } 
    //group g; 
z:      do 
    { 
      clrscr(); 
      gotoxy(30,4); 
      cout<<"*********************"; 
      gotoxy(30,5); 
      cout<<"BOOK STORE MANAGEMENT"; 
      gotoxy(30,6); 
      cout<<"*********************"; 
      gotoxy(30,10); 
      cout<<"1.insert record"; 
      gotoxy(30,11); 
      cout<<"2.display"; 
      gotoxy(30,12); 
      cout<<"3.update"; 
      gotoxy(30,13); 
      cout<<"4.search"; 
      gotoxy(30,14); 
      cout<<"5.delete"; 
      gotoxy(30,15); 
      cout<<"6.exit"; 
      gotoxy(30,20); 
      cout<<"enter your choice  :"; 
      cin>>choice; 
      clrscr(); 
      switch(choice) 
      { 
        case 1: 
             g.insert(); 
             break; 
        case 2: 
             g.display(); 
             break; 
        case 3: 
             g.update(); 
             break; 
        case 4: 
             g.search(); 
             break; 
        case 5: 
             g.deletion(); 
             break; 
        case 6: 
             g.exit(); 
             exit(1); 
    } 
      }while(choice != 0); 
} 

void group::group() //zero argument constructor 
{ 
 file.open("books.dat",ios::binary|ios::in|ios::out); 
 if(!file) 
    { 
      cout<<endl<<"unable to open the file"; 
       exit(); 
    } 
} 


//adds record to the file void group::insert() 
{ 
    char ch; 
    file.seekp(0L,ios::end); 
    do 
    { 
     cout<<endl<<"enter book name :"; 
     gets(b.bname); 
     cout<<endl<<"enter author's name :"; 
     gets(b.aname); 
     cout<<endl<<"enter publisher's name :"; 
     gets(b.pubname); 
     cout<<endl<<"enter the book's price :"; 
     cin>>b.price; 
     cout<<endl<<"enter the no of books  :"; 
     cin>>b.noofbooks; 
     b.flag=' '; 
     file.write((char*)&b,sizeof(b)); 
     cout<<endl<<endl<<"add another record?(y/n)"; 
     cin>>ch; 
    }while(ch=='y' || ch=='Y'); 
} 

//displays all the books void group::display() 
{ 
int j=1; 
file.seekg(0L,ios::beg); 

while (file.read((char*)&b,sizeof(b))) 
{ 
if(b.flag != '*') 
{ 
    cout<<endl<<"RECORD NO :"<<j++<<endl<<"*************"<<endl<<"BOOK NAME   :"<<b.bname<<endl<<"AUTHOR NAME :"<<b.aname 
        <<endl<<"PUBLISHER   :"<<b.pubname<<endl<<"PRICE       :"<<b.price 
        <<endl<<"COPIES      :"<<b.noofbooks<<endl<<endl<<endl; 
    getch(); 
} 
} 
file.clear(); 
a:cout<<endl<<endl<<endl<<"press any key ...."; 
getch(); 
} 

//update the books void group::update() 
{ 
    char code[20]; 
    int count=0; 
    longint pos; 
    cout<<endl<<"enter the book name :"; 
    gets(code); 

    file.seekg(0L,ios::beg); 

    while(file.read((char*)&b,sizeof(b))) 
    { 
      if(strcmp(b.bname,code)==0) 
       { 
        cout<<endl<<"enter the new book name :"; 
        gets(b.bname); 
        cout<<endl<<"enter author's name     :"; 
        gets(b.aname); 
        cout<<endl<<"enter publisher's name  :"; 
        gets(b.pubname); 
        cout<<endl<<"enter the price         :"; 
        cin>>b.price; 
        cout<<endl<<"enter the no of books   :"; 
        cin>>b.noofbooks; 
        b.flag=' '; 

        pos=count*sizeof(b); 
        file.seekp(pos,ios::beg); 
        file.write((char*)&b,sizeof(b)); 
        return; 
       } 
    count++; 
    } 
    cout<<endl<<"no book available with this name  :"<<code; 
    cout<<endl<<"press any key ...."; 
    getch(); 

    file.clear(); 
} 

//search for a given book void group::search() 
{ 
    char book[20],author[20]; 
    int opt; 
    cout<<endl<<"search by          :"; 
    cout<<endl<<endl<<"1.book name   "; 
    cout<<endl<<endl<<"2.author name "; 
    cout<<endl<<endl<<"enter your option  :"; 
    cin>>opt; 
    if(opt==1) 
    { 
        cout<<endl<<endl<<"enter book's name   :"; 
        gets(book); 
        file.seekg(0l,ios::beg); 
        while(file.read((char*)&b,sizeof(b))) 
        { 
            if(strcmp(b.bname,book)==0) 
            { 
                            cout<<endl<<setw(20)<<b.bname<<setw(20)<<b.aname<<setw(10)<<b.pubname<<setw(10)<<b.price<<setw(10)<<b.noofbooks; 
            } 
        } 
        file.clear(); 
    } 
    else 
    { 
        cout<<endl<<endl<<"enter author's name   :"; 
        gets(author); 
        file.seekg(0l,ios::beg); 
        while(file.read((char*)&b,sizeof(b))) 
        { 
            if(strcmp(b.aname,author)==0) 
            { 
              cout<<endl<<setw(20)<<b.bname<<setw(20)<<b.aname<<setw(10)<<b.pubname<<setw(10)<<b.price<<setw(10)<<b.noofbooks; 

            } 
        } 
        file.clear(); 
    } 
    cout<<endl<<"press any key ..."; 
    getch(); 
} 

//deletes the record void group::deletion() 
{ 
    char book[20],name[20],publ[20]; 
    longint pos; 
    int count=0; 
    cout<<endl<<"enter book's name :"; 
    gets(book); 
    cout<<endl<<"enter author's name :"; 
    gets(name); 
    cout<<endl<<"enter the publisher's name :"; 
    gets(publ); 
    file.seekg(0l,ios::beg); 
    while(file.read((char*)&b,sizeof(b))) 
    { 
        if(strcmp(b.bname,book)==0 && strcmp(b.aname,name)==0 && strcmp(b.pubname,publ)==0) 
        { 
            b.flag='*'; 
            pos=count*sizeof(b); 
            file.seekp(pos,ios::beg); 
            file.write((char*)&b,sizeof(b)); 
            cout<<endl<<"record deleted successfully"; 
            goto v; 
        } 
        count++; 
    } 
    cout<<endl<<"no book in file with name :"<<book<<" "<<"written by  "<<name<<" "<<"and published by  "<<publ; 
    v:cout<<endl<<"press any key....."; 
    getch(); 
    file.clear(); 
} 


void group::exit() 
{ 
    file.close(); 
} 
  
Share: 


Didn't find what you were looking for? Find more on Book Store Management Or get search suggestion and latest updates.

Easy Tutor
Easy Tutor author of Book Store Management is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
Sakoon Jain from United Kingdom Comment on: Nov 07
ONE ERROR IN THIS PROGRAM

View All Comments