Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3021

Adding/Searching/Editing Arrays - Serendipity Booksellers Project

$
0
0
Hello everyone. I was wondering if there was anyone that could help me with this code. Under the invtmenu.cpp file, I need to be able to add a book, look up a book, edit a book, and delete a book. (void addbook(), void editbook(), etc.. all of which can be placed inside the invtmenu.cpp file) I know a little bit of how I am to set it up, but I can not get anything to work. I know this is not the most challenging thing in the world, but this is the only concept I have had trouble understanding. If anyone could help out just by getting me started, I would deeply appreciate it.



Code:

#include "cashier.hpp"
#include "invtmenu.hpp"
#include "bookinformation.hpp"//3. include header file
#include "reports.hpp"
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

const int SIZE = 10;//1. declared before main function
string isbn[SIZE];// = {""}; 2. passing parameters
string title[SIZE];// = {""};
string author[SIZE];// = {""};
string publisher[SIZE];// = {""};
string dateAdded[SIZE];// = {""};
int qty[SIZE];// = {0};
double wholeCost[SIZE];// = {0.0};
double retail[SIZE];// = {0.0};


int main ()
{
int menu_choice;

do
{
cout << "\n\t\t\t\t\t\t\t\t " << " Serendipity Booksellers \n ";
cout << "\t\t\t\t\t\t\t\t\t" << " Main Menu \n\n";
cout << "\t\t\t\t\t\t\t\t " << "1." << " Cashier Module \n";
cout << "\t\t\t\t\t\t\t\t " << "2." << " Inventory Database Module \n";
cout << "\t\t\t\t\t\t\t\t " << "3." << " Report Module \n";
cout << "\t\t\t\t\t\t\t\t " << "4." << " Exit \n\n";
cout << "\t\t\t\t\t\t\t\t " << "Enter your choice: ";
cin >> menu_choice;
cout << "\n\n\n";



switch (menu_choice)
{
case 1:

cout << "\t\t\t\t\t\t\t\t " << "You have selected 1. Cashier Module. \n";
cashier();
break;
case 2:

cout << "\t\t\t\t\t\t\t\t " << "You have selected 2. Inventory Database Module. \n";
invtmenu();
break;
case 3:
cout << "\t\t\t\t\t\t\t\t " << "You have selected 3. Report Module \n";
reports();
break;
case 4:
cout << "\t\t\t\t\t\t\t\t " << "You have selected 4. Exit \n";
break;

default:
cout << "\t\t\t\t\t\t\t\t " << "Please enter a number 1 - 4.\n";


}
cout << endl;
} while (menu_choice != 4);// fixed bug with putting in default, entry 4 = exit, and switch is inside loop
cout << "\n\n";

return 0;
}


//reports.cpp

//
// reports.cpp
// SBS_Part_6
//
// Created by Eric on 3/30/16.
// Copyright © 2016 Eric. All rights reserved.
//


#include <iostream>

using namespace std;

void reports()
{
int choice;

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



while ( choice < 1 || choice > 7)
{
cout << "\t\t\t\t\t\t\t\t" << "Please Enter A Number 1-7" << endl << endl;
cin >> choice;
}
switch (choice)
{
case 1:

cout << "\t\t\t\t\t\t\t " << "You have selected 1." << " Inventory Listing \n";
break;

case 2:

cout << "\t\t\t\t\t\t\t " << "You have selected 2." << " Inventory Wholesale Value \n";
break;

case 3:

cout << "\t\t\t\t\t\t\t " << "You have selected 3." << " Inventory Retail Value \n";
break;

case 4:

cout << "\t\t\t\t\t\t\t " << "You have selected 4." << " Listing by Quantity \n";
break;

case 5:

cout << "\t\t\t\t\t\t\t " << "You have selected 5." << " Listing by Cost \n";
break;

case 6:

cout << "\t\t\t\t\t\t\t " << "You have selected 6." << " Listing by Age \n";
break;

case 7:

cout << "\t\t\t\t\t\t\t " << "Returning to main menu\n";
break;
default:
cout << "\t\t\t\t\t\t\t " << "Please enter a number 1 - 7.\n";
}
}while ( choice !=7);
}



//cashier.cpp


#include<iostream>
#include<iomanip>
#include<cstring>
using namespace std;

void cashier()
{

int qty;
float price;
double subtotal, tax, total;
char date[10], isbn[20], title[40], again;


cout << "\t\t\t\t\t\t\t Serendipity Booksellers" << endl;
cout << " \t\t\t\t\t\t\t Cashier Module" << endl << endl;
for(int count = 0; count < 20; count++)
{
cout << "\t\t\t\t\t\t\t Date: ";
cin >> date;
cout << "\t\t\t\t\t\t\t Quantity of Book: ";
cin >> qty;
cout << "\t\t\t\t\t\t\t ISBN: ";
cin >> isbn;
cin.ignore();
cout << "\t\t\t\t\t\t\t Title: ";
cin.getline (title, 40);
cout << "\t\t\t\t\t\t\t Price: ";
cin >> price;
cout << endl << endl;

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




cout << "\t\t\t\t\t\t\t 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 << "Would you like to do another (y/n)" << endl;
cin >> again;
cout << endl;
if (again == 'N' || again == 'n') {
break;
}

cout << endl;
}

}

//invtmenu.cpp

#include <iostream>
#include "bookinformation.hpp"
#include <string>
#include <cstring>
using namespace std;

const int SIZE = 10;
extern string title[SIZE];
extern string isbn[SIZE];
extern string author[SIZE];
extern string publisher[SIZE];
extern string dateAdded[SIZE];
extern int qty[SIZE];
extern double wholeCost[SIZE];
extern double retail[SIZE];
//void addbook();
void invtmenu()
{
int choice;
do
{
cout << "\n\t\t\t\t\t\t\t\t" << "Serendipity Booksellers \n ";
cout << "\t\t\t\t\t\t\t\t" << " Inventory Database \n\n";
cout << "\t\t\t\t\t\t\t\t" << "1." << " Look Up a Book \n";
cout << "\t\t\t\t\t\t\t\t" << "2." << " Add a Book \n";
cout << "\t\t\t\t\t\t\t\t" << "3." << " Edit a Book's Record \n";
cout << "\t\t\t\t\t\t\t\t" << "4." << " Delete a Book \n";
cout << "\t\t\t\t\t\t\t\t" << "5." << " Return to Main Menu\n\n ";
cout << "\t\t\t\t\t\t\t\t" << "Enter Your Choice: ";
cin >> choice;

while ( choice < 1 || choice > 5 )
{
cout << "\t\t\t\t\t\t\t\t\t" << " Enter a number 1-5";
cin >> choice;
}
switch (choice)
{
case 1:
cout << "\t\t\t\t\t\t\t\t\t" << " You have selected Look up a book\n";
//void lookupbook();
break;

case 2:
cout << "\t\t\t\t\t\t\t\t\t" << " You have selected Add a book\n";
void addbook();
break;

case 3:
cout << "\t\t\t\t\t\t\t\t\t" << " You have selected Edit a book's record\n";
break;

case 4:
cout << "\t\t\t\t\t\t\t\t\t" << " You have selected Delete a book\n";
break;

case 5:
cout << "\t\t\t\t\t\t\t\t\t" << " You will be returned to the main menu\n";
break;
default:
cout << "\t\t\t\t\t\t\t\t\t" << "Enter a number 1 - 5\n";//bug fix, enter default
}
} while ( choice != 5);




//return 0;

}




//bookinformation.cpp

//i was just putting some extra stuff in as notes, i assumed it's going to look close to this eventually anyway.
//i just followed your instructions from the hints on angel

#include <iostream>
#include "bookinformation.hpp" //3. include header file.

using namespace std;

void bookinformation (string isbn, string title, string author, string publisher, string dateAdded, int qty, double wholeCost, double retail)// 1. change the name. 2. pass the parameters.
{
//for (int i = 0; i < 20; i++)
//{

cout << "\n\t\t\t\t\t\t\t" << " Serendipity Booksellers \n ";
cout << "\t\t\t\t\t\t\t\t" << " Book Info \n\n";
cout << "\tISBN: \n";// << isbn[i] << endl;
cout << "\tTitle: \n"; //<< title[i] << endl;
cout << "\tAuthor: \n";// << author[i] << endl;
cout << "\tPublisher: \n"; // << publisher[i] << endl;
cout << "\tDate Added: \n"; //<< dateAdded[i] << endl;
cout << "\tQuantity-On-Hand: \n"; //<< qty[i] << endl;
cout << "\tWholesale Cost: \n"; //<< wholeCost[i] << endl;
cout << "\tRetail Price: \n"; //<< "\n" << retail[i] << endl;

//}



}


Viewing all articles
Browse latest Browse all 3021

Trending Articles