This program actually about student registration system....with option in
the CASE option. I try very hard to do with link list and lost in space
(see coding). Something wrong with my open file section.... what I get in
the diskette are funny character instead of student data... why????
Lost in PAscal Code,
Kim
program StudentDatabaseApplication;
USES CRT,DOS;
TYPE
keytype = string;
module = record
subject : string;
classcode : string;
test : integer;
assignment : integer;
exam : integer;
grade : string;
end;
student_type = record
stud_name : string;
sex : string;
stud_ID : keytype;
modules : ARRAY[1..12] of module;
status : char;
end;
stud_ptr = ^studentDB;
studentDB = record
data : student_type;
next : stud_ptr;
end;
VAR
Student_file : FILE OF student_type;
{ Oldfile,newfile : FILE OF student_type;
Student, New_Student : student_type;}
List : stud_ptr;
procedure create_list(VAR list: stud_ptr);
begin
list := nil;
end;
function empty_list(list : stud_ptr): boolean;
begin
empty_list := (list = nil);
end;
function full_list(list: stud_ptr):boolean;
VAR
temp : stud_ptr;
begin
new(temp);
IF temp = nil THEN
full_list := TRUE
ELSE
begin
full_list := FALSE;
DISPOSE (TEMP);
end;
end;
procedure insert_data(VAR newrec: stud_ptr);
VAR
new_stud_rec : Student_type;
begin
clrscr;
new(newrec);
Assign(Student_file, 'a:\Student.dat');
Reset(Student_File);
Writeln;
Writeln;
Writeln(' N E W S T U D E N T R E C O R D E N T R
Y');
Writeln('
*****************************************************');
Writeln;
Writeln;
Write(' Student ID : ');
Readln(newrec^.data.stud_ID);
Write(' Student Name : ');
Readln(newrec^.data.stud_name);
Write(' Student Gender (M/F) : ');
Readln(newrec^.data.sex);
Write(' Student Status (Comp/Incomp): ');
Readln(newrec^.data.status);
newrec^.next := nil;
Write(Student_file,new_stud_rec);
Close(Student_file);
clrscr;
end;
procedure insert_rec(VAR list: stud_ptr; newrec:stud_ptr; VAR
success:boolean);
VAR
curr,prev : stud_ptr;
done,dup : boolean;
begin
prev := nil;
curr := list;
done := FALSE;
dup := FALSE;
WHILE (curr <> nil) AND (NOT done) DO
begin
IF (newrec^.data.stud_ID > curr^.data.stud_ID) THEN
begin
prev := curr;
curr := curr^.next;
end
ELSE
done := true
end;
IF (curr = nil) THEN
dup := false
ELSE
IF (newrec^.data.stud_ID <> curr^.data.stud_ID) THEN
dup := false
ELSE
dup := true;
IF (NOT dup) THEN
begin
IF (prev = nil) THEN
begin
newrec^.next := list;
list := newrec;
end
ELSE
begin
newrec^.next := curr;
prev^.next := newrec;
end;
success := true;
end
ELSE
success := FALSE;
end;
procedure locate(list: stud_ptr; target : keytype;
VAR wanted : stud_ptr);
VAR
curr : stud_ptr;
begin
curr := list;
WHILE (curr <> nil) AND (curr^.data.stud_ID <> target) DO
curr := curr^.next;
IF curr^.data.stud_ID = target THEN
wanted := curr
ELSE
wanted := nil;
end;
procedure get_ID(VAR wanted : keytype);
begin
clrscr;
Writeln;
Writeln;
Writeln(' L O C A T E S T U D E N T R E C O R D');
Writeln(' ***********************************************');
Writeln;
Writeln;
Write(' Student ID : ');
Readln(wanted);
end;
procedure add_record(VAR list: stud_ptr);
VAR
newrec : stud_ptr;
Another : char;
success, cont : boolean;
begin
REPEAT
cont := NOT full_list(list);
IF cont THEN
begin
insert_data(newrec);
insert_rec(list,newrec,success);
IF success THEN
writeln(' Student Record Added')
ELSE
writeln(' Student ID Already Exists...Student
Record Not Added');
end
ELSE
begin
writeln;
writeln;
writeln(' Insufficient memory...Unable To Add
Student Record...');
end;
delay(1000);
writeln;
writeln;
write(' Add Another Record (Y/N) ?....');
readln(another);
clrscr;
UNTIL (upcase(another) = 'N') OR (NOT cont);
end;
procedure Delete(VAR list: stud_ptr);
VAR
target : keytype;
prev, wanted : stud_ptr;
Student : student_type;
begin
clrscr;
Assign(Student_File, 'a:\Student.dat');
Reset(Student_File);
IF NOT empty_list(list) THEN
begin
get_ID(target);
locate(list, target, wanted);
IF wanted <> nil THEN
begin
prev := list;
IF
prev = wanted THEN
list := wanted^.next
ELSE
begin
WHILE prev^.next <> wanted DO
prev := prev^.next;
prev^.next := wanted^.next;
end;
DISPOSE(wanted);
end
ELSE
writeln;
writeln;
writeln(' No Such ID !...Record Not Deleted');
delay(1000);
end
ELSE
writeln;
writeln;
writeln(' List is EMPTY!!!');
delay(1000);
clrscr;
Rewrite(Student_File);
close(Student_File);
end;
procedure Update(VAR list: stud_ptr);
VAR
target : keytype;
prev, wanted : stud_ptr;
begin
clrscr;
IF NOT empty_list(list) THEN
begin
get_ID(target);
locate(list, target,wanted);
IF wanted <> nil THEN
begin
writeln;
writeln('Student ID : ', wanted^.data.stud_ID);
writeln('Student Name : ', wanted^.data.stud_name);
writeln('Student Gender : ', wanted^.data.sex);
writeln;
writeln('==============================================');
writeln;
write('Student Status : ');
readln(wanted^.data.status);
write('
procedure main_menu(VAR list:stud_ptr);
VAR
option: char;
begin
clrscr;
REPEAT
writeln;
writeln;
writeln(' S T U D E N T D A T A B A S E M A I N M E N U');
writeln('
*******************************************************');
writeln;
writeln;
writeln(' [1] ...............Insert Record');
writeln(' [2] ...............Delete Record');
writeln(' [3] ...............Update Record');
writeln(' [4] ...........List all students');
writeln(' [5] ....List students in a class');
writeln(' [6] .....List students in a unit');
writeln(' [7] ...........Save Student File');
writeln(' [9] ........................Quit');
writeln;
write(' Choose options : ');
readln(option);
CASE (option) OF
'1' : add_record(list);
'2' : delete(list);
'3' : update(list);
'4' : list_student(list);
'5' : list_class(list);
'6' : list_unit(list);
'7' : save_rec(list);
'9' :
ELSE
begin
writeln;
writeln(' Invalid Option!.. Please Try Again');
delay (1000);
clrscr;
end;
end;
UNTIL
option = '9';
writeln;
writeln(' ~~~ Thank You ~~~');
delay (1000);
clrscr;
end;
begin
create_list(list);
main_menu(list);
end.