Serendipity Booksellers

I need to use the search method to modify the program.

Page 1 of 1

5 Replies - 9884 Views - Last Post: 06 December 2010 - 10:38 AM Rate Topic: -----

#1 cindy1405   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-December 10

Serendipity Booksellers

Posted 04 December 2010 - 08:03 PM

I'm having trouble with my search code for searching for the bookTitle. (Also I would like some help on how to modify the lookUpBook, editBook, deleteBook.)

Add Searching capabilities to the addBook, lookUpBook, editBook, and deleteBook functions.

1. Modify the addBook Function
When a new book is added to the inventory, the program will search the bookTitle array for a row whose first column is set to the null terminator. If the first column of a row contains a null terminator, it means there isn’t a string stored there.

Once an empty row is found in the bookTitle array, the book’s data may be stored in each of the other arrays by using the same subscript. For instance, if the title of the book is stored in bookTitle[7], its publisher’s name will be stored in publisher[7], the date the book was added to the inventory will be stored in dateAdded[7], the quantity of books on hand will be stored in qtyOnHand[7], the book’s wholesale price will be stored in wholesale[7], and the book’s retail price will be stored in retail[7].

The addBook function is currently a stub function. Modify it so it performs the following steps:
• First the function should search the bookTitle array for an empty row. As described above, the function should look for a row whose first column is set to the null terminator. If no empty row is found, it means the array is full. In that case, the function should display a message indicating that no more books may be added to the inventory, and then terminate.
• Once an empty row (or index) is found in bookTitle, the function should ask the user to enter the following items into the that row’s (or index’s) array:
Book title
ISBN number
Author’s name
Publisher’s name
The date the book is added to the inventory
The quantity of this book being added
The wholesale cost of the book
The retail price of the book
Each item above should be added to the appropriate array. Note that the wholesale cost and retail price is for a single copy of the book. Also, remember that the date should be entered in the form YYYY-MM-DD. Have this function call bookInfo( index) to display the information added.

2. Modify the lookUpBook Function
The lookUpBook function is currently a stub function. Modify it so it performs the following tasks:
• It should ask the user for the title of a book. This is a book that is to be looked up in the inventory database.
• The function should search the bookTitle array for a title that matches the one entered by the user. If no match is found, the function should display a message indicating that the book is not in inventory, and terminate. If the book is found, the function should call BookInfo, passing the correct index as the argument.

3. Modify the editBook function
The editBook function is currently a stub function. Modify it so it performs the following tasks:
• It should ask the user for the title of a book. This is a book whose data are to be edited.
• The function should search the bookTitle array for a title that matches the one entered by the user. If no match is found, the function should display a message indicating that the book is not in inventory, and terminate. If the book is found, the function should call BookInfo, passing the correct data as arguments.
• The function should ask the user new values for the all of the fields. These new values are saved in the arrays, replacing the old values.

4. Modify the deleteBook Function
The deleteBook function is currently a stub function. Modify it so it performs the following tasks:
• It should ask the user for the title of a book. This is a book that is to be deleted from the inventory database.
• The function should search the bookTitle array for a title that matches the one entered by the user. If no match is found, the function should display a message indicating that the book is not in inventory, and terminate. If the book is found, the function should call BookInfo, passing the correct data as arguments.
• The function should ask the user if they are sure the book’s data are to be deleted from the inventory. If so, set bookTitle[index] = null and isbn[index] = null.
This is what i have so far:
#include <iostream>
#include "mainmenu.h"
using namespace std;

char bookTitle[20][51];
char isbn[20][14];
char author[20][31];
char publisher[20][31];
char dateAdded[20][11];
int qtyOnHand[20];
double wholesale[20];
double retail[20];

int main()
{
	int choice;

	do
	{
	system("cls");
	cout << "     Serendipity Booksellers" << endl;
	cout << "           Main Menu" << endl << endl;
	cout << "  1. Cashier Module" << endl;
	cout << "  2. Inventory Database Module" << endl;
	cout << "  3. Report Module" << endl;
	cout << "  4. Exit" << endl << endl;
	cout << "  Enter Your Choice: ";
	cin >> choice;

	while (choice < 1 || choice > 4 )
	{	
		cout << "Please enter a number in the range 1-4. ";
		cin >> choice;
	}

	switch (choice)
	{
		case 1: cashier();
				break;
		case 2: invmenu();
				break;
		case 3: reports();
				break;
		case 4: choice = 4;
				break;
	}

	} while (choice != 4);
	
	return 0;
}


#include <iostream>
#include <iomanip>
#include <cstring>
#include "cashier.h"
using namespace std;

void cashier()
{
	int qty, choice;
	float price;
	double subtotal = 0.0;
	double tax = 0.0;
	double total = 0.0;
	char date[10], isbn[18], title[34];
	choice = 0;
	
	while(choice !=2)
	{
	system("cls");
	cout << "Serendipity Booksellers" << endl;
	cout << "    Cashier Module" << endl << endl;
	cout << "Date: ";
	cin >> date;
	cout << "Quantity of Book: ";
	cin >> qty;
	cout << "ISBN: ";
	cin >> isbn;
	cin.ignore();
	cout << "Title: ";
	cin.getline (title, 34);
	cout << "Price: ";
	cin >> price;
	cout << endl << endl;

	subtotal = price * qty;
	tax = subtotal * .06;
	total = subtotal + tax;

	cout << "Serendipity Booksellers" << endl << endl;
	cout << "Date: " << date << endl << endl;
	cout << "Qty" << setw(7) << "ISBN" << setw(16) << "Title" << setw(22) << "Price" << setw(14) << "Total" << endl;
	cout << "________________________________________________________________________" << endl;
	cout << qty << "     ";
	cout << setw(15) << left << isbn;
	cout << setw(22) << left << title;
	cout << setprecision(2) << fixed << showpoint << "$" << price;
	cout << setprecision(2) << fixed << showpoint << "        $" << left << total;
	cout << endl <<endl <<endl;
	cout << setprecision(2) << showpoint << fixed << "                     Subtotal                            $" << subtotal << endl;
	cout << setprecision(2) << showpoint << fixed << "                     Tax                                 $" << tax << endl;
	cout << setprecision(2) << showpoint << fixed << "                     Total                               $" << total << endl << endl;
	cout << endl << "Thank You for Shopping at Serendipity!" << endl;
	cout << "Would you like to make another transaction? (Y/N): ";
	cin >> choice;
	}
	while((choice != 'y') && (choice != 'Y') && (choice != 'n') && (choice != 'N'));
	{
		cout << "Please re-enter 'Y' or 'N': ";
		cin >> choice;
	}
	while((choice == 'y')||(choice == 'Y'));
}


#include <iostream>
#include "invmenu.h"
using namespace std;

char bookTitle[7];
char isbn[7];
char author[7];
char publisher[7];
char dateAdded[7];
int qtyOnHand[7];
double wholesale[7];
double retail[7];
int size = 1;

void setBookDetails()
{
	int i = size;
	cout << "Enter book info for book " << i << endl;
	cout << "Enter title of the book" << endl;
	cin >> bookTitle[i];
	cout << "Enter ISBN: " << endl;
	cin >> isbn[i];
	cout << "Enter the author name" << endl;
	cin >> author[i];
	cout << "Enter the publisher name" << endl;
	cin >> publisher[i];
	cout << "Enter the date in MM-DD-YYYY format" << endl;
	cin >> dateAdded[i];
	cout << "Enter the quantity on hand" << endl;
	cin >> qtyOnHand[i];
	cout <<"Enter the whole sale price of each book" << endl;
	cin >> wholesale[i];
	cout << "Enter the retail price of the book" << endl;
	cin >> retail[i];
	cout << endl;
}
void addBookSearch()
{
	int flag = 0;
	for(int i = size; i <= 20; i++)
	{
		if(bookTitle[i][0] == '\0')
			flag = 1;
	}
	if(flag == 1)
		cout << "Empty row exists" << endl;
	else
		cout << "No more books can be added" << endl;
}
void addBook()
{
	addBookSearch();
	if(size <= 20)
	{
		setBookDetails();
		cout << "Book " << size << " is added" << endl;
		size++;
	}
	else
		cout << "Array is full. No more books can be added to the inventory." << endl;
}
void lookUpBook()
{
	cout << "\n\t\tYou selected Look Up Book.\n";
	system("pause");
}
void editBook()
{
	cout << "\n\t\tYou selected Edit Book.\n";
	system("pause");
}

void deleteBook()
{
	cout << "\n\t\tYou selected Delete Book.\n";
	system("pause");
}

void invmenu()
{
	int choice;

	do
	{
		system("cls");
		cout << "     Serendipity Booksellers" << endl;
		cout << "       Inventory Database" << endl << endl;
		cout << " 1. Look Up a Book" << endl;
		cout << " 2. Add a Book" << endl;
		cout << " 3. Edit a Book's Record" << endl;
		cout << " 4. Delete a Book" << endl;
		cout << " 5. Return to the Main Menu" << endl << endl;
		cout << " Enter Your Choice: ";
		cin >> choice;

	while (choice < 1 || choice > 5 )
	{	
		cout << "Please enter a number in the range 1-5.";
		cin >> choice;
	}
	
	switch (choice)
	{	
		case 1: lookUpBook();
				break;
		case 2: addBook();
				break;
		case 3: editBook();
				break;
		case 4: deleteBook();
				break;
		case 5: choice = 5;
				break;
	}

	} while (choice != 5);
}
#include <iostream>
#include "reports.h"
using namespace std;

void repListing()
{
	cout << "\n\t\tYou selected Inventory Listing.\n";
	system("pause");
}

void repWholesale()
{
	cout << "\n\t\tYou selected Inventory Wholesale Value.\n";
	system("pause");
}

void repRetail()
{
	cout << "\n\t\tYou selected Inventory Retail Value.\n";
	system("pause");
}

void repQty()
{
	cout << "\n\t\tYou selected Listing By Quantity.\n";
	system("pause");
}

void repCost()
{
	cout << "\n\t\tYou selected Listing By Cost.\n";
	system("pause");
}

void repAge()
{
	cout << "\n\t\tYou selected Listing By Age.\n";
	system("pause");
}

void reports()
{
	int choice;

	do
	{
		system("cls");
		cout << "     Serendipity Booksellers" << endl;
		cout << "            Reports" << endl << endl;
		cout << " 1. Inventory Listing" << endl;
		cout << " 2. Inventory Wholesale Value" << endl;
		cout << " 3. Inventory Retail Value" << endl;
		cout << " 4. Listing by Quantity" << endl;
		cout << " 5. Listing by Cost" << endl;
		cout << " 6. Listing by Age" << endl;
		cout << " 7. Return to the Main Menu" << endl << endl;
		cout << " Enter Your Choice: ";
		cin >> choice;

	while (choice < 1 || choice > 7 )
	{	
		cout << "Please enter a number in the range 1-7. ";
		cin >> choice;
	}
	
	switch (choice)
	{	
		case 1: repListing();
				break;
		case 2: repWholesale();
				break;
		case 3: repRetail();
				break;
		case 4: repQty();
				break;
		case 5: repCost();
				break;
		case 6: repAge();
				break;
		case 7: choice = 7;
				break;
	}

	} while (choice != 7);
}



And this is the error I get:
invmenu.cpp(42) : error C2109: subscript requires array or pointer type

Any help will be appreciated. Thanks =)

This post has been edited by JackOfAllTrades: 04 December 2010 - 10:04 PM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Serendipity Booksellers

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6259
  • View blog
  • Posts: 24,028
  • Joined: 23-August 08

Re: Serendipity Booksellers

Posted 04 December 2010 - 10:06 PM

char bookTitle[7];

bookTitle is an array of seven individual characters.
if(bookTitle[i][0] == '\0')

You're treating it as if it were an array of arrays.
Was This Post Helpful? 0
  • +
  • -

#3 cindy1405   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-December 10

Re: Serendipity Booksellers

Posted 05 December 2010 - 09:23 AM

View PostJackOfAllTrades, on 04 December 2010 - 09:06 PM, said:

char bookTitle[7];

bookTitle is an array of seven individual characters.
if(bookTitle[i][0] == '\0')

You're treating it as if it were an array of arrays.


Ok so i change it to
if(bookTitle[7] == '\0')

...??
Was This Post Helpful? 0
  • +
  • -

#4 #define   User is offline

  • Duke of Err
  • member icon

Reputation: 1862
  • View blog
  • Posts: 6,713
  • Joined: 19-February 09

Re: Serendipity Booksellers

Posted 05 December 2010 - 07:11 PM

In invmenu you have this

char bookTitle[7];
char isbn[7];
char author[7];
char publisher[7];
char dateAdded[7];
int qtyOnHand[7];
double wholesale[7];
double retail[7];



I guess you added this is because the compiler complained of not finding the arrays. This way you are trying to create two sets of arrays, with two sets of data.

The arrays are defined in main. In invmenu to tell the compiler that the arrays are already defined in another part of the program, you need to use the extern keyword.

extern char bookTitle[20][51];
extern char isbn[20][14];
extern char author[20][31];
extern char publisher[20][31];
extern char dateAdded[20][11];
extern int  qtyOnHand[20];
extern double wholesale[20];
extern double retail[20];


Was This Post Helpful? 0
  • +
  • -

#5 cindy1405   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-December 10

Re: Serendipity Booksellers

Posted 06 December 2010 - 10:25 AM

View Post#define, on 05 December 2010 - 06:11 PM, said:

In invmenu you have this

char bookTitle[7];
char isbn[7];
char author[7];
char publisher[7];
char dateAdded[7];
int qtyOnHand[7];
double wholesale[7];
double retail[7];



I guess you added this is because the compiler complained of not finding the arrays. This way you are trying to create two sets of arrays, with two sets of data.

The arrays are defined in main. In invmenu to tell the compiler that the arrays are already defined in another part of the program, you need to use the extern keyword.

extern char bookTitle[20][51];
extern char isbn[20][14];
extern char author[20][31];
extern char publisher[20][31];
extern char dateAdded[20][11];
extern int  qtyOnHand[20];
extern double wholesale[20];
extern double retail[20];



Oh ok thank you, so this is how i fixed to:

[code]
#include <iostream>
#include "invmenu.h"
using namespace std;

char bookTitle[20][51];
char isbn[20][14];
char author[20][31];
char publisher[20][31];
char dateAdded[20][11];
int qtyOnHand[20];
double wholesale[20];
double retail[20];
int size = 1;

void setBookDetails()
{
int i = size;
cout << "Enter book info for book #" << i << ":" << endl;
cout << "Enter title of the book: ";
cin >> bookTitle[i];
cout << "Enter ISBN: ";
cin >> isbn[i];
cout << "Enter the author name: ";
cin >> author[i];
cout << "Enter the publisher name: ";
cin >> publisher[i];
cout << "Enter the date in MM-DD-YYYY format: ";
cin >> dateAdded[i];
cout << "Enter the quantity on hand: ";
cin >> qtyOnHand[i];
cout <<"Enter the whole sale price of each book: ";
cin >> wholesale[i];
cout << "Enter the retail price of the book: ";
cin >> retail[i];
cout << endl;
system("pause");
}
void addBookSearch()
{
int flag = 0;
for(int i = size; i <= 20; i++)
{
if(bookTitle[i][0] == '\0')
flag = 1;
}
if(flag == 1)
cout << "Empty row exists" << endl;
else
cout << "No more books can be added" << endl;
}
void addBook()
{
addBookSearch();
if(size <= 20)
{
setBookDetails();
cout << "Book " << size << " is added" << endl;
size++;
}
else
cout << "Array is full. No more books can be added to the inventory." << endl;
}
void lookUpBook()
{
system("pause");
}
void editBook()
{
cout << "\n\t\tYou selected Edit Book.\n";
system("pause");
}

void deleteBook()
{
cout << "\n\t\tYou selected Delete Book.\n";
system("pause");
}

void invmenu()
{
int choice;

do
{
system("cls");
cout << " Serendipity Booksellers" << endl;
cout << " Inventory Database" << endl << endl;
cout << " 1. Look Up a Book" << endl;
cout << " 2. Add a Book" << endl;
cout << " 3. Edit a Book's Record" << endl;
cout << " 4. Delete a Book" << endl;
cout << " 5. Return to the Main Menu" << endl << endl;
cout << " Enter Your Choice: ";
cin >> choice;

while (choice < 1 || choice > 5 )
{
cout << "Please enter a number in the range 1-5.";
cin >> choice;
}

switch (choice)
{
case 1: lookUpBook();
break;
case 2: addBook();
break;
case 3: editBook();
break;
case 4: deleteBook();
break;
case 5: choice = 5;
break;
}

} while (choice != 5);
}
[code]

now i need help modifying the lookUpBook, editBook, deleteBook can someone please help with any ideas. Thanks
Was This Post Helpful? 0
  • +
  • -

#6 jimblumberg   User is offline

  • member icon

Reputation: 5810
  • View blog
  • Posts: 17,740
  • Joined: 25-December 09

Re: Serendipity Booksellers

Posted 06 December 2010 - 10:38 AM

Quote

now i need help modifying the lookUpBook, editBook, deleteBook can someone please help with any ideas. Thanks


What have you tried? I don't see anything in any of these functions.

You must show some effort, we won't write the code for you.

Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1