PROGRAM Test_Schema_Params( input, output ); { This program demonstrates the use of discriminated and undiscriminated schema parameters. A file is opened which contains the number of students along with a list of each student, their social security number and their class. Totals are calculated for the number of freshmen, sophmores, juniors, and seniors. } CONST Example_Dir_Specification = 'SYS$COMMON:[SYSHLP.EXAMPLES.PASCAL]'; { Get the number of students from the first line in the file } FUNCTION Get_Number_Of_Students : INTEGER; VAR Students_File : TEXT; Num_Students : INTEGER; BEGIN OPEN( file_name := Example_Dir_Specification+'SCHEMA_PARAMETERS.DAT', file_variable := Students_File, history := OLD ); RESET( students_File ); READLN( Students_File, Num_Students ); CLOSE( Students_File ); Get_Number_Of_Students := Num_Students; END; TYPE Student_Record = RECORD Student_Name : STRING(20); Student_SS : STRING(10); Student_Class: (FR, SO, JR, SR ); END; Student_List_Template(a,b : INTEGER) = ARRAY [a..b] OF Student_Record; Student_List = Student_List_Template( 1, Get_Number_Of_Students ); VAR School : STRING(20) VALUE 'Central High School'; Logo : STRING(20) VALUE 'The Panthers'; Students : Student_List; PROCEDURE Write_School_Banner( School_Name : STRING; School_Logo : STRING ); VAR Blank : STRING(10) VALUE PAD( '', ' ', 10); BEGIN WRITELN( '*****************************************'); WRITELN( '* *'); WRITELN( Blank, School_Name ); WRITELN( Blank, School_Logo ); WRITELN( '* *'); WRITELN( '*****************************************'); WRITELN; END; { Read students from file } PROCEDURE Get_Students( VAR Students : Student_List_Template ); VAR Index : INTEGER; Students_File : TEXT; BEGIN OPEN( file_name := Example_Dir_Specification+'SCHEMA_PARAMETERS.DAT', file_variable := Students_File, history := OLD ); RESET ( Students_File ); READLN( Students_File ); { skip number of students } FOR Index := Students.a TO Students.b DO BEGIN READLN( Students_File, Students[Index].Student_Name ); READLN( Students_File, Students[Index].Student_SS ); READLN( Students_File, Students[Index].Student_Class ); END; CLOSE( Students_File ); END; { Write Students to SYS$OUTPUT } PROCEDURE Write_Students( Students : Student_List ); VAR Index : INTEGER; BEGIN FOR Index := Students.a TO Students.b DO BEGIN WRITELN; WRITELN( Students[Index].Student_Name ); WRITELN( Students[Index].Student_SS ); WRITELN( Students[Index].Student_Class ); END; END; { Calculate totals for each class } PROCEDURE Find_Class_Total( Students : Student_List ); VAR Index, Fresh, Soph, Juni, Seni : INTEGER := 0; BEGIN FOR Index := Students.a TO Students.b DO BEGIN CASE Students[Index].Student_Class OF FR : Fresh := Fresh + 1; SO : Soph := Soph + 1; JR : Juni := Juni + 1; SR : Seni := Seni + 1; OTHERWISE WRITELN( 'Student Without A Class' ); END; END; WRITELN; WRITELN( 'The number of freshman = ', fresh ); WRITELN( 'The number of sophomore = ', soph ); WRITELN( 'The number of juniors = ', juni ); WRITELN( 'The number of seniors = ', seni ); END; BEGIN Write_School_Banner( School, Logo ); Get_Students( Students ); Write_Students( Students ); Find_Class_Total( Students ); END.