module QuestionDatabase; from Question import QuestionDB, Question, TestQuestion, AnsweredQuestion, GradedQuestion, QuestionText, Type, Class, LastUsed, Keywords, Author, Time, Difficulty, AutoGrade, CorrectAnswer, QuestionNumber; operation SearchQuestionDatabase is inputs: qdb:QuestionDB, c:Class; outputs: ql:Question*; description: (* Find a question or questions by class. If more than one is found, output list is sorted by keyword. *); precondition: (* None *); postcondition: (* * The output list consists of all questions of the given class in the input db. *) (forall (q:Question) (q in ql) iff (q in qdb) and (q.class = c)) and (* * The output list is sorted in alphabetical order *) (forall (i:integer | (i >= 1) and (i < #ql)) ql[i].class < ql[i + 1].class); end SearchQuestionDatabase; operation SearchQuestionDatabase is inputs: qdb:QuestionDB, tp:Type; outputs: ql:Question*; description: (* Find a question or questions by type. If more than one is found, output list is sorted by keyword. *); precondition: (* None*); postcondition: (* * The output list consists of all questions of the given type in the input db. *) (forall (q:Question) (q in ql) iff (q in qdb) and (q.type = tp)) and (* * The output list is sorted in alphabetical order by keyword. *) (forall (i:integer | (i >= 1) and (i < #ql)) ql[i].keywords < ql[i + 1].keywords); end SearchQuestionDatabase; operation SearchQuestionDatabase is inputs: qdb:QuestionDB, tm:Time; outputs: ql:Question*; description: (* Find a question or questions by time. If more than one is found, output list is sorted by keyword. *); precondition: (* None *); postcondition: (* * The output list consists of all questions of the given time in the input db. *) (forall (q:Question) (q in ql) iff (q in qdb) and (q.time = tm)) and (* * The output list is sorted in alphabetical order by keyword. *) (forall (i:integer | (i >= 1) and (i < #ql)) ql[i].keywords < ql[i + 1].keywords); end SearchQuestionDatabase; operation SearchQuestionDatabase is inputs: qdb:QuestionDB, d:Difficulty; outputs: ql:Question*; description: (* Find a question or questions by difficulty. If more than one is found, output list is sorted by keyword. *); precondition: (* None *); postcondition: (* * The output list consists of all questions of the given difficulty in the input db. *) (forall (q:Question) (q in ql) iff (q in qdb) and (q.difficulty = d)) and (* * The output list is sorted in alphabetical order by keyword. *) (forall (i:integer | (i >= 1) and (i < #ql)) ql[i].keywords < ql[i + 1].keywords); end SearchQuestionDatabase; operation SearchQuestionDatabase is inputs: qdb:QuestionDB, l:LastUsed; outputs: ql:Question*; description: (* Find a question or questions by LastUse. If more than one is found, output list is sorted by keyword. *); precondition: (* None *); postcondition: (* * The output list consists of all questions of the given Last Use in the input db. *) (forall (q:Question) (q in ql) iff (q in qdb) and (q.lastused = l)) and (* * The output list is sorted in alphabetical order by keyword. *) (forall (i:integer | (i >= 1) and (i < #ql)) ql[i].keywords < ql[i + 1].keywords); end SearchQuestionDatabase; operation SearchQuestionDatabase is inputs: qdb:QuestionDB, k:Keywords; outputs: ql:Question*; description: (* Find a question or questions by keyword. If more than one is found, output list is sorted by keyword. *); precondition: (* None *); postcondition: (* * The output list consists of all questions of the given keyword in the input db. *) (forall (q:Question) (q in ql) iff (q in qdb) and (q.keywords = k)) and (* * The output list is sorted in alphabetical order by keyword. *) (forall (i:integer | (i >= 1) and (i < #ql)) ql[i].keywords < ql[i + 1].keywords); end SearchQuestionDatabase; operation SearchQuestionDatabase is inputs: qdb:QuestionDB, a:Author; outputs: ql:Question*; description: (* Find a question or questions by author. If more than one is found, output list is sorted by keyword. *); precondition: (* None *); postcondition: (* * The output list consists of all questions of the given author in the input db. *) (forall (q:Question) (q in ql) iff (q in qdb) and (q.author = a)) and (* * The output list is sorted in alphabetical order by keyword. *) (forall (i:integer | (i >= 1) and (i < #ql)) ql[i].keywords < ql[i + 1].keywords); end SearchQuestionDatabase; operation SortQuestionDatabase is inputs: qdb:QuestionDB; outputs: ql:Question*; description: (* Sorts the column labeled class in alphabetical order. *); precondition: (* None *); postcondition: (* * The output list is sorted in alphabetical order by class. *) (forall (i:integer | (i >= 1) and (i < #ql)) ql[i].class < ql[i + 1].class); end SortQuestionDatabase; operation SortQuestionDatabase is inputs: qdb:QuestionDB; outputs: ql:Question*; description: (* Sorts the column labeled type in alphabetical order. *); precondition: (* None *); postcondition: (* * The output list is sorted in alphabetical order by type. *) (forall (i:integer | (i >= 1) and (i < #ql)) ql[i].type < ql[i + 1].type); end SortQuestionDatabase; operation SortQuestionDatabase is inputs: qdb:QuestionDB; outputs: ql:Question*; description: (* Sort the column labeled time in descending numerical order. *); precondition: (* None *); postcondition: (* * The output list is sorted in numerical order by time. *) (forall (i:integer | (i >= 1) and (i < #ql)) ql[i].time < ql[i + 1].time); end SortQuestionDatabase; operation SortQuestionDatabase is inputs: qdb:QuestionDB; outputs: ql:Question*; description: (* Sort the column labeled difficulty in descending numerical order. *); precondition: (* None *); postcondition: (* * The output list is sorted in numerical order by difficulty. *) (forall (i:integer | (i >= 1) and (i < #ql)) ql[i].difficulty < ql[i + 1].difficulty); end SortQuestionDatabase; operation SortQuestionDatabase is inputs: qdb:QuestionDB; outputs: ql:Question*; description: (* Sort the column labeled Last Use by date with the most recent at the top. *); precondition: (* None *); postcondition: (* * The output list is sorted in alphabetical order by last use. *) (forall (i:integer | (i >= 1) and (i < #ql)) ql[i].lastused < ql[i + 1].lastused); end SortQuestionDatabase; operation SortQuestionDatabase is inputs: qdb:QuestionDB; outputs: ql:Question*; description: (* Sort the column labeled keyword in alphabetical order. *); precondition: (* None *); postcondition: (* * The output list is sorted in alphabetical order by keyword. *) (forall (i:integer | (i >= 1) and (i < #ql)) ql[i].keywords < ql[i + 1].keywords); end SortQuestionDatabase; operation SortQuestionDatabase is inputs: qdb:QuestionDB; outputs: ql:Question*; description: (* Sort the column labeled author in alphabetical order. *); precondition: (* None *); postcondition: (* * The output list is sorted in alphabetical order by keyword. *) (forall (i:integer | (i >= 1) and (i < #ql)) ql[i].author < ql[i + 1].author); end SortQuestionDatabase; end QuestionDatabase;