5.4 Instructor Database (InstructorDB.sl)

 
5.4 Instructor Database (InstructorDB.sl)

 (****
 *
 * This file defines objects and operation related to the instructor database.
 *
 *)

object InstructorDB
  components: ins:Instructor*;
  description: (*
    The InstructorDB is the database that contains all the instructors that 
    have been inputed into the system.  All Instructors are added into this 
    database using the operation of addInstructor and those added can be edited 
    later using the editInstructor operation.
  *);
end InstructorDB;

object Instructor
  components: empid:EMPID and name:Name and email:Email
                 and wtu:WTU and office:Office and phone:Phone
                 and disabilities:Disabilities;
  description: (*
    The instructor is the data that is inserted into the instructor database.  
    An instructor contains many components that can be added and edited and 
    are saved into an Instructor using the addInstructor and editInstructor 
    operations.
  *);
end Instructor;

object Name
  components: firstname:FirstName and lastname:LastName;
  description: (*
    This is the first and last name of the instructor.
  *);
end Name;

object EMPID = integer 
  description: (*
    This is the Id of the Instructor.
  *);
end EMPID;

object FirstName = string
  description: (* 
    This is the first name in the Name of the Instructor.
  *);
end FirstName;

object LastName = string
  description: (* 
    This is the last name in the Name of the Instructor.
  *);
end LastName;

object Email = string
  description: (* 
    This is the valid university email of the Instructor.
  *);
end Email;

object Office = string
  description: (* 
    This is the building and room of the Instructor's office hours.
  *);
end Office;

object Phone = integer
  description: (* 
    This is the university phone number of the Instructor.
  *);
end Phone;

object Disabilities = string
  description: (* 
    This lists any relavent disabilities of the Instructor.
  *);
end Disabilities;


operation addInstructor
  inputs: idb: InstructorDB, ins: Instructor;
  outputs: idb': InstructorDB;
  
  description: (*
    This will add a new Instructor to the Instructor database.
  *);
  
  precondition:
        (*
         * There is no Instructor in the input InstructorDB with the same EMPID as the
         * record to be added.
         *)
        (not (exists (ins' in idb) ins'.empid = ins.empid))

            and

        (*
         * The EMPID of the given Instructor is not empty and 9 characters of
         * length.
         *)
        (ins.empid != nil) and (#(ins.empid) = 9)

            and

        (*
         * The Name contains 2 strings for first and last name .
         *)
        (ins.name.firstname != nil) and (ins.name.lastname != nil)

            and

        (*
         * The email address is not empty.
         *)
        (ins.email != nil)

            and

        (*
         * The WTU is not empty.
         *)
        (ins.wtu != nil)

            and

        (*
         * The Office is not empty.
         *)
        (ins.office != nil)

            and

        (*
         * The phone number must be 10 digits long.
         *)
        (if (ins.phone != nil) then (#(ins.phone) = 10));

        (*
         * The Disabilities may be filled with anything.
         *)

    postcondition:
        (*
         * A Instructor is in the output db if and only if it is the new
         * Instructor to be added or it is in the input db.
         *)
        forall (ins':Instructor)
            (ins' in idb') iff (ins' = ins) or (ins' in idb);
            
end addInstructor;

operation editInstructor
  inputs: idb: InstructorDB, ins: Instructor;
  outputs: idb': InstructorDB;
  
  precondition:
        (*
         * There is no Instructor in the input InstructorDB with the same EMPID as the
         * record to be added.
         *)
        (not (exists (ins' in idb) ins'.empid = ins.empid))

            and

        (*
         * The EMPID of the given Instructor is not empty and 9 characters of
         * length.
         *)
        (ins.empid != nil) and (#(ins.empid) = 9)

            and

        (*
         * The Name contains 2 strings for first and last name .
         *)
        (ins.name.firstname != nil) and (ins.name.lastname != nil)

            and

        (*
         * The email address is not empty.
         *)
        (ins.email != nil)

            and

        (*
         * The WTU is not empty.
         *)
        (ins.wtu != nil)

            and

        (*
         * The Office is not empty.
         *)
        (ins.office != nil)

            and

        (*
         * The phone number must be 10 digits long.
         *)
        (if (ins.phone != nil) then (#(ins.phone) = 10));

        (*
         * The Disabilities may be filled with anything.
         *)

    postcondition:
        (*
         * A Instructor is in the output db if and only if it is the new
         * Instructor to be added or it is in the input db.
         *)
        forall (ins':Instructor)
            (ins' in idb') iff ((ins' = ins) or (ins' in idb));
  
  description: (*
    This will change the inputed instructor in the database dependant on all 
    the fields that have been changed inside the Instructor.
  *);
end editInstructor;





Prev: view.sl | Next: options.sl | Up: spec | Top: index