// Fig. 19.22: shop.cpp // Program to display available books. #include using std::cerr; using std::cout; using std::ios; #include using std::ifstream; #include using std::string; #include using std::exit; void header(); int main() { // variables to store product information char book[ 50 ] = ""; char year[ 50 ] = ""; char isbn[ 50 ] = ""; char price[ 50 ] = ""; string bookString = ""; string yearString = ""; string isbnString = ""; string priceString = ""; ifstream userData( "catalog.txt", ios::in ); // open file for input // file could not be opened if ( !userData ) { cerr << "Could not open database."; exit( 1 ); } // end if header(); // output header // output available books cout << "

Books available for sale

" << ""; // file is open while ( userData ) { // retrieve data from file userData.getline( book, 50 ); bookString = book; userData.getline( year, 50 ); yearString = year; userData.getline( isbn, 50 ); isbnString = isbn; userData.getline( price, 50 ); priceString = price; cout << ""; // file is still open after reads if ( userData ) { // output form with buy button cout << "\n"; } // end if cout << "\n"; } // end while cout << "
" << bookString << "" << yearString << "" << isbnString << "" << priceString << "
" << "" << "" << "\n

" << "Check Out" << ""; return 0; } // end main // function to output header information void header() { cout << "Content-Type: text/html\n\n"; // output header // output XML declaration and DOCTYPE cout << "" << ""; // output html element and some of its contents cout << "" << "Shop Page"; } // end function header /************************************************************************** * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and * * Pearson Education, Inc. All Rights Reserved. * * * * DISCLAIMER: The authors and publisher of this book have used their * * best efforts in preparing the book. These efforts include the * * development, research, and testing of the theories and programs * * to determine their effectiveness. The authors and publisher make * * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * * and publisher shall not be liable in any event for incidental or * * consequential damages in connection with, or arising out of, the * * furnishing, performance, or use of these programs. * **************************************************************************/