#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 !!**