(**** 5.3. QuestionBank (editdb.rsl) * * Module QuestionBank defines the objects and operations related to using the * database to add, insert, view, mask, and modify questions in the database. * *) module QuestionBank; from Question import all; export all; object Question inherits from RawQuestion components: qid:QID, cd:CreationDate, md:ModifiedDate; description:(* adds the following fields SelectCell, QID, CreationDate and ModifiedDate *); end Question; object QuestionBank is components: q:Question* ; operations: AddQuestion, DeleteQuestion, SellectAll, MaskQuestions, SortQuestions, InsertSelectedQuestions, ZoomIn, ZoomOut; description: (* allows the user to quickly add, insert, modify, sort and delete questions in the database *); end QuestionBank; object QID is integer description:(* each question has a unique number in the question bank *); end QID; object CreationDate is integer description:(* indicates the date when the question was added to the question bank *); end CreationDate; object ModifiedDate is integer description:(* indicates the date and time the question was modified in the question bank *); end ModifiedDate; operation AddQuestion is inputs: qb:QuestionBank, q:Question; outputs: qb':QuestionBank; description:(*Add question to QuestionBank*); precondition:(*none*); postcondition:(* The question exists in QuestionBank *) (q in qb') and (* new question bank is old question bank plus qestion*) qb'=qb+q; end AddQuestion; operation MaskQuestions is inputs: qb:QuestionBank, qclass:Question.QuestionClassName, qtype:Question.QuestionType, qtime:Question.TimeToComplete; outputs: qb':QuestionBank; precondition:(* Question parameters like class name, type and time to complete are selected otherwise qb'=qb*) ; postcondition:(* Question matching input parameters are not in the database*) not((qclass in qb') and (qtype in qb') and (qtime in qb')) ; description: (*Mask fields in the question bank *); end MaskQuestion; operation SortQuestions is inputs: qb:QuestionBank; outputs: qb':QuestionBank; precondition: ; postcondition: ; description: (* takes the database with one header flagged and returns same database with question sorted according with the header field *); end SortQuestions; operation SelectQuestions is inputs: qb:QuestionBank, q:Question; outputs: qb':QuestionBank; precondition: ; postcondition: ; description: (*selects one or more questions in the question bank *); end Select; operation SelectAll is inputs: qb:QuestionBank; outputs: qb':QuestionBank, q:Question*; precondition: (* question bank is not empty*) not(qb=nil); postcondition: (* question bank has not changed and questions are selected*) qb'=qb and not(q=nil); description: (* selects all questions in the question bank *); end SelectAll; operation DeleteQuestions is inputs: qb:QuestionBank, q:Question; outputs: qb':QuestionBank; precondition:(*a question is selected and the question bank is not empty*) not((q=nil) and (qb=nil)); postcondition:(*selected question does not exist in the database*) qb'=qb-q; description: (* Deletes selected questions from the question bank *); end DeleteQuestions; operation InsertSelectedQuestions is inputs: qb:QuestionBank, q:Question*; outputs: qb':QuestionBank; precondition: (* this operation only works if the question bank is not empty and a at least a question is selected *) not((q=nil) and (qb=nil)); postcondition:qb=qb' ; description: (* Copy selected questions into current test *); end InsertSelectedQuestions; operation ZoomIn is inputs: qb:QuestionBank; outputs: qb':QuestionBank; precondition: ; postcondition: qb'=qb; description: (* the width and height of cells is incremented *); end ZoomIn; operation ZoomOut is inputs: qb:QuestionBank; outputs: qb':QuestionBank; precondition: ; postcondition: qb'=qb; description: (* the width and height of cells is decremented *); end ZoomOut; end QuestionBank;