Pascal database check

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2005
Posts: 2
Reputation: ucdmrt is an unknown quantity at this point 
Solved Threads: 0
ucdmrt ucdmrt is offline Offline
Newbie Poster

Pascal database check

 
0
  #1
Jun 4th, 2005
Hey wussup, im in a pascal class and I am currently working on a class assignment in which we have movie database program, the information for each movie is its name, length in minutes and year it came out. We have to use records to store the information. And my problem is that when I add a new movie, i dont know how to error check the name of the movie to the database and see if its already not there, when i type up a code i get "Operator is not overloaded"

Please respond so i can send you what i have so far and you can help me
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 31
Reputation: Jackrabbit is an unknown quantity at this point 
Solved Threads: 0
Jackrabbit Jackrabbit is offline Offline
Light Poster

Re: Pascal database check

 
0
  #2
Jun 7th, 2005
Pascal and Delphi Syntax (Toggle Plain Text)
  1. program movies;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6. Classes,
  7. SysUtils;
  8. type
  9. TMovie = record
  10. Name: string;
  11. RunTime: Integer;
  12. Year: Integer;
  13. end;
  14.  
  15. TMovies = array[0..4] of TMovie;
  16. var
  17. I: Integer;
  18. MyMovies: TMovies;
  19. begin
  20. // Initialize the database
  21. MyMovies[0].Name := 'Rocky';
  22. MyMovies[0].RunTime := 119;
  23. MyMovies[0].Year := 1976;
  24.  
  25. MyMovies[1].Name := 'Titanic';
  26. MyMovies[1].RunTime := 194;
  27. MyMovies[1].Year := 1997;
  28.  
  29. MyMovies[2].Name := 'Star Wars';
  30. MyMovies[2].RunTime := 121;
  31. MyMovies[2].Year := 1977;
  32.  
  33. MyMovies[3].Name := 'Batman';
  34. MyMovies[3].RunTime := 126;
  35. MyMovies[3].Year := 1989;
  36.  
  37. MyMovies[4].Name := 'True Grit';
  38. MyMovies[4].RunTime := 128;
  39. MyMovies[4].Year := 1969;
  40.  
  41. // Find the index for the movie Star Wars
  42. for I := Low(MyMovies) to High(MyMovies) do
  43. begin
  44. if UpperCase(MyMovies[I].Name) = 'STAR WARS' then
  45. begin
  46. writeln;
  47. writeln('Found Star Wars at index: ' + IntToStr(I));
  48. writeln;
  49. end;
  50. end;
  51. end.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2
Reputation: ucdmrt is an unknown quantity at this point 
Solved Threads: 0
ucdmrt ucdmrt is offline Offline
Newbie Poster

Re: Pascal database check

 
0
  #3
Jun 7th, 2005
thanks for the reply but thats not what im really looking for, here is my code

program p6;

type
movie = record
nametring;
hours:real;
year:integer;
end;

mov_arr = array[1..100] of movie;



var
{These should be the only global variables}
data : mov_arr;
size:integer;
ans:integer;

function add_mov(var name:string; data:mov_arr):movie;
var
tmp:movie;
ans:string;
x:boolean;
i: integer;
begin
x:=false;
repeat
writeln('Enter Movie Name');
readln(tmp.name);
writeln('Enter Length of Movie in minutes');
readln(tmp.hours);
writeln('Enter the year the movie was released');
readln(tmp.year);
writeln('Is this correct?');
writeln(tmp.name, tmp.hours, tmp.year);
until ans = 'yes';
add_mov := tmp;



end;

procedure write_file(data:mov_arr; size:integer);
var
fp:text;
name:string;
i:integer;
begin
writeln('Enter File');
readln(name);
assign(fp, name);
rewrite(fp);
for i:=1 to size do
begin
writeln(fp, data[i].name);
writeln(fp, data[i].hours);
writeln(fp, data[i].year);
end;
close(fp);
end;

procedure print_file();
var
fp:text;
name1:string;
name:string;
hours:real;
year:integer;
begin
writeln('Enter file name');
readln(name1);
assign(fp, name1);
reset(fp);
While not eof(fp) do
begin
readln(fp, name);
readln(fp, hours);
readln(fp, year);
writeln(name);
writeln(hours);
writeln(year);
end;
close(fp);
end;

begin{main}

{initial to size zero}
size:=0;

repeat
writeln;
writeln;
writeln('Options');
writeln('1: Display database');
writeln('2: Add movie');
writeln('3: Delete movie');
writeln('4: Sort');
writeln('5: Read from file');
writeln('6: Write to file');
writeln('0: To quit');
readln(ans);



{Each option must be a function/procedure call}

if ans = 1 then
{ Display all the movies' name length and year}



if ans = 2 then
{ Add a movie to the database but only if is isn't already in there.}

if ans = 3 then
{ Ask the user for a the name of the movie and delete it.
If it is not in the database, tell the user and do nothing}

if ans = 4 then

{ Ask the user how they want to sort: name, hours, or year
Then sort the database. Don't worry about ties.}



{
For options 5 and 6, you will be reading from a file.
The format of the file is

name of movie
hours
year

Each file may have between 1 and 100 movies recorss
}



if ans = 5 then

{
Ask the user for a file name and read the records from the file.
The database is initialized to the contents of the file and
any pre-existing data in the database is lost.
}




if ans = 6 then

{
Ask the user for a filename and write the data to the file in the proper format}



until ans = 0;


end.{main}
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 31
Reputation: Jackrabbit is an unknown quantity at this point 
Solved Threads: 0
Jackrabbit Jackrabbit is offline Offline
Light Poster

Re: Pascal database check

 
0
  #4
Jun 8th, 2005
If you modify what I posted slightly, it will work in your application.

Pascal and Delphi Syntax (Toggle Plain Text)
  1. { Change to procedure. You don't use the return value for anything. }
  2. procedure add_mov(var name:string; data:mov_arr);
  3. var
  4. tmp:movie;
  5. ans:string;
  6. i: integer;
  7. MovieFound: boolean;
  8. begin
  9. repeat
  10. writeln('Enter Movie Name');
  11. readln(tmp.name);
  12. writeln('Enter Length of Movie in minutes');
  13. readln(tmp.hours);
  14. writeln('Enter the year the movie was released');
  15. readln(tmp.year);
  16. writeln('Is this correct?');
  17. writeln(tmp.name, tmp.hours, tmp.year);
  18. until ans = 'yes';
  19.  
  20. { Search the array for a movie title matching the one the user entered. }
  21. MovieFound := False;
  22. for I := Low(data) to High(data) do
  23. begin
  24. if UpperCase(data[I].Name) = UpperCase(tmp.name) then
  25. begin
  26. MovieFound := True;
  27. Break;
  28. end;
  29. end;
  30.  
  31. { If the movie title wasn't found, add it to the array. }
  32. if not MovieFound then
  33. begin
  34. { Add the movie to the array. }
  35.  
  36. { You might consider using a dynamic array,
  37.   a TList object, or a linked list instead of
  38.   using a static array. How do you know how
  39.   many movies are already in the array? }
  40. end;
  41. end;
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Pascal and Delphi Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC