I have designed the next program. It is the catalogue of a library. The problem is that if I want to find the book "the new world war" the program also finds other books (being the tiltle completely diferent). I want to modificate the code so that if I introduce the title "the new world war", I could find only the books that have this title. But, at the same time, I am interested in if I introduce the word "moment", to find all the books that contain in the title that word.
program pro;
{$APPTYPE CONSOLE}
uses SysUtils;
type
tbook = record
title : string[100];
author : string[100];
date : string[20];
end;
procedure searchtitle(book: array of tbook);
var
fbook : file of tbook;
title1,title2:string[100];
I,T,v_ascii:integer;
begin
assign (fbook, 'c:\dos.txt');
rewrite(fbook);
with book[0] do begin
title :='what a book';
author :='benjamin chesterton';
date :='1999';
end;
with book[1] do begin
title :='this is a story';
author :='juan antonio fernandez';
date :='2002';
end;
with book[2] do begin
title :='our world';
author :='ken follet';
date :='1995';
end;
with book[3] do begin
title :='do not loose it';
author :='raymond chandler';
date :='2005';
end;
with book[4] do begin
title :='the new world war';
author :='herman hesse';
date :='1991';
end;
with book[5] do begin
title :='mexican food';
author :='juan antonio fernandez';
date :='1991';
end;
with book[6] do begin
title :='interrupt our moment';
author :='john smith';
date :='1999';
end;
with book[7] do begin
title :='this is the moment';
author :='tahore mirkas';
date :='1998';
end;
for I:= 0 to 7 do
write(fbook, book[i]);
I := 0;
reset(fbook);
write(' Write the title of the book you want to find: ');
readln(title1);
writeln(' ');
writeln(' Results:');
For T:=1 to Length(title1) do
begin
if title1[T] = Upcase (title1[T]) then
begin
v_ascii:=ord(title1[T]);
title1[T]:=(chr(v_ascii+32));
end;
title2:=title1[T];
end;
while not EOF(fbook) do begin
read(fbook, book[i]);
if ansiPos( title2, book[I].title ) <> 0 then begin
writeln(' ');
writeln (' Book ',I, ' : ' , book[i].title, ' ', book[i].author, ' ', book[i].date);
writeln(' ');
I := I + 1;
end;
end;
close (fbook);
end;
var
book : array[0..7] of tbook;
opcion: char;
begin
repeat
writeln(' ');
writeln(' ');
writeln(' -----------------------------------------------');
writeln(' ');
writeln(' HOUSTON LIBRARY');
writeln(' ');
writeln(' ');
writeln(' Welcome to our catalogue.');
writeln(' ');
writeln(' 1.-Search by title');
writeln(' ');
writeln(' 2.-Search by author');
writeln(' ');
writeln(' -----------------------------------------------');
writeln(' ');
write(' Choose the option you want: ');
readln(opcion);
writeln(' ');
writeln(' ');
case opcion of
'1': begin
searchtitle(book);
end;
end;
until (opcion<'1')or (opcion>'2');
readln;
end.