#include <fstream>
#include <iostream>
#include <cstring>
using namespace std;
#include "Book_1.h"
#include "Overload.h"
|
|
|
int main( int argc, char* argv[ ] ) {
fstream index, file;
Book b;
int length, low, high, guess, result, count, offset;
char ISBN[11];
|
|
|
index.open( "index.txt", fstream::in );
index >> high >> length;
low = count = 1;
|
|
|
while ( low <= high ) {
guess = ( high + low ) / 2;
index.seekg ( 12+(guess-1)*length, fstream::beg );
index.getline( ISBN, 11, '|' );
index >> offset;
cout << count++ << " comparisons; checking ISBN: " << ISBN << "<br>";
if ( ( result = strcmp( argv[1], ISBN ) ) == 0 ) {
file2.open ( "data.txt", fstream::in );
file2.seekg( offset, fstream::beg );
file2 >> b;
b.PutResults( );
file2.close( );
break;
}
else if ( result < 0 )
high = guess - 1;
else
low = guess + 1;
}
|
|
|
if ( low > high ) {
cout << "<br><br><h2>ISBN: " << argv[1]
<< " is not found.</h2>";
}
index.close( );
}
|
|
|
|