/* My name is Scott McIrvin, I wrote this stuff and the bookclass.h include thing It is a tad bit thrown together, just because another class also needed a program wrote :( */ #include #include #include #include "bookclass.h" using namespace std; void nofile(); void main_menu(); void exit_screen(); void error(); int searchedbook; void main() { ifstream infile; infile.open("datafile.txt"); if(!infile) nofile(); else { int inputsize; infile >> inputsize; booktype *book; book = new booktype [SIZE]; int inputcount, subcount; for(inputcount = 0; inputcount < inputsize; inputcount++) { infile >> book[inputcount].btitle; infile >> book[inputcount].inputauthors; book[inputcount].authorarray = new string [AUTHORS]; for(subcount = 0; subcount < book[inputcount].inputauthors; subcount++) { infile >> book[inputcount].authorarray[subcount]; } infile >> book[inputcount].bpublisher; infile >> book[inputcount].bisbn; infile >> book[inputcount].bprice; infile >> book[inputcount].bstock; } // data is loaded in from infile infile.close(); ofstream outfile; outfile.open("output.txt"); bool quit; int main_selection; do { char setchoice; bool changequit = false; char change; string testisbn; string testtitle; string testauthor; bool exit = false; bool found = false; int count = 0; string testpub; main_menu(); cin >> main_selection; switch(main_selection) { case 1: system("cls"); cout << "search by title" << endl << endl; cout << "please put in the title -> "; cin >> testtitle; cin.ignore(100, '\n'); while(exit == false) { exit = false; exit = book[count].setequaltitle(testtitle); if(exit == true) { searchedbook = count; found = true; } count++; if(count == inputcount) exit = true; } quit = false; break; case 2: system("cls"); cout << "search by author" << endl << endl; cout << "please put in an author -> "; cin >> testauthor; cin.ignore(100, '\n'); while(exit == false) { exit = false; exit = book[count].setequalauthor(testauthor); if(exit == true) { searchedbook = count; found = true; } count++; if(count == inputcount) exit = true; } quit = false; break; case 3: system("cls"); cout << "search by publisher" << endl << endl; cout << "please input a publisher -> "; cin >> testpub; cin.ignore(100, '\n'); while(exit == false) { exit = false; exit = book[count].setequalpub(testpub); if(exit == true) { searchedbook = count; found = true; } count++; if(count == inputcount) exit = true; } quit = true; break; case 4: system("cls"); cout << "Search by ISBN" << endl << endl; cout << "Please provide an ISBN number: "; cin >> testisbn; while(exit == false) { exit = false; exit = book[count].setequalisbn(testisbn); if(exit == true) { searchedbook = count; found = true; } count++; if(count == inputcount) exit = true; } quit = false; break; case 5: exit_screen(); for(inputcount = 0; inputcount < inputsize; inputcount++) { outfile << "Book #" << (inputcount + 1) << "." << endl; outfile << "Title: " << book[inputcount].btitle << endl; outfile << "Author: "; for(subcount = 0; subcount < book[inputcount].inputauthors; subcount++) { outfile << book[inputcount].authorarray[subcount] << " "; if( subcount != book[inputcount].inputauthors-1) outfile << "and "; } outfile << endl; outfile << "Publisher: " << book[inputcount].bpublisher << endl; outfile << "ISBN: " << book[inputcount].bisbn << endl; outfile.setf(ios::fixed); outfile.setf(ios::showpoint); outfile.precision(2); outfile << "Price: $" << book[inputcount].bprice << endl; outfile << "Amount in stock: " << book[inputcount].bstock << endl << endl; } quit = true; break; default:error(); quit = false; } if(found == true) { while(changequit == false) { system("cls"); cout << "The book was found" << endl; book[searchedbook].showbook(); cout << endl; cout << "Would you like to change anything about this record? (Y/N) -> "; cin >> change; cin.ignore(100, '\n'); switch(change) { case 'y': case 'Y': system("cls"); book[searchedbook].showbook(); cout << endl; cout << "ok which one would you like to change" << endl; cout << "1. the title" << endl; cout << "2. the authors" << endl; cout << "3. the publisher" << endl; cout << "4. the isbn" << endl; cout << "5. the price" << endl; cout << "6. the stock available" << endl; cout << "choose one (1-6) -> "; cin >> setchoice; cin.ignore(100, '\n'); switch(setchoice) { case '1':book[searchedbook].settitle(); break; case '2':book[searchedbook].setauthor(); break; case '3':book[searchedbook].setpub(); break; case '4':book[searchedbook].setisbn(); break; case '5':book[searchedbook].setprice(); break; case '6':book[searchedbook].updatestocknum(); break; default: system("cls"); cout << "let's try again...."; getch(); changequit = false; } break; case 'n': case 'N': changequit = true; system("cls"); cout << "back to main menu then"; getch(); break; default: changequit = false; system("cls"); cout << "let's try doing this right"; getch(); } } } else { if(main_selection != 5) { system("cls"); cout << "The book was not found, back to main menu"; getch(); } } }while(quit == false); outfile.close(); delete [] book; } getch(); } void nofile() { system("cls"); cout << "There is no input file!" << endl; } void main_menu() { system("cls"); cout << "Please choose how you would like to pull up a book." << endl << endl; cout << "1. Search by Title" << endl; cout << "2. Search by Author" << endl; cout << "3. Search by Publisher" << endl; cout << "4. Search by ISBN" << endl; cout << "5. Quit the program" << endl << endl; cout << "Please choose an option: "; } void exit_screen() { system("cls"); cout << "we are done"; } void error() { system("cls"); cout << "There was an error, please press a key and try again."; getch(); }