#include <iostream>
#include <string>
#include <iomanip>
#include "mainmenu.h"
using namespace std;
string bookTitle[20] = {""};
string isbn[20] = {""};
string author[20] = {""};
string publisher[20] = {""};
string dateAdded[20] = {""};
int qtyOnHand[20] = {0};
double wholesale[20] = {0.0};
double retail[20] = {0.0};
string searchTitle;
int main()
{
// Declarations for function
int choice;
// Constants for menu choices
const int Cashier_Module = 1,
Inventory_Database_Module = 2,
Report_Module = 3,
Exit = 4;
do
{
// Read input
cout << " Serendipity Booksellers\n";
cout << " Main Menu\n\n";
cout << " 1. Cashier Module\n";
cout << " 2. Inventory Database Module\n";
cout << " 3. Book Information Module\n";
cout << " 4. Report Module\n";
cout << " 5. Exit\n\n";
cout << " Enter Your Choice: ";
cin >> choice;
cout << "\n";
// Choice validation
switch (choice)
{
case 1: cashier();
break;
case 2: invMenu();
break;
case 3: bookInfo(isbn, bookTitle, author, publisher, dateAdded, qtyOnHand, wholesale, retail);
break;
case 4: reports();
break;
case 5: cout << " You have chosen to end the program.\n";
break;
default: cout << " Please enter a number in the range of 1-5.\n";
}
cout << endl;
} while (choice != 5);
cout << "\n";
return 0;
}
void cashier()
{
// Declarations for function
string date;
string isbn;
string title;
int quantity, answer;
float price_of_book, subtotal, tax, total, percent_of_tax;
do
{
// Read input
cout << " Please fill in the information below:\n\n";
cout << " Please enter the date in the form (MM/DD/YYYY): ";
cin >> date;
cout << " Enter the ISBN of the book in the form (X-XXX-XXXXX-X): ";
cin >> isbn;
cin.ignore(); // Skips to the next character so I can enter the title
// *Need to use this before a getline so i can enter the next statement*
cout << " Enter the title of the book: ";
getline(cin, title); // Allows me to enter a name with spaces
cout << " Enter the number of books: ";
cin >> quantity;
cout << " Enter the price of the book: ";
cin >> price_of_book;
cout << " Enter the percent of tax: ";
cin >> percent_of_tax;
cout << "\n\n\n";
// Calculations
subtotal = quantity * price_of_book;
tax = subtotal * percent_of_tax;
total = subtotal + tax;
// Display Results
cout << setprecision(2) << fixed << showpoint;
cout << " Serendipity Book Sellers\n\n\n";
cout << " Date: " << date << endl;
cout << "\n";
cout << " Qty ISBN Title Price Total\n";
cout << " ________________________________________________________________\n";
cout << setw(3) << quantity << setw(15) << isbn << setw(13) << title << setw(15) << "$ " << price_of_book <<
setw(9) << "$ " << subtotal << endl;
cout << "\n\n\n";
cout << " Subtotal $ " << subtotal << endl;
cout << " Tax $ " << tax << endl;
cout << " Total $ " << total << endl;
cout << "\n\n";
cout << "Would you like to make another transaction?" << endl;
cout << "(1 = Yes & 2 = No): ";
cin >> answer;
cout << "\n";
} while(answer == 1);
while (answer == 2)
{
cout << "Thank You for Shopping at Serendipity!\n\n";
break;
}
}
void invMenu()
{
// Declarations for function
int choice;
// Constants for menu choices
const int Look_up_a_book = 1,
Add_a_book = 2,
Edit_a_book_record = 3,
Delete_a_book = 4,
Return_to_main_menu = 5;
do
{
// Read input
cout << " Serendipity Booksellers\n";
cout << " Inventory Database\n\n";
cout << " 1. Look Up a Book\n";
cout << " 2. Add a Book\n";
cout << " 3. Edit a Book's Record\n";
cout << " 4. Delete a Book\n";
cout << " 5. Return to the Main Menu\n\n";
cout << " Enter Your Choice: ";
cin >> choice;
cout << "\n";
// Choice validation
switch (choice)
{
case 1: lookUpBook();
break;
case 2: addBook();
break;
case 3: editBook();
break;
case 4: deleteBook();
break;
case 5: cout << " You have chosen to return to the Main Menu.\n";
break;
default: cout << " Please enter a number in the range 1-5.\n";
}
cout << endl;
} while (choice != 5);
cout << "\n";
}
void bookInfo(string bookTitle[], string isbn[], string author[], string publisher[], string dateAdded[], int qtyOnHand[], double wholesale[], double retail[])
{
for (int i = 0; i < 20; i++)
{
// Read input
cout << " Serendipity Booksellers\n";
cout << " Book Information\n\n\n";
cout << " Title: " << bookTitle[i] << endl;
cout << " ISBN: " << isbn[i] << endl;
cout << " Author: " << author[i] << endl;
cout << " Publisher: " << publisher[i] << endl;
cout << " Date Added: " << dateAdded[i] << endl;
cout << " Quantity-On-Hand: " << qtyOnHand[i] << endl;
cout << " Wholesale Cost: " << wholesale[i] << endl;
cout << " Retail Price: " << retail[i] << endl;
}
}
void reports()
{
// Declarations for function
int choice;
// Constants for program
const int Inventory_listing = 1,
Inventory_wholesale = 2,
Inventory_retail = 3,
Listing_quantity = 4,
Listing_cost = 5,
Listing_age = 6,
Main_menu = 7;
do
{
// Read input
cout << " Serendipity Booksellers\n";
cout << " Reports\n\n";
cout << " 1. Inventory Listing\n";
cout << " 2. Inventory Wholesale Value\n";
cout << " 3. Inventory Retail Value\n";
cout << " 4. Listing by Quantity\n";
cout << " 5. Listing by Cost\n";
cout << " 6. Listing by Age\n";
cout << " 7. Return to Main Menu\n\n";
cout << " Enter Your Choice: ";
cin >> choice;
cout << "\n";
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: cout << " You have chosen to return to the Main Menu.\n";
break;
default: cout << " Please enter a number in the range 1-7.\n";
}
cout << endl;
} while (choice != 7);
cout << "\n";
}
// *******************************
// Inventory Database Functions *
// *******************************
void lookUpBook()
{
cin.ignore();
cout << " Please enter the title of the book: ";
getline(cin, searchTitle);
cout << "\n";
for (int i = 0; i < 20; i++)
{
if (searchTitle == bookTitle[i])
{
bookInfo(bookTitle, isbn, author, publisher, dateAdded, qtyOnHand, wholesale, retail);
break;
}
else
{
cout << " This book is not in the inventory.\n";
break;
}
}
cout << "\n";
}
void addBook()
{
for (int i = 0; i < 20; i++)
{
if (bookTitle[i] == "")
{
cout << " Please enter the information for the following:\n\n";
cin.ignore();
cout << " Enter the title of the book: ";
getline(cin, bookTitle[i]);
cout << " Enter the ISBN of the book in the form (X-XXX-XXXXX-X): ";
cin >> isbn[i];
cin.ignore();
cout << " Enter the name of the author: ";
getline(cin, author[i]);
cout << " Enter the name of the publisher: ";
getline(cin, publisher[i]);
cout << " Enter the date added, in the form (MM/DD/YYYY): ";
cin >> dateAdded[i];
cout << " Enter the quantity of the book being added: ";
cin >> qtyOnHand[i];
cout << " Enter the wholesale cost of the book: ";
cin >> wholesale[i];
cout << " Enter the retail price of the book: ";
cin >> retail[i];
cout << "\n";
cout << " The book information has been successfully entered.\n\n";
break;
}
else if (bookTitle[i] == bookTitle[20])
{
cout << " No more books may be added to the inventory!\n\n";
break;
}
}
}
void editBook()
{
cout << " You selected Edit Book.\n";
}
void deleteBook()
{
cout << " You selected Delete Book.\n";
}
// ************************
// Report Stub Functions *
// ************************
void repListing()
{
cout << " You selected Inventory Listing.\n";
}
void repWholesale()
{
cout << " You selected Inventory Wholesale Value.\n";
}
void repRetail()
{
cout << " You selected Inventory Retail Value.\n";
}
void repQty()
{
cout << " You selected Listing By Quantity.\n";
}
void repCost()
{
cout << " You selected Listing By Cost.\n";
}
void repAge()
{
cout << " You selected Listing By Age.\n";
}
---------------------------------------------------------------------------------------------------------------
Hello,
Instructions:
It should ask the user for the title of a book. This is the 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
The problems I am having:
I have done this, but I'm having trouble with my for loops.
In the addBook() function there is a break statement at the bottom because "I only need to enter the information once", not 20 times, but "I used a counter so I could fit the information in each subscript".
(I found out that because of the break statement, when i come around again to add a book, the information won't be found because the memory is already taken up for that subscript, due to it resetting everytime it runs through.)
In the bookInfo(....) function it is displaying the data 20 times, but once again "I only need the data shown for the title entered". I'm just confused because without the counter, it won't show the data for each matching subscript.
I need the lookUpBook() function to display the information, only if it matches the title searched.
Help if you can, please, thank you for your time.