Book_1.h


Again, the class Book is rewritten and improved. It makes the program more object-oriented.

 ~wenchen/public_html/cgi-bin/351/week8/Book_1.h 
#include  <cstdlib>
#include  <iostream>
#include  <cstring>
  using namespace  std;

#include  "itoa.h"
class  Book {
  private:
    char  title[129];
    char  ISBN[11];
    char  price[8];
    int   quantity;
  public:
    char*  GetValue( int i, char* buffer ) {
    switch ( i ) {
      case 1:  strcpy( buffer,   title );     break;
      case 2:  strcpy( buffer,   ISBN );      break;
      case 3:  strcpy( buffer,   price );     break;
      case 4:  itoa  ( quantity, buffer );    break;
      default: cout << "Error!" << endl; break;
    };
    return  buffer;
  };
  void  PutValue( int i, char* buffer ) {
    switch ( i ) {
      case 1:  strcpy( title, buffer );     break;
      case 2:  strcpy( ISBN,  buffer );     break;
      case 3:  strcpy( price, buffer );     break;
      case 4:  quantity = atoi( buffer );  break;
      default: cout << "Error!" << endl; break;
    };
  };
  void  PutResults( void ) {
    char  buffer[128];
    cout << "<br /><center>";
    cout << "<table width='95%' bgcolor='#EDF3FE' border='2' cellpadding='10'>";
    cout << "<tr bgcolor='#3366CC'><th><font color='white' size='+1'>Title</th>";
    cout << "<th><font color='white' size='+1'>ISBN</th>";
    cout << "<th><font color='white' size='+1'>Price</th>";
    cout << "<th><font color='white' size='+1'>Quantity</th>";
    cout << "</tr><td><font size='+1'>";
    cout << GetValue( 1, buffer ) << "</td><td align='center'><font size='+1'>";
    cout << GetValue( 2, buffer ) << "</td><td align='center'><font size='+1'>";
    cout << GetValue( 3, buffer ) << "</td><td align='center'><font size='+1'>";
    GetValue( 4, buffer );
    cout << buffer <<  "</td>";
    cout < "</tr></table></center>";
  };
};