5.6. Rooms Database (Rooms Database)

(****
 *
 * This file defines the objects and operations related to the Rooms
 * database view available to the user.
 *
 * See Section 2.3.3 of the Milestone 4 requirements.
 *
 *)

 
object RoomsDB
	components: RoomRecord*;
	operations: AddRoom, EditRoom, DeleteRoom, ViewRoom, FilterRooms;
	description: (*
		The RoomsDB contains the room records that provide information 
		about the rooms that can be scheduled.  
	*);
end RoomsDB;

object RoomRecord
	components: rid:Room_ID and build:Building and num:Room_Number and tp:Type and cp:Capacity and eqp:Equipment and mplc:Map_Location and Descrip;
	description: (*
		A RoomRecord has a RoomID, Building, and Room_Number which identify
		what the room is. The Subject, Title, Map_Location, and Descrip are both free-form strings.
		The Type indicates whether it is a Lecture or a Lab. The Capacity
		component is an integer representing the number of students that
		can be enrolled in the class. The Equipment component contains all the components the Room contains.
	*);
end RoomRecord;

object Room_ID = integer
	description: (*
		The Room ID of the course
	*);
end Room_ID;



object Room_Number = integer
	description: (*
		The room number of the room.
	*);
end Room_Number;



object Map_Location = string
	description: (*
		The location of the room on the campus grid. Ex. D4.
	*);
end Map_Location;

operation AddRoom
	inputs: rdb:RoomsDB, rr:RoomRecord;
	outputs: rdb':RoomsDB;
	
   precondition:
        (*
         * There is no room record in the input RoomDB with the same id as the
         * record to be added.
         *)
        (not (exists (rr' in rdb) rr'.rid = rr.rid))

            and

        (*
         * The id of the given room record is not empty and 5 characters or
         * less.
         *)
        (rr.rid != nil) and (#(rr.rid) <= 5)

            and

        (*
         * The building number is not empty.
         *)
        (rr.build != nil)

            and
            
        (*
         * The room number is not empty.
         *)
        (rr.num != nil);

    postcondition:
        (*
         * A room record is in the output db if and only if it is the new
         * record to be added or it is in the input db.
         *)
        (forall (rr':RoomRecord)
            (rr' in rdb') iff ((rr' = rr) or (rr' in rdb)));
   
   
	description: (*
		Add the given RoomRecord to the given RoomsDB.
		The Room_ID of the given room record must not be 
		the same as a room record already in the Room_ID.
	*);
end AddRoom;

operation EditRoom
	inputs: rdb:RoomsDB, rr:RoomRecord;
	outputs: rdb':RoomsDB;

  precondition:
        (*
         * There is no Room in the input RoomDB with the same Room_ID as the
         * record to be added.
         *)
        (not (exists (rr' in rdb) rdb'.rid = rdb.rid))

            and

        (*
         * The Room_ID of the given Room Record is not empty and 9 characters of
         * length.
         *)
        (rr.rid != nil) and (#(rr.rid) = 5)

            and


        (*
         * The building number is not empty.
         *)
        (rr.build != nil)

            and
            
        (*
         * The room number is not empty.
         *)
        (rr.num != nil);


    postcondition:
        (*
         * A Room is in the output db if and only if it is the new
         * Room to be added or it is in the input db.
         *)
        forall (rr':RoomRecord)
            (rr' in rdb') iff ((rr' = rr) or (rr' in rdb));

	description: (*
		Edit the given RoomRecord in the given RoomsDB.
		The given record must already be in the input db.
	*);
end EditRooom;

operation DeleteRoom
	inputs: rdb:RoomsDB, rr:RoomRecord;
	outputs: rdb':RoomsDB;

    precondition:
        (*
         * The given RoomRecord is in the given RoomDB.
         *)
        rr in rdb;

    postcondition:
        (*
         * A room record is in the output db if and only if it is not the
         * existing record to be deleted and it is in the input db.
         *)
        (forall (rr':RoomRecord)
            (rr' in rdb') iff ((rr' != rr) and (rr' in rdb)));


	description: (*
		Delete the given room record from the given RoomsDB.
		The given record must already be in the input db.
	*);
end DeleteRoom;

operation ViewRoom
	inputs: rdb:RoomsDB, rr:RoomRecord;
	outputs: rdb':RoomsDB;

    precondition:
        (*
         * The given RoomRecord is in the given RoomDB.
         *)
        rr in rdb;
    postcondition:
        (*
         * A room record is in the output db if and only if it is not the
         * existing record to be deleted and it is in the input db.
         *)
        (forall (rr':RoomRecord)
            (rr' in rdb') iff (rr' in rdb));

	description: (*
		View the given room record in the given RoomsDB.
		The given record must already be in the input db.
	*);
end ViewRoom;


operation FilterRooms
   inputs: rdb:RoomsDB, roomid:Room_ID;
   outputs: rrl:RoomRecord*;
    description: (*
        Find a room or rooms by room id.  If more than one is found,
        the output list is sorted by id.
    *);

    precondition: ;

    postcondition:
        (*
         * The output list consists of all records of the given name in the
         * input db.
         *)
        (forall (rr' in rrl) (rr' in rdb) and (rr'.rid = roomid))

            and

        (*
         * The output list is sorted alphabetically by Building Number.
         *)
        (forall (i:integer | (i >= 1) and (i < #rrl))
            rrl[i].build < rrl[i+1].build);

end FilterRooms;

operation FilterRooms
   inputs: rdb:RoomsDB, building:Building;
   outputs: rrl:RoomRecord*;
    description: (*
        Find a room or rooms by Building.  If more than one is found,
        the output list is sorted by id.
    *);

    precondition: ;

    postcondition:
        (*
         * The output list consists of all records of the given name in the
         * input db.
         *)
        (forall (rr' in rrl) (rr' in rdb) and (rr'.build = building))

            and

        (*
         * The output list is sorted alphabetically by id.
         *)
        (forall (i:integer | (i >= 1) and (i < #rrl))
            rrl[i].rid < rrl[i+1].rid);

end FilterRooms;

operation FilterRooms
   inputs: rdb:RoomsDB, roomnumber:Room_Number;
   outputs: rrl:RoomRecord*;
    description: (*
        Find a room or rooms by Room_Number.  If more than one is found,
        the output list is sorted by id.
    *);

    precondition: ;

    postcondition:
        (*
         * The output list consists of all records of the given name in the
         * input db.
         *)
        (forall (rr' in rrl) (rr' in rdb) and (rr'.num = roomnumber))

            and

        (*
         * The output list is sorted alphabetically by id.
         *)
        (forall (i:integer | (i >= 1) and (i < #rrl))
            rrl[i].rid < rrl[i+1].rid);

end FilterRooms;







Prev: schedule.sl | Next: admin.sl | Up: spec | Top: index