My code is below; keep in mind it's not yet complete. For example, I still need to finish filling in the switch statement at the bottom. That shouldn't be affecting my current issue, however.
Attached is the .txt file necessary to run this application.
If any more information is required, please let me know. I'll be checking back often for responses. Thank you very much for any help/suggestions you are able to give.
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
const int MAX_BOOKS = 100;
class bookType
{
private:
string title; //item-name (some authors are included in this)
static const int numAuthors = 4;
string authors[numAuthors]; //authors
string publisher; //market
string ISBN; //product_id
string copies; //quantity
int i; //for searching by index (of array)
string item_name[MAX_BOOKS];
string author1[MAX_BOOKS];
string author2[MAX_BOOKS];
string author3[MAX_BOOKS];
string author4[MAX_BOOKS];
string quantity[MAX_BOOKS];
string price[MAX_BOOKS];
string product_id[MAX_BOOKS];
string market[MAX_BOOKS];
string book_header_line;
public:
void mainDisplay();
void setTitle();
void searchTitle();
void setAuthors();
void searchAuthors();
void setPublisher();
void searchPublisher();
void setISBN();
void searchISBN();
void setPrice();
void setCopies();
} myBooks[MAX_BOOKS];
int main()
{
ifstream inFile;
inFile.open("books.txt");
if(!inFile)
{
cout << "Unable to open input book file!" << endl ;
system ("pause");
}
else
{
myBooks[MAX_BOOKS].mainDisplay();
}
return 0;
}
void bookType::mainDisplay()
{
ifstream inFile;
ofstream outFile;
getline(inFile, book_header_line, '\n');
cout << book_header_line << endl;
i = 0;
cout << "test check 1" << endl;
system("Pause");
while(!inFile.eof() && i < MAX_BOOKS)
{
system("CLS");
getline(inFile, item_name[i], '\t');
getline(inFile, author1[i], '\t');
getline(inFile, author2[i], '\t');
getline(inFile, author3[i], '\t');
getline(inFile, author4[i], '\t');
getline(inFile, price[i], '\t');
getline(inFile, quantity[i], '\t');
getline(inFile, product_id[i], '\t');
getline(inFile, market[i], '\n');
cout << "\n Book " << i + 1 <<
"\t Title: " << item_name[i] <<
"\t Author 1: " << author1[i] <<
"\t Author 2: " << author2[i] <<
"\t Author 2: " << author3[i] <<
"\t Author 4: " << author4[i] <<
"\t Publisher: " << market[i] <<
"\t ISBN: " << product_id[i] <<
"\t Price: " << price[i] <<
"\t Quantity: " << quantity[i] << endl;
cout << "\n\n Continue in order, modify data, or perform a search?"
"\n\t 1) Next"
"\n\t 2) Previous"
"\n\n Modification Options:"
"\n\t 3) Modify Title"
"\n\t 4) Modify Author(s)"
"\n\t 5) Modify Publisher"
"\n\t 6) Modify Price"
"\n\t 7) Modify Quantity"
"\n\n Search Options:"
"\n\t 8) Search by i"
"\n\t 9) Search by Title"
"\n\t10) Search by Author"
"\n\t11) Search by Publisher"
"\n 12) Exit" << endl;
int choice;
do
{
cin >> choice;
switch (choice)
{
case 1:
{
i++;
myBooks[MAX_BOOKS].mainDisplay();
break;
}
case 2:
{
i--;
myBooks[MAX_BOOKS].mainDisplay();
break;
}
case 3:
{
break;
}
case 4:
{
break;
}
case 5:
{
break;
}
case 6:
{
break;
}
case 7:
{
break;
}
case 8:
{
break;
}
case 9:
{
break;
}
case 10:
{
break;
}
case 11:
{
break;
}
case 12:
{
break;
}
default:
{
cout << "Error: Invalid input." << endl;
break;
}
}
}
while (choice != 1 || choice != 2 || choice != 3 || choice != 4 || choice != 5 || choice != 6 || choice != 7 || choice != 8 || choice != 9 || choice != 10 || choice != 11 != 12);
}
//end while
}
//end mainDisplay();
Oh also, the class was provided with the following code as an example of how to read the necessary components of the .txt file.
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
#define MAX_BOOKS 500
int main()
{
ifstream inFile;
ofstream outFile;
string item_name [MAX_BOOKS];
string listing_id [MAX_BOOKS];
string seller_sku [MAX_BOOKS];
string price [MAX_BOOKS];
string quantity [MAX_BOOKS];
string open_date [MAX_BOOKS];
string item_note [MAX_BOOKS];
string item_condition [MAX_BOOKS];
string product_id [MAX_BOOKS];
string market [MAX_BOOKS];
string book_header_line;
int i;
double tPrice;
inFile.open("books.txt");
if(!inFile)
{
cout << "Unable to open input book file!" << endl ;
system ("pause");
return 1;
}
getline(inFile,book_header_line, '\n');
cout << book_header_line << endl;
i = 0;
while(!inFile.eof() && i < MAX_BOOKS)
{
getline(inFile,item_name[i], '\t');
getline(inFile,listing_id[i], '\t');
getline(inFile,seller_sku[i], '\t');
getline(inFile,price[i], '\t');
getline(inFile,quantity[i], '\t');
getline(inFile,open_date[i], '\t');
getline(inFile,item_note[i], '\t');
getline(inFile,item_condition[i], '\t');
getline(inFile,product_id[i], '\t');
getline(inFile,market[i], '\n');
tPrice = atof(price[i].c_str());
cout << item_name[i] << '\t' << listing_id[i] << '\t' << seller_sku[i] << '\t' << price[i] << '\t' << tPrice << '\t' << quantity[i] << '\t' << open_date[i] << '\t' << item_note[i] << '\t' << item_condition[i] << '\t' << product_id[i] << '\t' << market[i] << endl;
i++;
}
system("pause");
return 0;
}
Triple post but, the .txt file can be copy/pasted in Microsoft Excel/Open Office Calc for easier viewing, if you are curious as to the contents of the file.
Attached File(s)
-
books.txt (16.93K)
Number of downloads: 26

New Topic/Question
Reply



MultiQuote






|