I'm a newie and am in the process of trying to develop a book store as part of a class project. I would greatly appreciate any assistance that may be offered my way. Please do not give me any answers, but if you have any suggestions that may nudge me in the right direction I would be thankful. I must store the inventory of the books in an array of classes. Here is the code I have written so far.
#include <iostream>
#include <iomanip>
#include <string>
#define MAX 100 //Maximum number of books in inventory array
using namespace std;
class CBooks //Class definition
{
public:
//Constructor
CBooks(string bookName = "0", string author = "0", int isbn = 000000000,
float price = 0.00): _bookName(bookName), _author(author),
_isbn(isbn), _price(price){}
//Destructor
~CBooks(){};
//Functions
void inputBooks(string bookName, string author, int isbn, float price);
void displayBooks(string bookName, string author, int isbn, float price);
private:
string _bookName; //Name of book
string _author; //Author of book
int _isbn; //ISBN of book
float _price; //Price of book
}inventory[MAX]; //Array of class objects
//Functions
double getProfit(double doublePrice);
void viewProfit();
int current; //Used to count number of books in inventory
double netProfit = 0;
//Main Function
int main()
{
//Declare variables
int x = 0, transaction, another = 2, choice;
double bookProfit, priceArray[99];
string seller, password, bookInfo[99];
while (another != 1)
{
system("CLS");
//display section header
cout << "***********************\n";
cout << "*Team A Book Inventory*\n";
cout << "***********************\n\n";
cout << "Please type the number of the desired action and press <ENTER>:\n" ;
cout << "1. Buy\n";
cout << "2. Sell\n";
cout << "3. View Profit\n";
cin >> transaction;
cin.ignore(); //statement is necessary in order to make cin.getline() to work properly.
//Tells cin to ignore the line feed at the end of input
//code to view profit
if (transaction == 3)
{
viewProfit();
}
// code to sell a textbook
if (transaction == 2)
{
if (x<=99)
{
system("CLS");
//display section header
cout << "***********\n";
cout << "*Sell Book*\n";
cout << "***********\n\n";
CBooks::inputBooks();
x++;
}
else
{
cout << "I'm sorry, the database cannot hold any more books.\n"; //print if more then 100 books in inventory
}
}
//code to buy book
if (transaction == 1)
{
system("CLS"); //clear screen
//display section header
cout << "**********\n";
cout << "*Buy Book*\n";
cout << "**********\n\n";
cout << "Book Name " << "Book Author " << "ISBN " << "Price\n"; //print buy header
cout << "--------- " << "----------- " << "---- " << "-----\n\n"; //print buy header
CBooks::displayBooks();
cout << "\nPlease enter the number of the book you would like to buy:\n";
cin >> choice; //the number choosen
cout << "Thank you for your purchase!\n\n";
bookProfit = getProfit(priceArray[choice-1]); //call function to figure out profit of the book
netProfit += bookProfit; //add book profit to total profit
bookInfo[choice-1] = "SOLD"; //over write selection with the word SOLD
priceArray[choice-1] = 0; //right 0 to element
}
cout << "\nPlease type the number of the desired action and press <ENTER>:\n"; //print option make another trans
cout << "1. Quit program\n"; //quit program
cout << "2. Make another transaction\n"; //make another trans
cin >> another; //get answer
if (another == 1) //check if user selected exit
{
cout << "WARNING!! Data will be lost if program is exited. Are you sure you want to exit?\n"; //print warning about loosing data
cout << "1. Yes, please exit.\n";
cout << "2. No, stay in program.\n";
cin >> another; //get answer again
}
}
return 0;
}
//Checks password and diplays profit
void viewProfit()
{
string password;
system("CLS");
//display header section
cout << "*************\n";
cout << "*View Profit*\n";
cout << "*************\n\n";
cout << "Please type your password:\n";
cin >> password;
if (password == "upwd") //check password
{
cout << "Profit = $" << netProfit << "\n";
}
else
{
cout << "Invalid password.\n";
}
system("PAUSE");
}
//Input books into inventory function
void CBooks::inputBooks()
{
cout << "Please enter the book's name: \n";
cin.getline(bookName, 64);
_bookName = bookName;
cout << "Please enter the book's author: \n";
cin.getline(author, 64);
_author = author;
cout << "Please enter the book's ISBN: \n";
cin.getline(isbn, 10);
cin.ignore();
_isbn = isbn;
cout << "Please enter the desired price: \n";
cin >> price;
cin.ignore();
_price = price;
//Increments the number of books entered into inventory
current++;
cout << "There are now " << current << "books for in our inventory.";
}
//Diplay books in inventory function
void CBooks::displayBooks(void)
{
int loop;
//Display all of the books in inventory
for (loop = 0; loop < 99; loop++)
{
cout << inventory[loop].bookName;
cout << inventory[loop].author;
cout << inventory[loop].isbn;
cout << inventory[loop].price;
}
}
//Calculates the 10% profit and pass to called instance
double getProfit(double doublePrice)
{
return doublePrice*.1;
}
As of now, I'm not able to get it to compile, because of the 4 errors listed below.
(80) : error C2660: 'CBooks::inputBooks' : function does not take 0 arguments
(100) : error C2660: 'CBooks::displayBooks' : function does not take 0 arguments
(155) : error C2511: 'void CBooks::inputBooks(void)' : overloaded member function not found in 'CBooks'
d:\My Documents\Visual Studio Projects\Book Store\Test.cpp(9) : see declaration of 'CBooks'
(177) : error C2511: 'void CBooks::displayBooks(void)' : overloaded member function not found in 'CBooks'
d:\My Documents\Visual Studio Projects\Book Store\Test.cpp(9) : see declaration of 'CBooks'
Thanks in advance for any guidance offered.