2. Metalanguage Descriptions of Arrays and Records




Let us examine metalanguage descriptions for defining and using multi-dimensional arrays, arrays of records, files and random number generators in a variety of highlevel languages

1. Declaring multi-dimensional arrays and arrays of records

https://drive.google.com/open?id=0BwzvXeA1LcQuMzVTblJaNTNFSms

  1. Steps involved in declaring a variable:
    1. If data type does not exist - then must be defined
    2. A variable of that data type is declared
  2. Declaring Arrays, Files or Records:

    1. The TYPE statement is used to create a user defined data type.
    2. DefineDataType=
             TYPE <varname>=
                   (ARRAY”[“<range>{,<range>}”]”OF<type>)|
                   (FILE OF <type>)|
                   (RECORD<varname>:<type>{;<varname>:<type>}END);

              Eg.    Multidimensional Array
                      TYPE

          ProductType = ARRAY[0..19] OF Char;
          ProductArrayType = ARRAY[0..10,0..4,0..99] OF ProductType;

      VAR
          Products : ProductArrayType;

                         Record Type - comprising Fields of Arrays 

                       TYPE

                          CustomerRecType=
                                  RECORD
                                          Surname : ARRAY[1..20] OF Char;
                                          FirstName : ARRAY[1..20] OF Char;
                                          Gender : Char;
                                          Email : ARRAY[1..30] OF Char
                                  END;

                          CustomerType = ARRAY[1..500] OF CustomerRecType;   ## An Array of 500 Customer Records
                      VAR
                          Customers : CustomerType;

      2. Using Arrays of Records and Files

      Sample Algorithm to access a file to write Customer Records

      BEGIN StoreCustomers (FileName)

              Open Filename for output
              Count=0
              WHILE Count<=500
                      Write Filename from Customers(Count)
                      Add 1 to Count
              ENDWHILE
              Close Filename

      END StoreCustomers


      https://drive.google.com/open?id=0BwzvXeA1LcQuRlpFMVVQZTlHOGM





      Comments