Hello! I'm new to the DaniWeb, so I'm not sure what I'm allowed to ask, and I don't have enough time to search for all rules right now. I have to write a program for tomorrow, otherwise I won't be able to pass the year. It's a bit difficult to explain the organization with professors, so I got to write a program, before I even had a chance to learn the entire Pascal syntax - my prof. didn't teach my class everything so he will, but the day after I need this.
I have to write two programs in Turbo Pascal:
1. The first program should create a binary file and than write to it. It should read two values from a keyboard, the first representing the x coordinate, and the second representing the y coordinate of a point in a plane, and than write that to the file.
2. The second program should read from that binary file, and put its values into a single linked list, in the same order as it was in the file. After that program should remove the coordinates of the farthest point from the point (x=0 y=0), and remove linked list from memory.
First of all, I'm not quite sure how to create a binary file. I was thinking to do that the same way I would do for text files. Here's what I've done:
PROGRAM create; TYPE point = RECORD x: real; y: real; END; VAR output_file: FILE OF point; number, i: integer; ordinate, abscissa: point; BEGIN assign (output_file, 'out.dat'); rewrite (output_file); write (output, 'Enter a number of points in a plane: '); readln (input, number); FOR i := 1 TO number DO BEGIN write (output, 'Enter a coordinate of the ', i, '. point (x, y): '); readln (input, ordinate.x, abscissa.y); write (output_file, ordinate); write (output_file, abscissa); END; close (output_file); END.
Is the above code all right? Did I miss something?
And About the 2nd program, I don't know how to call the file out.dat and to read it's content.
I've tried something like this:
(** TYPE - The same as in first file **) PROCEDURE call_file(input_file: FILE OF point); VAR ordinate, abscissa: point; BEGIN assign (input_file, 'out.dat'); reset (input_file); (** Because I don't know how to create single list, I tried just to read the data **) WHILE NOT eof DO BEGIN read (input_file, ordinate.x); (** line problem **) read (input_file, abscissa.y); END; END;
When I used TP's debugger, program stops working in the line marked as line problem, but after it reads all values from the binary file - I get error message "Error 100 - Disk read error".
After that single linked list is another problem. It looks very confusing to me, and if anyone could type me those subprograms (procedures) I would appreciate very much. I'm trying to write and learn this for 5 whole days, and no luck.
Please help me! This means a lot to me.