Pascal Program to Create and Save Records in a Textfile

program Create_Records;
Type
Gra = String [30];
File_Content = Record
Name : Gra;
Matric_No : Gra;
Dept : Gra;
Sex : Gra;
Date_Of_Birth : Gra;
(*enter as many data as you like and intialise either as string, integer or char*);
End;

Var
 
       FileInfo : File_Content;
       Newfile : text;
        I : Integer;

Begin
Assign (newfile, 'Grace_Joseph.txt');
rewrite (Newfile);
      for i := 1 to 5 do
       begin
      writeln ('Enter name:');
      readln ( fileinfo.name);
       writeln ('matric number');
       readln (fileinfo.matric_No);
        writeln ('department');
       readln (fileinfo.dept);
        writeln ('sex');
        readln (fileinfo.sex);
        writeln ('date of  birth');
        readln (fileinfo.date_of_birth);
(*follow the above procedure to write and read the data you initialised*    )

writeln (newfile,' Name:', fileinfo.name)
writeln (newfile, 'matric number:', fileinfo.matric_no);
writeln (newfile,' Department: ', fileinfo.dept);
writeln (newfile,' Sex:', fileinfo.sex);
writeln (newfile,' Date Of Birth:', fileinfo.date_of_birth);
readln;
end;
close (newfile);
end.

In the program above, students records are saved in a textfile. You can rename the name of the textfile from Grace_Joseph.txt to yourDesired Name.txt. Goto the documents in your computer and search for the file using. the filename.txt.

The program creates a record for 5 students using the For Do loop.


Subscribe to TECHLASS by Email



Do you like this post? Please link back to this article by copying one of the codes below.

URL Of Post:


HTML Link Code:

BB (forum) link code:

Share on Google Plus

About Grace Joseph

Grace Joseph is from Cross River State, Nigeria. She studied Computer Science in University of Calabar and has great passion for writing, technology and blogging.

0 comments:

Post a Comment