#include "stdafx.h"
        #include<iostream>
        #include<conio.h>
        #include<string>

        using namespace std;

        //--------------------------------Structures--------------------------------//
        struct datee
        {   
            int month;
            int days;
            int years;
        };
        struct book
        {   
            string bookname;
            string bookpublisher;
            string authorName;
            int copies;
            int price;
            int edition;
            datee date; 
        };

        //---------------------------Function Prototypes----------------------------//
        void titleheader();
        void menu();
        void addbook(book b[],int i);
        void display(book b[],int j);
        void edit(book b[], int a);
        void search(book b[],int a);
        void del (book b[],int a);
        //--------------------------Main Function---------------------------------//
        char op;

        int _tmain(int argc, _TCHAR* argv[])
        {
            book * pt;


            int ch;
            static int a;
            const int size=10;
            book b[size];
            book array[size];
        loop:
            titleheader();
            menu();
            cout<<"\nPress option key to activate the required function: ";
            cin>>ch;
            switch (ch)
            {
            case 1:
                {
                    system("cls");
                    titleheader();
                    cout<<"How many Books do you want to enter: ";
                    cin>>a;
                    for(int i=0;i<a;i++)
                    {
                        cout<<"\n";
                        addbook(b,i);
                    }
                    cout<<endl;
                    system("pause");
                    cin.get();
                    system("cls");
                    goto loop;
                }

            case 2:
                {
                    system("cls");
                    titleheader();
                    for (int j=0;j<a;j++)
                    {
                        cout<<"\n\t\tBook No: "<<j<<"\n"<<endl;
                        display(b,j);
                    }
                    cout<<endl;
                    system("pause");
                    cin.get();  
                    system("cls");
                    goto loop;
                }

            case 3:
                {
                    system("cls");
                    titleheader();
                    edit(b,a);
                    cout<<endl;
                    system("pause");
                    cin.get();
                    system("cls");
                    goto loop;
                }

            case 4:
                {
                    system("cls");
                    titleheader();
                    search (b,a);
                    system("cls");
                    goto loop;
                }

            case 5:
                {
                    system("cls");
                    titleheader();
                    del(b,a);
                    cout<<endl;
                    system("pause");
                    cin.get();
                    system("cls");
                    goto loop;
                }

            case 6:
                {
                    break;
                }

            default :
                {
                    exit (0);
                }
            }

            getch();
        }
        //************************************ END of main() and Functions Bodies are given below. *********************************************\\

        void titleheader()
        {
            cout<<"\n ------------------------------------------------------------------------------ "<<endl;
            cout<<"                         **** Book Store Managment ****                         "<<endl;
            cout<<" ------------------------------------------------------------------------------\n"<<endl;
        }

        void menu()
        {
            cout<<"1). Add a New Book. "<<endl;
            cout<<"2). Display all Records."<<endl; 
            cout<<"3). Edit a Book Record."<<endl;
            cout<<"4). Search a Book from Record."<<endl;
            cout<<"5). Delete a Book from Record."<<endl;
            cout<<"6). Press any other key to quit."<<endl;
        }

        void addbook(book b[],int i)
        {
            cout<<" Enter Book name: ";
            cin.ignore();
            cin>>(b[i].bookname);
            cout<<" Enter Book Publisher name: ";
            cin>>(b[i].bookpublisher);
            cout<<" Enter Author/Writer name: ";
            cin>>(b[i].authorName);
            cout<<" Enter Number of Copies : ";
            cin>>b[i].copies;
            cout<<" Enter Price: ";
            cin>>b[i].price;
            cout<<" Enter Edition: " ;
            cin>>b[i].edition;
            cout<<" Enter Date of Entry : ";
            cin>>b[i].date.month>>b[i].date.days>>b[i].date.years;
        }

        void display(book b[],int j)
        {
            cout<<" Book Name: "<<b[j].bookname<<endl;
            cout<<" Publisher Name: "<<b[j].bookpublisher<<endl;
            cout<<" Author Name : "<<b[j].authorName<<endl;
            cout<<" No. Of Copies: "<<b[j].copies<<endl;
            cout<<" Price: "<<b[j].price<<endl;
            cout<<" Book Edition: "<<b[j].edition<<endl;
            cout<<" Date Added: "<<b[j].date.month<<"/"<<b[j].date.days<<"/"<<b[j].date.years<<endl;
        }

        void edit(book b[],int a)
        {
            string book;
            cout<<" Enter name of the book you want to edit record of: ";
            cin>>book;
            for (int i=0;i<a;i++)
            {
                if (book==b[i].bookname)
                {
                    cin.ignore();
                    cout<<" Enter New Book name: ";       
                    cin>>(b[i].bookname);
                    cout<<" Enter New Book Publisher name: ";
                    cin>>(b[i].bookpublisher);
                    cout<<" Enter Author/Writer name: ";
                    cin>>(b[i].authorName);
                    cout<<" Enter Number of Copies : ";
                    cin>>b[i].copies;
                    cout<<" Enter Price: ";
                    cin>>b[i].price;
                    cout<<" Enter Edition: " ;
                    cin>>b[i].edition;
                    cout<<" Enter Date of Entry : ";
                    cin>>b[i].date.month>>b[i].date.days>>b[i].date.years;
                }
            }
        }

        void search (book b[],int a)
        {
            string search;
            cout<<"1). Seacrh by Book name: \n";
            cout<<"2). Search by Publisher name: \n";
            cout<<"3). Search by date of entry: \n";
            int choice;
            cout<<"\nWhat is your choice: ";
            cin>>choice;
            if (choice==1)
            {
                cout<<"Enter Book name you want to search the record of: ";
                cin>>search;
                for (int i=0;i<a;i++)
                    if (search==b[i].bookname)
                    {
                        cout<<"\n Book Record found. \n\n";
                        cout<<" Book Name: "<<b[i].bookname<<endl;
                        cout<<" Publisher Name: "<<b[i].bookpublisher<<endl;
                        cout<<" Author Name : "<<b[i].authorName<<endl;
                        cout<<" No. Of Copies: "<<b[i].copies<<endl;
                        cout<<" Price: "<<b[i].price<<endl;
                        cout<<" Book Edition: "<<b[i].edition<<endl;
                        cout<<" Date Added: "<<b[i].date.month<<"/"<<b[i].date.days<<"/"<<b[i].date.years<<endl;
                    }
            }
            else
                if (choice==2)
                {
                    cout<<" Enter Publisher name for the book you want to search the record of: ";
                    cin>>search;
                    for (int j=0;j<a;j++)
                        if (search==b[j].bookpublisher)
                        {
                            cout<<" Book Record found. \n\n";
                            cout<<" Book Name: "<<b[j].bookname<<endl;
                            cout<<" Publisher Name: "<<b[j].bookpublisher<<endl;
                            cout<<" Author Name : "<<b[j].authorName<<endl;
                            cout<<" No. Of Copies: "<<b[j].copies<<endl;
                            cout<<" Price: "<<b[j].price<<endl;
                            cout<<" Book Edition: "<<b[j].edition<<endl;
                            cout<<" Date Added: "<<b[j].date.month<<"/"<<b[j].date.days<<"/"<<b[j].date.years<<endl;
                        }

                }
                else 
                    if (choice==3)
                    {
                        cout<<" Enter Writer name for the book you want to search the record of: ";
                        cin>>search;
                        for (int k=0;k<a;k++)
                            if (search==b[k].authorName)
                            {
                                cout<<" Book Record found. \n\n";
                                cout<<" Book Name: "<<b[k].bookname<<endl;
                                cout<<" Publisher Name: "<<b[k].bookpublisher<<endl;
                                cout<<" Author Name : "<<b[k].authorName<<endl;
                                cout<<" No. Of Copies: "<<b[k].copies<<endl;
                                cout<<" Price: "<<b[k].price<<endl;
                                cout<<" Book Edition: "<<b[k].edition<<endl;
                                cout<<" Date Added: "<<b[k].date.month<<"/"<<b[k].date.days<<"/"<<b[k].date.years<<endl;
                            }

                    }
                    else
                    {
                        cout<<"Invalid selection.";
                    }
                    cout<<endl;
                    system("pause");
                    cin.get();

        }

        void del (book b[],int a)
        {

        }


**
I am a beginner .Please tell me how to delete a record from this program ..I enter a record it get saved,searched,edited and displayed by calling respective functions.. but no record is getting deleted .I have done so much to do it but in vain.Please help me.Thanks !!

**

Rows can not be deleted from arrays. The best you can do is to mark the row for deletion, one way to do that is to replace one of the structure members, such as bookname, with "", then as your program searches through the array if bookname == "" then you know that row in the array is marked for deletion. When you want to add a new record re-use the row with bookname == "". When you write out the array to a file ignore the rows that have been marked for deletion.

Another method is to move the row that is to be deleted down to the end of the array, which means you will have to shuffle all the other rows up one row to fill in the gap. You will also want to set bookname = "" so that you know it has been deleted.

Sir (ANCIENT DRAGON) I am a Noob (:P).Now shifting and stuff,i really Don't know how to do that..and Sir you can look at all the coding,its so simple and every thing is easily done !! I really don't know how to do what you said. Please post some piece of code for me !! Thanks

Didn't you write that program? The easiest thing to do is just set bookane == "" so that it will look like the row is deleted. If you really wrote all that program you posted then you shouldn't have a very difficult time doing that.

A suggestion: try to keep the code you post to an absolute minimum. Something like the following is very simple to understand and will get you a lot further than three hundred lines of code that take a while to read.

void main() 
{
    char* names[3] = {"john", "paul", "george" };

    // how can I delete paul ?
}

The answer is, you can't delete it. The suggested remedy is to somehow identify names[1] as deleted by setting names[1]=""; This can save a null pointer exception that could follow the ancient idiom: names[1] = NULL;

Another note about this type of code: in learning how to program, you must learn the basic operations and the problems that can follow them. You need to understand terms like shifting in order to see how problematic certain styles can be. Shifting refers to moving entries around in the array so that you won't have multiple chunks of deleted data hanging around creating special cases for other parts of your code.

You young whippersnappers benefit from the experience of your predecessors when you learn to use standardized containers like lists, vectors and hashes along with standard algorithms that are adapted to the standardized containers. If you learn to program using the standard vector, you won't need to worry about how to delete an entry, you just use the appropriate member of the template class. (Which will be the 'erase' member function.)

See: http://www.cplusplus.com/reference/vector/vector/erase/ for an example.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.