Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Homework HelpRSS Feeds

CREATING A LIST OF THE BOOKS AND THEIR DETAILS AND ACCEPTING DETAILS FROM THE CUSTOMER AND SEARCHING THE BOOKS

Posted By: Adelgiese Fischer     Category: C++ Programming     Views: 13219

CREATING A LIST OF THE BOOKS AND THEIR DETAILS AND ACCEPTING DETAILS FROM THE CUSTOMER AND SEARCHING THE BOOKS.

Code for CREATING A LIST OF THE BOOKS AND THEIR DETAILS AND ACCEPTING DETAILS FROM THE CUSTOMER AND SEARCHING THE BOOKS in C++ Programming

#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<string.h>

struct link
{
    char title[30];
    char author[30];
    char publisher[30];
    float price;
    int stock;
    struct link *next;
};

class books
{
    link *first,*curr,*point,*prev;
    public:
        books()
        {

        }
        void getdata();
        void getdata1();
        void display();
        void search();
};

void books::getdata()
{
    int ans;
    first=newstruct link;
    point=first;
    int ctr=0;
    while(1)
    {
            if(ctr==0)
            {
                clrscr();
                cout<<"\nENTER BOOK TITLE      :";
                char c;
                for(int i=0;(c=getche())!='\r';i++)
                        point->title[i]=c;
                point->title[i]='\0';
                cout<<"\nENTER AUTHORS NAME    :";
                for(i=0;(c=getche())!='\r';i++)
                        point->author[i]=c;
                point->author[i]='\0';
                cout<<"\nENTER PUBLISHERS NAME :";
                for(i=0;(c=getche())!='\r';i++)
                point->publisher[i]=c;
                point->publisher[i]='\0';
                cout<<"\nENTER PRICE OF BOOK   :";
                cin>>point->price;
                cout<<"ENTER STOCK POSITION  :";
                cin>>point->stock;
                ctr++;
            }
            else
            {
                char title[30];
                int flag=0;
                char author[30];
                char publisher[30];
                int copies;
                clrscr();
                cout<<"\nENTER BOOK TITLE      :";
                char c;
                for(int i=0;(c=getche())!='\r';i++)
                        title[i]=c;
                title[i]='\0';
                cout<<"\nENTER AUTHORS NAME    :";
                for(i=0;(c=getche())!='\r';i++)
                        author[i]=c;
                author[i]='\0';
                point=first;
                while(point!=NULL)
                {
                    if(strcmp(title,point->title)==0)
                    {
                        if(strcmp(author,point->author)==0)
                        {
                            cout<<"\nTHERE ARE "<<point->stock<<" COPIES AVAILABLE FOR THIS BOOK";
                            cout<<"\nWOULD YOU LIKE TO ADD MORE(1 FOR Y/2 FOR N) :";
                            cin>>ans;
                                if(ans==1)
                                {
                                    cout<<"\nENTER THE PUBLISHER   :";
                                    cin>>point->publisher;
                                    cout<<"ENTER THE PRICE OF BOOK :";
                                    cin>>point->price;
                                    cout<<"ENTER THE No. OF COPIES :";
                                    cin>>copies;
                                    point->stock=point->stock+copies;
                                    flag=1;
                                }
                                elseif(ans==2)
                                {
                                    flag=1;
                                    cout<<"\nNO COPIES ADDED";
                                    cout<<"\nCOPIES AVALABLE ARE "<<point->stock;
                                 }
                        }
                    }
                    point=point->next;
                }
                if(flag==0)
                {
                        point=first;
                        while(point->next!=NULL)
                            point=point->next;
                        point->next=newstruct link;
                        point=point->next;
                        point->next=NULL;
                        
                        strcpy(point->title,title);
                        strcpy(point->author,author);
                        cout<<"\nENTER PUBLISHERS NAME :";
                        for(i=0;(c=getche())!='\r';i++)
                            point->publisher[i]=c;
                        point->publisher[i]='\0';

                        cout<<"\nENTER PRICE OF BOOK   :";
                        cin>>point->price;

                        cout<<"ENTER STOCK POSITION  :";
                        cin>>point->stock;

                    }
                }
                while(1)
                {
                    cout<<"\nDO YOU WANT TO CONTINUE(1 FOR Y/2 FOR N):";
                    cin>>ans;
                    if(ans==1)
                        break;
                    elseif(ans==2)
                        break;
                    elsecontinue;
                }
                    if(ans==1)
                    {
                        //point->next=new struct link;// point=point->next;
                        point->next=NULL;
                     }
                    else
                    {
                        point->next=NULL;
                        break;
                    }
    }

}

void books::getdata1()
{
    while(1)
    {
            char title[30];
            int flag=0;
            char author[30];
            char publisher[30];
            int copies;
            clrscr();
            cout<<"\nENTER BOOK TITLE      :";
            char c;
            for(int i=0;(c=getche())!='\r';i++)
                    title[i]=c;
            title[i]='\0';
            cout<<"\nENTER AUTHORS NAME    :";
            for(i=0;(c=getche())!='\r';i++)
                    author[i]=c;
            author[i]='\0';
            point=first;
            int ans;
            while(point!=NULL)
            {
                if(strcmp(title,point->title)==0)
                {
                    if(strcmp(author,point->author)==0)
                    {
                            cout<<"\nTHERE ARE "<<point->stock<<" COPIES AVAILABLE FOR THIS BOOK";
                            cout<<"\nWOULD YOU LIKE TO ADD MORE(1 FOR Y/2 FOR N) :";
                            cin>>ans;
                            if(ans==1)
                            {
                                cout<<"\nENTER THE PUBLISHER   :";
                                cin>>point->publisher;
                                cout<<"ENTER THE PRICE OF BOOK :";
                                cin>>point->price;
                                cout<<"ENTER THE No. OF COPIES :";
                                cin>>copies;
                                point->stock=point->stock+copies;
                                flag=1;
                            }
                            elseif(ans==2)
                            {
                                flag=1;
                                cout<<"\nNO COPIES ADDED";
                                cout<<"\nCOPIES AVALABLE ARE "<<point->stock;
                             }
                        }
                }
                point=point->next;
            }
            if(flag==0)
            {
                curr=newstruct link;
                strcpy(curr->title,title);
                strcpy(curr->author,author);
                cout<<"\nENTER PUBLISHERS NAME :";
                for(i=0;(c=getche())!='\r';i++)
                    curr->publisher[i]=c;
                curr->publisher[i]='\0';

                cout<<"\nENTER PRICE OF BOOK   :";
                cin>>curr->price;

                cout<<"ENTER STOCK POSITION  :";
                cin>>curr->stock;
             }
        while(1)
        {
            cout<<"\nDO YOU WANT TO CONTINUE(1 FOR Y/2 FOR N):";
            cin>>ans;
            if(ans==1)
                break;
            elseif(ans==2)
                break;
            elsecontinue;
        }
        if(ans==1)
        {
            point=first;
            while(point->next!=NULL)
                point=point->next;
            point->next=curr;
            point=point->next;
            point->next=NULL;
        }
        else
        {
            if(flag==0)
            {
                point=first;
                while(point->next!=NULL)
                {
                    point=point->next;
                }
                point->next=curr;
                point=point->next;
                point->next=NULL;
                break;
            }
            elsebreak;
         }
    }
}
void books::display()
{
        point=first;
        while(point->next!=NULL)
        {
            clrscr();
            cout<<"\nBOOK TITLE     :"<<point->title;
            cout<<"\nBOOK AUTHOR    :"<<point->author;
            cout<<"\nBOOK PUBILSHER :"<<point->publisher;
            cout<<"\nBOOK PRICE     :"<<point->price;
            cout<<"\nSTOCK POSITION :"<<point->stock;
            getch();
            point=point->next;
        }
        clrscr();
        cout<<"\nBOOK TITLE     :"<<point->title;
        cout<<"\nBOOK AUTHOR    :"<<point->author;
        cout<<"\nBOOK PUBILSHER :"<<point->publisher;
        cout<<"\nBOOK PRICE     :"<<point->price;
        cout<<"\nSTOCK POSITION :"<<point->stock;
        getch();
}
void books::search()
{
    int flag=0;
    char title[30];
    char author[30];
    int copies,ans;
    float price;
    char c;
    while(1)
    {
        flag=0;
        clrscr();
        cout<<"\nENTER THE BOOK TO SEARCH :";
        for(int i=0;(c=getche())!='\r';i++)
            title[i]=c;
        title[i]='\0';
        point=first;
        while(point!=NULL)
        {
            if(strcmp(title,point->title)==0)
            {
                cout<<"\nENTER THE AUTHORS NAME   :";
                for(i=0;(c=getche())!='\r';i++)
                    author[i]=c;
                author[i]='\0';
                if(strcmp(author,point->author)==0)
                {
                    if(point->stock==0)
                    {
                        cout<<"\nOUT OF STOCK";
                        flag=1;

                     }
                     else
                     {
                        cout<<"\nBOOK AVAILABLE";

                        while(1)
                        {
                            cout<<"\nENTER THE NUMBER OF COPIES:";
                            cin>>copies;
                            if(copies>point->stock)
                            {
                                cout<<"\nONLY "<<point->stock<<" COPIES ARE AVAILBALE";
                                getch();
                                continue;
                            }
                            else
                            {
                                price=point->price*copies;
                                cout<<"\n AMOUNT PAYABLE("<<point->price<<"/book) :"<<price;
                                point->stock=point->stock-copies;
                                getch();
                                flag=1;
                                break;
                            }
                        }
                     }
                }
            }
             point=point->next;
        }
        if(flag==0)
        {
            cout<<"\nNO SUCH BOOK AVAILABLE WITH US";
        }

    while(1)
    {
        cout<<"\nDO YOU WANT TO CONTINUE(1 FOR Y/2FOR N) :";
        cin>>ans;
        if (ans==1)
            break;
        elseif(ans==2)
            break;
        elsecontinue;
     }
     if (ans==1)
        continue;
     elsebreak;
}
}








main()
{
    int ctr=0;
    while(1)
    {
        clrscr();
        cout<<"\n\t\tBOOKS INVENTORY";
        cout<<"\n\t1. ADD BOOKS TO LIST";
        cout<<"\n\t2. SEARCH A BOOK";
        cout<<"\n\t3. DISPLAY LIST";
        cout<<"\n\t4. EXIT";
        cout<<"\n\n\tENTER YOUR CHOICE :";
        int ans;
        cin>>ans;
        books b1;
        if(ans==1)
        {
            if(ctr==0)
            {
                b1.getdata();
                ctr++;
            }
            else
                b1.getdata1();
         }
            elseif(ans==2)
                b1.search();
            elseif(ans==3)
                b1.display();
        elseif(ans==4)
        {
            exit(0);
        }
        else
        {
            cout<<"INVALID CHOICE";
            continue;
        }
    }
}
  
Share: 



Adelgiese Fischer
Adelgiese Fischer author of CREATING A LIST OF THE BOOKS AND THEIR DETAILS AND ACCEPTING DETAILS FROM THE CUSTOMER AND SEARCHING THE BOOKS is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

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

 
No Comment Found, Be the First to post comment!