Join 149,911 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,194 people online right now. Registration is fast and FREE... Join Now!
I am confused on how the data is printed or goes to the printer, and when it saves, where does it save to?
Here is the INPUT I used to print: Trigonometry ISBN:2389 Hostetler 7th Edition New/Yes $125 Quantity =40 Expected Enrollment=20
I then go to print menu to print the data, is it suppose to print out of the printer or is it simulated? Also the SAVE DATA option, it says data has been succesfuly saved, but where is it saved to?
CODE
// Program using pointer with array sructure.
#include "stdafx.h" #include <iostream> #include <cstdlib> #include <string> #include <stdio.h> #include <iomanip> #include <conio.h> #include <fstream> using namespace std; struct book { string title; string isbn; string author; string edition; string publisher; string new_used; string requirement; string price; string enrollment; int no_books; double all_val; struct book *next; }; void title_screen(); void page_continue(); void header(string); book *main_menu(); book *link_input(); book *input(); book *input(); void print_result(book *); void output_menu(book *); void one_item_out(book *); book *title_search(book *); book *isbn_search(book *); book *author_search(book *); void search_menu(book *); void print_output_table(book *); void field_print(string , int); void found_book(book *); void print_menu(book *); void print_all_result(book *, char*); int main(void) { title_screen(); book *stock; stock = main_menu(); return 0; } /*********************************************************** * Function Name: title_screen * * Date: 12/07/07* * Description of Output Parameters and * * Other Values Returned: void * * Purpose of Function: to display the titles * * Other functions called by this function: title_screen()* * Programmer Name: James Chavez* ***********************************************************/ void title_screen (void) { cout << setw(1); for (int count=0; count < 40; count++) cout<< "* "; cout << setw(1)<< "*" << setw(78)<< "*" <<endl; cout << setw(1)<< "*" << setw(22)<< "*" << setw(14)<< "*" << setw(15)<< "****" << setw(27)<< "*" <<endl; cout << setw(1)<< "*" << setw(22)<< "*" << setw(2)<< "*" << setw(10)<< "*" << setw(2)<< "*" << setw(10)<< "*" << setw(32)<< "*" <<endl; cout << setw(1)<< "*" << setw(22)<< "*" << setw(4)<< "*" << setw(6)<< "*" << setw(4)<< "*" << setw(10)<< "*" << setw(32)<< "*" <<endl; cout << setw(1)<< "*" << setw(22)<< "*" << setw(7)<< "*" << setw(7)<< "*" << setw(10)<< "*" << setw(32)<< "*" <<endl; cout << setw(1)<< "*" << setw(22)<< "*" << setw(14)<< "*" << setw(10)<< "*" << setw(32)<< "*" <<endl; cout << setw(1)<< "*" << setw(22)<< "*" << setw(14)<< "*" << setw(10)<< "*" << setw(32)<< "*" <<endl; cout << setw(1)<< "*" << setw(22)<< "*" << setw(14)<< "*" << setw(7)<< "IRAMAR" << setw(8)<< "****" << setw(7)<< "OLLEGE" << setw(20)<< "*" <<endl; cout << setw(1)<< "*" << setw(78)<< "*" <<endl; cout << setw(1)<< "*" << setw(24)<< "****" << setw(20)<< "*****" << setw(17)<< "****" << setw(17)<< "*" <<endl; cout << setw(1)<< "*" << setw(20)<< "*" << setw(5)<< "*" << setw(14)<< "*" << setw(6)<< "*" << setw(11)<< "*" << setw(22)<< "*" <<endl; cout << setw(1)<< "*" << setw(20)<< "*" << setw(5)<< "*" << setw(14)<< "*" << setw(6)<< "*" << setw(11)<< "*" << setw(22)<< "*" <<endl; cout << setw(1)<< "*" << setw(20)<< "*" << setw(5)<< "*" << setw(14)<< "*" << setw(6)<< "*" << setw(11)<< "*" << setw(22)<< "*" <<endl; cout << setw(1)<< "*" << setw(24)<< "*****" << setw(15)<< "*" << setw(6)<< "*" << setw(16)<< "****" << setw(17)<< "*" <<endl; cout << setw(1)<< "*" << setw(20)<< "*" << setw(5)<< "*" << setw(14)<< "*" << setw(6)<< "*" << setw(17)<< "*" << setw(16)<< "*" <<endl; cout << setw(1)<< "*" << setw(20)<< "*" << setw(5)<< "*" << setw(14)<< "*" << setw(6)<< "*" << setw(17)<< "*" << setw(16)<< "*" <<endl; cout << setw(1)<< "*" << setw(20)<< "*" << setw(5)<< "*" << setw(14)<< "*" << setw(6)<< "*" << setw(17)<< "*" << setw(16)<< "*" <<endl; cout << setw(1)<< "*" << setw(24)<< "****" << setw(10)<< "OOKSTORE" << setw(10)<< "*****" << setw(6)<< "RDER" << setw(11)<< "*****" << setw(7)<< "YSTEM" << setw(10)<< "*" <<endl; cout << setw(1)<< "*" << setw(78)<< "*" <<endl; cout << setw(1)<< "*" << setw(63)<< "Prepared by: James Chavez" << setw(15)<< "*"<<endl; cout << setw(1)<< "*" << setw(78)<< "*" <<endl; cout << setw(1); for (int count=0; count < 40; count++) cout<< "* "; page_continue(); system("cls"); }// end of title_screen() /*********************************************************** * Function Name: page_continue * * Date: 12/07/07 * * Description of Output Parameters and * * Other Values Returned: void * * Purpose of Function: to continue screens * * Other functions called by this function:page_continue()* * Programmer Name: James Chavez* ***********************************************************/ void page_continue(void) { string message1 = "Press <Enter> To Continue"; cout << setw(52)<< message1 << endl; while (!kbhit()); cin.get(); } // end of page_continue() /*********************************************************** * Function Name: header * * Date: 12/07/07 * * Description of Output Parameters and * * Other Values Returned: void * * Purpose of Function: to display the headers * * Other functions called by this function: header() * * Programmer Name: James Chavez * ***********************************************************/ void header(string subtitle) { string title1 = "MIRAMAR COLLEGE"; string title2 = "BOOKSTORE ORDER SYSTEM"; system ("cls"); cout << setw(1); for (int count=0; count < 40; count++) cout<< "* "; cout << setw(((80-title1.length())/2 + title1.length()))<<title1<<endl; cout <<endl; cout << setw(((80-title2.length())/2 + title2.length()))<<title2<<endl; cout <<endl; cout<<endl; cout << setw((( 80-subtitle.length())/2) + subtitle.length()) << subtitle << endl; cout << setw(1); for (int count=0; count < 40; count++) cout<< "* "; for (int i=0; i<2; i++) cout <<endl; }//end of void header(void) /*********************************************************** * Function Name: main_menu * * Date: 12/07/07 * * Description of Output Parameters and * * Other Values Returned: void and return start * * Purpose of Function: to chose the options I,O,or Q and * * do the function according to user * * input * * Other functions called by this function: main_menu() * * Programmer Name: James Chavez* ***********************************************************/ book *main_menu(void) { string result; book *start = NULL; book *last = NULL; book *temp = NULL; string title = "Main Menu"; string option1 = " <I>nput Data"; string option2 = " <O>utput Data"; string option3 = " <Q>uit"; string message1 = "Entry Error"; do { header(title); cout << setw(25)<< " "<< option1 <<endl; cout << setw(25)<< " "<< option2 <<endl; cout << setw(25)<< " "<< option3 <<endl; for (int i=0; i<4; i++) cout <<endl; cout << setw(35)<< "Enter I, O, or Q: "; getline(cin,result); switch(result.at(0)) { case 'I': case 'i': start = link_input(); page_continue(); break; case 'O': case 'o': temp = start; output_menu(temp); page_continue(); break; case 'Q': case 'q': break; default: cout<<"Your Entry was incorrect.\n" << endl; cout<<"The choices are : I,O, or Q" <<endl; cout<<"Press any key to continue"; cin.get(); page_continue(); } //end of switch(result) }while((result.at(0) != 'Q') && (result.at(0) != 'q')); return start; }// end of main_menu
/*********************************************************** * Function Name: output_menu * * Date: 12/08/07 * * Description of Output Parameters and * * Other Values Returned:(book *first) and return nothing * * Purpose of Function: to display the options (P,S,or Q) * * and do the function according to * * what user input * * Other functions called by this function: output_menu * * (first) * * Programmer Name: James Chavez* ***********************************************************/ void output_menu(book *first) { string resp; book* temp; string title = "Output Menu"; string option1 = "<P>rint Menu"; string option2 = "<S>earch Menu"; string option3 = "<Q>uit"; do { header(title); cout << "Do you want to go to print menu or search menu? "; cout << endl; cout << endl; cout << setw(25)<< " "<< option1 <<endl; cout << setw(25)<< " "<< option2 <<endl; cout << setw(25)<< " "<< option3 <<endl; for (int i=0; i<4; i++) cout <<endl; cout << setw(35)<< "Enter P, S, or Q: "; getline(cin,resp); switch(resp.at(0)) { case 'P': case 'p': temp = first; print_menu(temp); page_continue(); break; case 'S': case 's': temp = first; search_menu(temp); page_continue(); break; case 'Q': case 'q': break; default: cout<<"Your Entry was incorrect.\n" << endl; cout<<"The choices are : P,S, or Q" <<endl; cout<<"Press any key to continue"; cin.get(); page_continue(); } //end of switch(resp) }while((resp.at(0) != 'Q') && (resp.at(0) != 'q')); }//end of output_menu /*********************************************************** * Function Name: *link_input * * Date: 12/08/07 * * Description of Output Parameters and * * Other Values Returned: void and return book * * Purpose of Function: link list to data input * * Other functions called by this function: input * * Programmer Name: James Chavez * ***********************************************************/ book *link_input(void) { string title = "Input Screen"; string answer; book *first, *temp1, *temp2; header(title); temp1 = input(); cout << "Enter another book(Y/N):"; getline(cin,answer); first = temp1; while(answer.at(0) == 'Y' || answer.at(0) == 'y') { system("cls"); header(title); temp2 = input(); temp1->next = temp2; temp1 = temp2; cout << "Enter another book(Y/N):"; getline(cin,answer); } temp1->next = NULL; return first; }// end of *link_input /*********************************************************** * Function Name: *input * * Date: 12/08/07 * * Description of Output Parameters and * * Other Values Returned: void and return item * * Purpose of Function: to allow user input * * Other functions called by this function: input() * * Programmer Name: James Chavez* ***********************************************************/ book *input(void) { double order_fact = 0.0; book *item = new book; cout << "Enter book's title:"; getline(cin,item->title); cout << "Enter ISBN:"; getline(cin,item->isbn); cout << "Enter author of book:"; getline(cin,item->author); cout << "Enter edition of book:"; getline(cin,item->edition); cout << "Enter publisher of book:"; getline(cin,item->publisher); cout << "Enter New/Used(Y/N):"; getline(cin,item->new_used); cout << "Enter Requirement(Y/N):"; getline(cin,item->requirement); cout << "Enter price of book:"; getline(cin,item->price); cout << "Enter enrollment:"; getline(cin,item->enrollment); if (item->new_used.at(0) == 'Y' || item->new_used.at(0) == 'y') { if (item->requirement.at(0) == 'Y' || item->requirement.at(0) == 'y') order_fact = 0.60; else order_fact = 0.17; } else { if (item->requirement.at(0) == 'Y' || item->requirement.at(0) == 'y') order_fact = 0.45; else order_fact = 0.10; } item->no_books = atoi(item->enrollment.data()) * order_fact + 0.5; cout << setw(31)<< "Number of books ordered : " << item->no_books << endl; item->all_val = atof(item->price.data()) * item->no_books; cout << fixed << setw(14)<< setprecision (2)<< "Whole Value" << setw(18) << ": $" << item->all_val <<endl; cout << endl; item->next = NULL; return item; }//end of *input(void)
/*********************************************************** * Function Name: print_result * * Date: 12/09/07 * * Description of Output Parameters and * * Other Values Returned:(book *first) and return nothing * * Purpose of Function: to display the options (P,S,or Q) * * and do the function according to * * what user input * * Other functions called by this function: output_menu * * (first) * * Programmer Name: James Chavez* ***********************************************************/ void print_result(book *print_data, char* filename) { ofstream printer; printer.open(filename); printer << setw(50) << "MIRAMAR COLLEGE" << endl; printer << setw(55) << "BOOKSTORE ORDER SYSTEM" << endl; printer << endl; printer << setw(53) << "SEARCH DATA" << endl; printer << endl; printer << endl; printer << setw(13) << "Title: " << print_data->title << endl; printer << endl; printer << setw(14) << "ISBN: " << print_data->isbn << endl; printer << setw(15) << "Author: " << print_data->author << endl; printer << endl; printer << setw(14) << "Price: " << print_data->price << endl; printer << setw(19) << "Enrollment: " << print_data->enrollment << endl; printer << endl; printer << setw(17) << "New/Used: " << print_data->new_used << endl; printer << setw(21) << "Requirement : " << print_data->requirement << endl; printer << endl; printer << setw(24) << "Number to Order: " << print_data->no_books << endl; printer << setw(22) << "Total Value: $" << print_data->all_val << endl; printer << endl; printer.close(); }//end of void print_result(book *print_data, char* filename)
/*********************************************************** * Function Name: print_all_result * * Date: 12/10/07 * * Description of Output Parameters and * * Other Values Returned:(book *first) and return nothing * * Purpose of Function: to display the options (P,S,or Q) * * and do the function according to * * what user input * * Other functions called by this function: output_menu * * (first) * * Programmer Name: James Chavez * ***********************************************************/ void print_all_result(book *first, char* filename) { header("Save Data"); ofstream printer; printer.open(filename); book *temp; temp = first; printer << setw(15) << "Title"; printer << setw(20) << "ISBN"; printer << setw(25) << "Author"; printer << setw(15) << "Edition"; printer << setw(20) << "Publisher"; printer << setw(10) << "Price"; printer << setw(15) << "Quantity"; printer << setw(9) << "Total"; printer << endl; printer << setw(15) << "========="; printer << setw(14) << "========="; printer << setw(14) << "========="; printer << setw(13) << "========"; printer << setw(13) << "========"; printer << setw(8) << "====="; printer << setw(10) << "======"; printer << setw(9) << "======"; printer << endl; while(temp != NULL) { printer << setw(15) << temp->title; printer << setw(15) << temp->isbn; printer << setw(17) << temp->author; printer << setw(17) << temp->edition; printer << setw(14) << temp->publisher; printer << setw(8) << temp->price; printer << setw(10) << temp->no_books; printer << setw(16) << temp->all_val; printer << endl; temp = temp->next; } printer.close(); }//end of void print_result(book *print_data, char* filename)
/*********************************************************** * Function Name: print_output_table * * Date: 12/10/07 * * Description of Output Parameters and * * Other Values Returned:(book *first) and return nothing * * Purpose of Function: to display the options (P,S,or Q) * * and do the function according to * * what user input * * Other functions called by this function: output_menu * * (first) * * Programmer Name:James Chavez * ***********************************************************/ void print_output_table(book *temp_ptr) { header("Print List"); cout << setw(10) << "Title"; cout << setw(10) << "ISBN"; cout << setw(12) << "Author"; cout << setw(12) << "Edition"; cout << setw(11) << "Publisher"; cout << setw(7) << "Price"; cout << setw(9) << "Quantity"; cout << setw(9) << "Total"; cout << setw(10) << " ======"; cout << setw(10) << " ====="; cout << setw(12) << " ======="; cout << setw(12) << " ========"; cout << setw(11) << " ========="; cout << setw(7) << " ====="; cout << setw(9) << "========"; cout << setw(9) << " ======"; cout << endl; while(temp_ptr != NULL) { one_item_out(temp_ptr); temp_ptr = temp_ptr->next; } //end of while(first != NULL) } //end of void print_output_table(book *temp_ptr) /*********************************************************** * Function Name: one_item_out(book *one) * * Date: 12/13/07 * * Description of Output Parameters and * * Other Values Returned: (book *one) and return nothing * * Purpose of Function: to display the output table * * Other functions called by this function: one_item_out * * (one) * * Programmer Name: James Chavez* ***********************************************************/ void one_item_out(book *one) { field_print(one->title,10); field_print(one->isbn,10); field_print(one->author,12); field_print(one->edition,12); field_print(one->publisher,11); cout << setw(7) << one->price; cout << setw(9) << one->no_books; cout << setw(9) << one->all_val; }//end of one_item_out(book *one) /*********************************************************** * Function Name: field_print * * Date: 12/11/07 * * Description of Output Parameters and * * Other Values Returned:(book *first) and return nothing * * Purpose of Function: to display the options (P,S,or Q) * * and do the function according to * * what user input * * Other functions called by this function: output_menu * * (first) * * Programmer Name: James Chavez* ***********************************************************/ void field_print(string item, int length) { int ctr; if(item.length()<length) cout<< setw(length) << item; else for(ctr=0;ctr<length;ctr++) cout << item.at(ctr); }//void field_print(string item, int length)
/*********************************************************** * Function Name: found_book * * Date: 12/11/07 * * Description of Output Parameters and * * Other Values Returned:(book *first) and return nothing * * Purpose of Function: to display the options (P,S,or Q) * * and do the function according to * * what user input * * Other functions called by this function: output_menu * * (first) * * Programmer Name: James Chavez* ***********************************************************/ void found_book(book *thing) { string ans; if (thing == NULL) { cout << "Record Not Found!"; cout << endl; } else { cout << setw(10) << "Title"; cout << setw(10) << "ISBN"; cout << setw(12) << "Author"; cout << setw(12) << "Edition"; cout << setw(11) << "Publisher"; cout << setw(7) << "Price"; cout << setw(9) << "Quantity"; cout << setw(9) << "Total"; cout << setw(10) << " ======"; cout << setw(10) << " ====="; cout << setw(12) << " ======="; cout << setw(12) << " ========"; cout << setw(11) << " ========="; cout << setw(7) << " ====="; cout << setw(9) << "========"; cout << setw(9) << " ======"; cout << endl; one_item_out(thing); cout << endl; cout << "Do you want to save this data to file? (Y/N): "; getline(cin, ans); if(ans.at(0) == 'Y' || ans.at(0) == 'y') print_result(thing, "FoundData.txt"); } }//end of void found_book(*thing)
/**************************************************************** * Function Name: *title_search(book *one) * * Date: 12/11/07 * * Description of Output Parameters and * * Other Values Returned: (book *one) and return one * * Purpose of Function: to search with the title * * Other functions called by this function: title_search(one) * * Programmer Name: James Chavez* ****************************************************************/ book *title_search(book *one) { string ans; string title = "Search Title"; header(title); cout << "Enter book's title to search:"; getline(cin,ans); while((one != NULL) && (ans.compare(one->title) != 0)) one = one->next; return one; }//end of book *title(book *one) /**************************************************************** * Function Name: *isbn_search(book *one) * * Date: 12/11/07 * * Description of Output Parameters and * * Other Values Returned: (book *one) and return one * * Purpose of Function: to search with the isbn * * Other functions called by this function: isbn_search(one) * * Programmer Name: James Chavez* ****************************************************************/ book *isbn_search(book *one) { string buffer; string title = "Search ISBN"; header(title); cout << "Enter book's isbn to search:"; getline(cin,buffer); while((one != NULL) && (buffer.compare(one->isbn) != 0)) one = one->next; return one; }//end of book *isbn_search(book *one) /**************************************************************** * Function Name: *author_search(book *one) * * Date: 12/11/07 * * Description of Output Parameters and * * Other Values Returned: (book *one) and return one * * Purpose of Function: to search with the author * * Other functions called by this function: author_search(one) * * Programmer Name: James Chavez* ****************************************************************/ book *author_search(book *one) { string temp; string title = "Search Author"; header(title); cout << "Enter Author's name to search:"; getline(cin,temp); while((one != NULL) && (temp.compare(one->author) != 0)) one = one->next; return one; }//end of book *author_search(book *one) /*********************************************************** * Function Name: search_menu * * Date: 12/11/07 * * Description of Output Parameters and * * Other Values Returned:(book *strptr) and return nothing* * Purpose of Function: to display the options (T,I,Aor Q)* * and do the function according to * * what user input ` * * Other functions called by this function: search_menu * * (strptr) * * Programmer Name: James Chavez* ***********************************************************/ void search_menu(book *first) { book *found; book *temp; string buffer; string title = "Search Menu"; string option1 = "<T>itle"; string option2 = "<I>sbn"; string option3 = "<A>uthor"; string option4 = "<Q>uit"; string message = "Entry Error"; do { header(title); cout << "Enter how you like to search: "<< endl; cout << endl; cout << setw(25)<< " "<< option1 <<endl; cout << setw(25)<< " "<< option2 <<endl; cout << setw(25)<< " "<< option3 <<endl; cout << setw(25)<< " "<< option4 <<endl; for (int i=0; i<4; i++) cout <<endl; cout << setw(35)<< "Enter T, I, A, or Q: "; getline(cin,buffer); switch(buffer.at(0)) { case 't': case 'T': temp = first; found = title_search(temp); cout << endl; found_book(found); cout << endl; page_continue(); break; case 'i': case 'I': temp = first; found = isbn_search(temp); cout << endl; found_book(found); cout << endl; page_continue(); break; case 'a': case 'A': temp = first; found = author_search(temp); cout << endl; found_book(found); cout << endl; page_continue(); break; case 'q': case 'Q': break; default: cout<< setw(40)<< message<<endl; page_continue(); }// end of switch() }while((buffer.at(0) !='Q') && (buffer.at(0) !='q')); } // end of search_menu(void) /*********************************************************** * Function Name: print_menu * * Date: 12/11/07 * * Description of Output Parameters and * * Other Values Returned:(book *strptr) and return nothing* * Purpose of Function: to display the options (T,I,Aor Q)* * and do the function according to * * what user input ` * * Other functions called by this function: search_menu * * (strptr) * * Programmer Name: James Chavez* ***********************************************************/ void print_menu(book *first) { book *temp; string choice; string title = "Print Menu"; string option1 = "<P>rint data"; string option2 = "<S>ave data"; string option3 = "<Q>uit"; string message = "Entry Error"; do { header(title); cout << "Do you want to print or save data? Choose from the options given below: "<< endl; cout << endl; cout << endl; cout << setw(25)<< " "<< option1 <<endl; cout << setw(25)<< " "<< option2 <<endl; cout << setw(25)<< " "<< option3 <<endl; for (int i=0; i<4; i++) cout <<endl; cout << setw(35)<< "Enter P, S, or Q: "; getline(cin,choice); switch(choice.at(0)) { case 'p': case 'P': temp = first; print_output_table(temp); cout << endl; page_continue(); break; case 's': case 'S': temp = first; print_all_result(temp, "AllBooks.txt"); cout << "The Data has been successfully saved!"; cout << endl; cout << endl; page_continue(); break; case 'q': case 'Q': break; default: cout<< setw(40)<< message<<endl; page_continue(); }// end of switch() }while((choice.at(0) != 'Q') && (choice.at(0) != 'q')); }// end of void print_menu(book *first)
I thought I did post the code. Also, with my program I am basically trying to get every INPUT data saved in the C: drive whenever it asks to print or save option.That way I can just print the file from the C: drive. I did it for PRINT DATA from the PRINT MENU, but I don't know how to do it for SEARCH OPTION and SAVE DATA? Any help here, I would appreciate it
Ok I got the Input data to save to the C: drive from PRINT DATA OPTION, but how do I get it to save to the C: drive under SAVE DATA OPTION and SEARCH DATA OPTION?
#include "stdafx.h" #include <iostream> #include <cstdlib> #include <string> #include <stdio.h> #include <iomanip> #include <conio.h> #include <fstream> using namespace std; struct book { string title; string isbn; string author; string edition; string publisher; string new_used; string requirement; string price; string enrollment; int no_books; double all_val; struct book *next; }; void title_screen(); void page_continue(); void header(string); book *main_menu(); book *link_input(); book *input(); book *input(); void print_result(book *); void output_menu(book *); void one_item_out(book *); book *title_search(book *); book *isbn_search(book *); book *author_search(book *); void search_menu(book *); void print_output_table(book *); void field_print(string , int); void found_book(book *); void print_menu(book *); void print_all_result(book *, char*); int main(void) { title_screen(); book *stock; stock = main_menu(); return 0; } /*********************************************************** * Function Name: title_screen * * Date: 12/07/07* * Description of Output Parameters and * * Other Values Returned: void * * Purpose of Function: to display the titles * * Other functions called by this function: title_screen()* * Programmer Name: James Chavez* ***********************************************************/ void title_screen (void) { cout << setw(1); for (int count=0; count < 40; count++) cout<< "* "; cout << setw(1)<< "*" << setw(78)<< "*" <<endl; cout << setw(1)<< "*" << setw(22)<< "*" << setw(14)<< "*" << setw(15)<< "****" << setw(27)<< "*" <<endl; cout << setw(1)<< "*" << setw(22)<< "*" << setw(2)<< "*" << setw(10)<< "*" << setw(2)<< "*" << setw(10)<< "*" << setw(32)<< "*" <<endl; cout << setw(1)<< "*" << setw(22)<< "*" << setw(4)<< "*" << setw(6)<< "*" << setw(4)<< "*" << setw(10)<< "*" << setw(32)<< "*" <<endl; cout << setw(1)<< "*" << setw(22)<< "*" << setw(7)<< "*" << setw(7)<< "*" << setw(10)<< "*" << setw(32)<< "*" <<endl; cout << setw(1)<< "*" << setw(22)<< "*" << setw(14)<< "*" << setw(10)<< "*" << setw(32)<< "*" <<endl; cout << setw(1)<< "*" << setw(22)<< "*" << setw(14)<< "*" << setw(10)<< "*" << setw(32)<< "*" <<endl; cout << setw(1)<< "*" << setw(22)<< "*" << setw(14)<< "*" << setw(7)<< "IRAMAR" << setw(8)<< "****" << setw(7)<< "OLLEGE" << setw(20)<< "*" <<endl; cout << setw(1)<< "*" << setw(78)<< "*" <<endl; cout << setw(1)<< "*" << setw(24)<< "****" << setw(20)<< "*****" << setw(17)<< "****" << setw(17)<< "*" <<endl; cout << setw(1)<< "*" << setw(20)<< "*" << setw(5)<< "*" << setw(14)<< "*" << setw(6)<< "*" << setw(11)<< "*" << setw(22)<< "*" <<endl; cout << setw(1)<< "*" << setw(20)<< "*" << setw(5)<< "*" << setw(14)<< "*" << setw(6)<< "*" << setw(11)<< "*" << setw(22)<< "*" <<endl; cout << setw(1)<< "*" << setw(20)<< "*" << setw(5)<< "*" << setw(14)<< "*" << setw(6)<< "*" << setw(11)<< "*" << setw(22)<< "*" <<endl; cout << setw(1)<< "*" << setw(24)<< "*****" << setw(15)<< "*" << setw(6)<< "*" << setw(16)<< "****" << setw(17)<< "*" <<endl; cout << setw(1)<< "*" << setw(20)<< "*" << setw(5)<< "*" << setw(14)<< "*" << setw(6)<< "*" << setw(17)<< "*" << setw(16)<< "*" <<endl; cout << setw(1)<< "*" << setw(20)<< "*" << setw(5)<< "*" << setw(14)<< "*" << setw(6)<< "*" << setw(17)<< "*" << setw(16)<< "*" <<endl; cout << setw(1)<< "*" << setw(20)<< "*" << setw(5)<< "*" << setw(14)<< "*" << setw(6)<< "*" << setw(17)<< "*" << setw(16)<< "*" <<endl; cout << setw(1)<< "*" << setw(24)<< "****" << setw(10)<< "OOKSTORE" << setw(10)<< "*****" << setw(6)<< "RDER" << setw(11)<< "*****" << setw(7)<< "YSTEM" << setw(10)<< "*" <<endl; cout << setw(1)<< "*" << setw(78)<< "*" <<endl; cout << setw(1)<< "*" << setw(63)<< "Prepared by: James Chavez" << setw(15)<< "*"<<endl; cout << setw(1)<< "*" << setw(78)<< "*" <<endl; cout << setw(1); for (int count=0; count < 40; count++) cout<< "* "; page_continue(); system("cls"); }// end of title_screen() /*********************************************************** * Function Name: page_continue * * Date: 12/07/07 * * Description of Output Parameters and * * Other Values Returned: void * * Purpose of Function: to continue screens * * Other functions called by this function:page_continue()* * Programmer Name: James Chavez* ***********************************************************/ void page_continue(void) { string message1 = "Press <Enter> To Continue"; cout << setw(52)<< message1 << endl; while (!kbhit()); cin.get(); } // end of page_continue() /*********************************************************** * Function Name: header * * Date: 12/07/07 * * Description of Output Parameters and * * Other Values Returned: void * * Purpose of Function: to display the headers * * Other functions called by this function: header() * * Programmer Name: James Chavez * ***********************************************************/ void header(string subtitle) { string title1 = "MIRAMAR COLLEGE"; string title2 = "BOOKSTORE ORDER SYSTEM"; system ("cls"); cout << setw(1); for (int count=0; count < 40; count++) cout<< "* "; cout << setw(((80-title1.length())/2 + title1.length()))<<title1<<endl; cout <<endl; cout << setw(((80-title2.length())/2 + title2.length()))<<title2<<endl; cout <<endl; cout<<endl; cout << setw((( 80-subtitle.length())/2) + subtitle.length()) << subtitle << endl; cout << setw(1); for (int count=0; count < 40; count++) cout<< "* "; for (int i=0; i<2; i++) cout <<endl; }//end of void header(void) /*********************************************************** * Function Name: main_menu * * Date: 12/07/07 * * Description of Output Parameters and * * Other Values Returned: void and return start * * Purpose of Function: to chose the options I,O,or Q and * * do the function according to user * * input * * Other functions called by this function: main_menu() * * Programmer Name: James Chavez* ***********************************************************/ book *main_menu(void) { string result; book *start = NULL; book *last = NULL; book *temp = NULL; string title = "Main Menu"; string option1 = " <I>nput Data"; string option2 = " <O>utput Data"; string option3 = " <Q>uit"; string message1 = "Entry Error"; do { header(title); cout << setw(25)<< " "<< option1 <<endl; cout << setw(25)<< " "<< option2 <<endl; cout << setw(25)<< " "<< option3 <<endl; for (int i=0; i<4; i++) cout <<endl; cout << setw(35)<< "Enter I, O, or Q: "; getline(cin,result); switch(result.at(0)) { case 'I': case 'i': start = link_input(); page_continue(); break; case 'O': case 'o': temp = start; output_menu(temp); page_continue(); break; case 'Q': case 'q': break; default: cout<<"Your Entry was incorrect.\n" << endl; cout<<"The choices are : I,O, or Q" <<endl; cout<<"Press any key to continue"; cin.get(); page_continue(); } //end of switch(result) }while((result.at(0) != 'Q') && (result.at(0) != 'q')); return start; }// end of main_menu
/*********************************************************** * Function Name: output_menu * * Date: 12/08/07 * * Description of Output Parameters and * * Other Values Returned:(book *first) and return nothing * * Purpose of Function: to display the options (P,S,or Q) * * and do the function according to * * what user input * * Other functions called by this function: output_menu * * (first) * * Programmer Name: James Chavez* ***********************************************************/ void output_menu(book *first) { string resp; book* temp; string title = "Output Menu"; string option1 = "<P>rint Menu"; string option2 = "<S>earch Menu"; string option3 = "<Q>uit"; do { header(title); cout << "Do you want to go to print menu or search menu? "; cout << endl; cout << endl; cout << setw(25)<< " "<< option1 <<endl; cout << setw(25)<< " "<< option2 <<endl; cout << setw(25)<< " "<< option3 <<endl; for (int i=0; i<4; i++) cout <<endl; cout << setw(35)<< "Enter P, S, or Q: "; getline(cin,resp); switch(resp.at(0)) { case 'P': case 'p': temp = first; print_menu(temp); page_continue(); break; case 'S': case 's': temp = first; search_menu(temp); page_continue(); break; case 'Q': case 'q': break; default: cout<<"Your Entry was incorrect.\n" << endl; cout<<"The choices are : P,S, or Q" <<endl; cout<<"Press any key to continue"; cin.get(); page_continue(); } //end of switch(resp) }while((resp.at(0) != 'Q') && (resp.at(0) != 'q')); }//end of output_menu /*********************************************************** * Function Name: *link_input * * Date: 12/08/07 * * Description of Output Parameters and * * Other Values Returned: void and return book * * Purpose of Function: link list to data input * * Other functions called by this function: input * * Programmer Name: James Chavez * ***********************************************************/ book *link_input(void) { string title = "Input Screen"; string answer; book *first, *temp1, *temp2; header(title); temp1 = input(); cout << "Enter another book(Y/N):"; getline(cin,answer); first = temp1; while(answer.at(0) == 'Y' || answer.at(0) == 'y') { system("cls"); header(title); temp2 = input(); temp1->next = temp2; temp1 = temp2; cout << "Enter another book(Y/N):"; getline(cin,answer); } temp1->next = NULL; return first; }// end of *link_input /*********************************************************** * Function Name: *input * * Date: 12/08/07 * * Description of Output Parameters and * * Other Values Returned: void and return item * * Purpose of Function: to allow user input * * Other functions called by this function: input() * * Programmer Name: James Chavez* ***********************************************************/ book *input(void) { double order_fact = 0.0; book *item = new book; cout << "Enter book's title:"; getline(cin,item->title); cout << "Enter ISBN:"; getline(cin,item->isbn); cout << "Enter author of book:"; getline(cin,item->author); cout << "Enter edition of book:"; getline(cin,item->edition); cout << "Enter publisher of book:"; getline(cin,item->publisher); cout << "Enter New/Used(Y/N):"; getline(cin,item->new_used); cout << "Enter Requirement(Y/N):"; getline(cin,item->requirement); cout << "Enter price of book:"; getline(cin,item->price); cout << "Enter enrollment:"; getline(cin,item->enrollment); if (item->new_used.at(0) == 'Y' || item->new_used.at(0) == 'y') { if (item->requirement.at(0) == 'Y' || item->requirement.at(0) == 'y') order_fact = 0.60; else order_fact = 0.17; } else { if (item->requirement.at(0) == 'Y' || item->requirement.at(0) == 'y') order_fact = 0.45; else order_fact = 0.10; } item->no_books = atoi(item->enrollment.data()) * order_fact + 0.5; cout << setw(31)<< "Number of books ordered : " << item->no_books << endl; item->all_val = atof(item->price.data()) * item->no_books; cout << fixed << setw(14)<< setprecision (2)<< "Whole Value" << setw(18) << ": $" << item->all_val <<endl; cout << endl; item->next = NULL; return item; }//end of *input(void)
/*********************************************************** * Function Name: print_result * * Date: 12/09/07 * * Description of Output Parameters and * * Other Values Returned:(book *first) and return nothing * * Purpose of Function: to display the options (P,S,or Q) * * and do the function according to * * what user input * * Other functions called by this function: output_menu * * (first) * * Programmer Name: James Chavez* ***********************************************************/ void print_result(book *print_data, char* filename) { ofstream printer; printer.open("C:\\project5.txt"); //filename="C:\\project5.txt"; printer << setw(50) << "MIRAMAR COLLEGE" << endl; printer << setw(55) << "BOOKSTORE ORDER SYSTEM" << endl; printer << endl; printer << setw(53) << "SEARCH DATA" << endl; printer << endl; printer << endl; printer << setw(13) << "Title: " << print_data->title << endl; printer << endl; printer << setw(14) << "ISBN: " << print_data->isbn << endl; printer << setw(15) << "Author: " << print_data->author << endl; printer << endl; printer << setw(14) << "Price: " << print_data->price << endl; printer << setw(19) << "Enrollment: " << print_data->enrollment << endl; printer << endl; printer << setw(17) << "New/Used: " << print_data->new_used << endl; printer << setw(21) << "Requirement : " << print_data->requirement << endl; printer << endl; printer << setw(24) << "Number to Order: " << print_data->no_books << endl; printer << setw(22) << "Total Value: $" << print_data->all_val << endl; printer << endl; printer.close(); }//end of void print_result(book *print_data, char* filename)
/*********************************************************** * Function Name: print_all_result * * Date: 12/10/07 * * Description of Output Parameters and * * Other Values Returned:(book *first) and return nothing * * Purpose of Function: to display the options (P,S,or Q) * * and do the function according to * * what user input * * Other functions called by this function: output_menu * * (first) * * Programmer Name: James Chavez * ***********************************************************/ void print_all_result(book *first, char* filename) { header("Save Data"); ofstream printer; printer.open(filename); book *temp; temp = first; printer << setw(15) << "Title"; printer << setw(20) << "ISBN"; printer << setw(25) << "Author"; printer << setw(15) << "Edition"; printer << setw(20) << "Publisher"; printer << setw(10) << "Price"; printer << setw(15) << "Quantity"; printer << setw(9) << "Total"; printer << endl; printer << setw(15) << "========="; printer << setw(14) << "========="; printer << setw(14) << "========="; printer << setw(13) << "========"; printer << setw(13) << "========"; printer << setw(8) << "====="; printer << setw(10) << "======"; printer << setw(9) << "======"; printer << endl; while(temp != NULL) { printer << setw(15) << temp->title; printer << setw(15) << temp->isbn; printer << setw(17) << temp->author; printer << setw(17) << temp->edition; printer << setw(14) << temp->publisher; printer << setw(8) << temp->price; printer << setw(10) << temp->no_books; printer << setw(16) << temp->all_val; printer << endl; temp = temp->next; } printer.close(); }//end of void print_result(book *print_data, char* filename)
/*********************************************************** * Function Name: print_output_table * * Date: 12/10/07 * * Description of Output Parameters and * * Other Values Returned:(book *first) and return nothing * * Purpose of Function: to display the options (P,S,or Q) * * and do the function according to * * what user input * * Other functions called by this function: output_menu * * (first) * * Programmer Name:James Chavez * ***********************************************************/ void print_output_table(book *temp_ptr) { header("Print List"); cout << setw(10) << "Title"; cout << setw(10) << "ISBN"; cout << setw(12) << "Author"; cout << setw(12) << "Edition"; cout << setw(11) << "Publisher"; cout << setw(7) << "Price"; cout << setw(9) << "Quantity"; cout << setw(9) << "Total"; cout << setw(10) << " ======"; cout << setw(10) << " ====="; cout << setw(12) << " ======="; cout << setw(12) << " ========"; cout << setw(11) << " ========="; cout << setw(7) << " ====="; cout << setw(9) << "========"; cout << setw(9) << " ======"; cout << endl; while(temp_ptr != NULL) { one_item_out(temp_ptr); temp_ptr = temp_ptr->next; } //end of while(first != NULL) } //end of void print_output_table(book *temp_ptr) /*********************************************************** * Function Name: one_item_out(book *one) * * Date: 12/13/07 * * Description of Output Parameters and * * Other Values Returned: (book *one) and return nothing * * Purpose of Function: to display the output table * * Other functions called by this function: one_item_out * * (one) * * Programmer Name: James Chavez* ***********************************************************/ void one_item_out(book *one) { field_print(one->title,10); field_print(one->isbn,10); field_print(one->author,12); field_print(one->edition,12); field_print(one->publisher,11); cout << setw(7) << one->price; cout << setw(9) << one->no_books; cout << setw(9) << one->all_val; }//end of one_item_out(book *one) /*********************************************************** * Function Name: field_print * * Date: 12/11/07 * * Description of Output Parameters and * * Other Values Returned:(book *first) and return nothing * * Purpose of Function: to display the options (P,S,or Q) * * and do the function according to * * what user input * * Other functions called by this function: output_menu * * (first) * * Programmer Name: James Chavez* ***********************************************************/ void field_print(string item, int length) { int ctr; if(item.length()<length) cout<< setw(length) << item; else for(ctr=0;ctr<length;ctr++) cout << item.at(ctr); }//void field_print(string item, int length)
/*********************************************************** * Function Name: found_book * * Date: 12/11/07 * * Description of Output Parameters and * * Other Values Returned:(book *first) and return nothing * * Purpose of Function: to display the options (P,S,or Q) * * and do the function according to * * what user input * * Other functions called by this function: output_menu * * (first) * * Programmer Name: James Chavez* ***********************************************************/ void found_book(book *thing) { string ans; if (thing == NULL) { cout << "Record Not Found!"; cout << endl; } else { cout << setw(10) << "Title"; cout << setw(10) << "ISBN"; cout << setw(12) << "Author"; cout << setw(12) << "Edition"; cout << setw(11) << "Publisher"; cout << setw(7) << "Price"; cout << setw(9) << "Quantity"; cout << setw(9) << "Total"; cout << setw(10) << " ======"; cout << setw(10) << " ====="; cout << setw(12) << " ======="; cout << setw(12) << " ========"; cout << setw(11) << " ========="; cout << setw(7) << " ====="; cout << setw(9) << "========"; cout << setw(9) << " ======"; cout << endl; one_item_out(thing); cout << endl; cout << "Do you want to save this data to file? (Y/N): "; getline(cin, ans); if(ans.at(0) == 'Y' || ans.at(0) == 'y') print_result(thing, "FoundData.txt"); } }//end of void found_book(*thing)
/**************************************************************** * Function Name: *title_search(book *one) * * Date: 12/11/07 * * Description of Output Parameters and * * Other Values Returned: (book *one) and return one * * Purpose of Function: to search with the title * * Other functions called by this function: title_search(one) * * Programmer Name: James Chavez* ****************************************************************/ book *title_search(book *one) { string ans; string title = "Search Title"; header(title); cout << "Enter book's title to search:"; getline(cin,ans); while((one != NULL) && (ans.compare(one->title) != 0)) one = one->next; return one; }//end of book *title(book *one) /**************************************************************** * Function Name: *isbn_search(book *one) * * Date: 12/11/07 * * Description of Output Parameters and * * Other Values Returned: (book *one) and return one * * Purpose of Function: to search with the isbn * * Other functions called by this function: isbn_search(one) * * Programmer Name: James Chavez* ****************************************************************/ book *isbn_search(book *one) { string buffer; string title = "Search ISBN"; header(title); cout << "Enter book's isbn to search:"; getline(cin,buffer); while((one != NULL) && (buffer.compare(one->isbn) != 0)) one = one->next; return one; }//end of book *isbn_search(book *one) /**************************************************************** * Function Name: *author_search(book *one) * * Date: 12/11/07 * * Description of Output Parameters and * * Other Values Returned: (book *one) and return one * * Purpose of Function: to search with the author * * Other functions called by this function: author_search(one) * * Programmer Name: James Chavez* ****************************************************************/ book *author_search(book *one) { string temp; string title = "Search Author"; header(title); cout << "Enter Author's name to search:"; getline(cin,temp); while((one != NULL) && (temp.compare(one->author) != 0)) one = one->next; return one; }//end of book *author_search(book *one) /*********************************************************** * Function Name: search_menu * * Date: 12/11/07 * * Description of Output Parameters and * * Other Values Returned:(book *strptr) and return nothing* * Purpose of Function: to display the options (T,I,Aor Q)* * and do the function according to * * what user input ` * * Other functions called by this function: search_menu * * (strptr) * * Programmer Name: James Chavez* ***********************************************************/ void search_menu(book *first) { book *found; book *temp; string buffer; string title = "Search Menu"; string option1 = "<T>itle"; string option2 = "<I>sbn"; string option3 = "<A>uthor"; string option4 = "<Q>uit"; string message = "Entry Error"; do { header(title); cout << "Enter how you like to search: "<< endl; cout << endl; cout << setw(25)<< " "<< option1 <<endl; cout << setw(25)<< " "<< option2 <<endl; cout << setw(25)<< " "<< option3 <<endl; cout << setw(25)<< " "<< option4 <<endl; for (int i=0; i<4; i++) cout <<endl; cout << setw(35)<< "Enter T, I, A, or Q: "; getline(cin,buffer); switch(buffer.at(0)) { case 't': case 'T': temp = first; found = title_search(temp); cout << endl; found_book(found); cout << endl; page_continue(); break; case 'i': case 'I': temp = first; found = isbn_search(temp); cout << endl; found_book(found); cout << endl; page_continue(); break; case 'a': case 'A': temp = first; found = author_search(temp); cout << endl; found_book(found); cout << endl; page_continue(); break; case 'q': case 'Q': break; default: cout<< setw(40)<< message<<endl; page_continue(); }// end of switch() }while((buffer.at(0) !='Q') && (buffer.at(0) !='q')); } // end of search_menu(void) /*********************************************************** * Function Name: print_menu * * Date: 12/11/07 * * Description of Output Parameters and * * Other Values Returned:(book *strptr) and return nothing* * Purpose of Function: to display the options (T,I,Aor Q)* * and do the function according to * * what user input ` * * Other functions called by this function: search_menu * * (strptr) * * Programmer Name: James Chavez* ***********************************************************/ void print_menu(book *first) { book *temp; string choice; string title = "Print Menu"; string option1 = "<P>rint data"; string option2 = "<S>ave data"; string option3 = "<Q>uit"; string message = "Entry Error"; do { header(title); cout << "Do you want to print or save data? Choose from the options given below: "<< endl; cout << endl; cout << endl; cout << setw(25)<< " "<< option1 <<endl; cout << setw(25)<< " "<< option2 <<endl; cout << setw(25)<< " "<< option3 <<endl; for (int i=0; i<4; i++) cout <<endl; cout << setw(35)<< "Enter P, S, or Q: "; getline(cin,choice); switch(choice.at(0)) { case 'p': case 'P': temp = first; char *afile; //print_output_table(temp); print_result(temp,afile); cout << endl; page_continue();
break; case 's': case 'S': temp = first; print_all_result(temp, "AllBooks.txt"); cout << "The Data has been successfully saved!"; cout << endl; cout << endl; page_continue(); break; case 'q': case 'Q': break; default: cout<< setw(40)<< message<<endl; page_continue(); }// end of switch() }while((choice.at(0) != 'Q') && (choice.at(0) != 'q')); }// end of void print_menu(book *first)