Thursday, October 10, 2024

Data file using Pascal Sample Program

Data file using Pascal

program studentdatafiles;

const
  fname=  'students.dat'   ;

type
   StudentRecord = Record
      s_name: String[25];
      s_add: String[30];
      s_phone: String[20];

   end;

var
   Student: StudentRecord;
   f: file of StudentRecord;
   n:char;
procedure Addrec() ;
begin
  Assign(f,fname);
  Rewrite(f);
  n:='Y'  ;
  while  (n='Y') do
  begin
        Write('Enter Your Name ?');
        Readln(Student.s_name);
        Write('Enter your Address ?');
        Readln(Student.s_add);
        Write('Enter your Phone No ?');
        Readln(Student.s_phone);

        Write(f,Student);
        Write('Do you have another record to write (Y/N)?' );
        Readln(n);
        writeln();
  end;

  Close(f);
end;
procedure Readrec() ;
begin
  Assign(f,fname);
  Reset(f);
  writeln('Name','Address','Phone');
  while not eof(f) do
   begin
      read(f,Student);
      writeln(Student.s_name,Student.s_add,Student.s_Phone);
   end;

   close(f);
end;

begin
   Addrec();
   Readrec();
   Readln;
end.

Sample Output


Data File using Pascal Program

No comments:

Post a Comment