(**** * * This file defines operations related to Student Functionality. * *) module StudentFunctionality; from Tests import all; from Database import Database; export all; object Student is components: fname:FirstName, lname:LastName, uid:UserID, passwd:Password; description: (* A Student object is made up of a user id and matching password. This allows the student to login and also allows the proctor to set which students are going to take the test. *); end Student; object FirstName is string; object LastName is string; object UserID is string; object Password is string; object AgreeToContinue is boolean; object Server is components: users:Student* and ptest:ProctorTest and tests:TakenTest*; description: (* A server is a list of students, a ProctorTest to hand out to each of the students, and a list of all the tests being taken by students. *); end Server; operation Login inputs: s:Server, uid:UserID, passwd:Password, test:Test; outputs: test':TakenTest; precondition: (* * Make sure the student's user id and password are valid. *) exists (u:Student | u in s.users) (u.uid = uid) and (u.passwd = passwd); postcondition: (* * TakenTest flag must be set to InProgress. *) (test'.flag); description: (* This is the functionality for taking a test from home. The user id and password involved are from the student's unix account. Student logs in to the TestTool program using his or her UserID and Password then chooses which test to take from a local drive. That test comes back as a TakenTest with the InProgress flag set to true. This is the test that the student will submit at the end if required. *); end Login; operation AnswerQuestion inputs: test:TakenTest, ans:GivenAnswer, questionNumber:integer; outputs: test':TakenTest; precondition: (* * GivenAnswer is not nil. *) (ans != nil); postcondition: (* * TakenTest output must contain the new answer. *) (test'.answers[questionNumber] = ans); description: (* Answer a specific question on a test. Takes in the current test being worked on, the ans to the question, and the question number. This function is called when the student switches to another question. When the focus has been switched, the previous question being worked on is added as an answer to the test. *); end AnswerQuestion; operation SubmitTest inputs: test:TakenTest, stu:Student, continue:AgreeToContinue; outputs: test':TakenTest; precondition: (* * User must agree to continue if some answers are blank. Check to see if the length * of the list of given answers is equal to the length of questions on the test, and * if the student has agreed to continue even if the test is incomplete. *) ( (#(test.questions) != #(test.answers)) and (continue) ) and (* * The Student must also be defined. *) (stu != nil) and (* * The InProgress flag must now be false. *) (not (test.flag)); postcondition: (* * The student name must now be added to the TakenTest. *) (test'.name = stu); description: (* When a student submits a test, their name is added to the test and the InProgress flag is turned off. The test is now ready for the proctor. *); end SubmitTest; end StudentFunctionality;