(**** * * This file defines student objects. * * See Sections 2.4.1, of the Milestone 4 requirements. * *) module student; from class import Class; export all; object Student is components: studentinfo:StudentInfo, grades:Grade*; description: (* A student contains the StudentInfo object. *); end Student; object Grade is number; object StudentInfo is components: lastname:LastName and firstname:FirstName and classid:ClassID and sid:StudentID and ClassPassword and EnrollmentStatus and StudentUserName and StudentPassword and Major and ClassStanding and EmailAddress and homePhone:HomePhoneNumber and HomeAddress and otherPhone:OtherPhoneNumber and EmergencyContact and LocalAddress; description: (* StudentInfo contains administrative information about a student and additional personal information about a student *); end StudentInfo; object ClassStanding is string; object StudentUserName is string; object LastName is string; object FirstName is string; object ClassID is number; object StudentID is integer; object ClassPassword is string; object Major is string; object EnrollmentStatus is string; object StudentPassword is string; object EmailAddress is string; object HomePhoneNumber is PhoneNumber; object PhoneNumber is area:Area and number:Number description: (* A phone number consists of a three-digit area code and seven-digit number. *); end; object Area is integer description: (* The three-digit area code component of a user phone number. *); end Area; object Number is integer description: (* The seven-digit number component of a user phone number. *); end Number; object Address is components: Line1 and Line2; description:(* Address contains the address of a student *); end Address; object Line1 is string; object Line2 is string; object HomeAddress inherits from Address is description: (* HomeAddress inherits from Address. HomeAddress contains the home address of a student. *); end HomeAddress; object OtherPhoneNumber is PhoneNumber; object EmergencyContact is ContactName and ContactPhoneNumber; object ContactName is string; object ContactPhoneNumber is PhoneNumber; object LocalAddress inherits from Address is description: (* LocalAddress inherits from Address. LocalAddress contains the address of where a student currently live in. *); end LocalAddress; operation AddStudent is inputs: class:Class, student:Student; outputs: class':Class; description: (* Add the given Student to the given Class. The UserId of the given user record must not be the same as a student record already in the Class If the sid component exists, it must be nine characters. The phone number is optional; if given, the area code and number must be 3 and 7 digits respectively. *); precondition: (not (exists (student' in class.studs) student'.studentinfo.sid = student.studentinfo.sid)) and (if (student.studentinfo.sid != nil) then (#(student.studentinfo.sid) = 9)) and (if (student.studentinfo.homePhone.area != nil) then (#(student.studentinfo.homePhone.area) = 3)) and (if (student.studentinfo.homePhone.number != nil) then (#(student.studentinfo.homePhone.number) = 7)) and (student.studentinfo.firstname != nil) and (student.studentinfo.lastname != nil); postcondition: (* A user 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 (student':Student) (student' in class'.studs) iff ((student' = student) or (student' in class.studs)); end AddStudent; operation EditStudent is inputs: class:Class, student:Student; outputs: class':Class; description: (* Edit the given Student in the given Class. The UserId of the given user record must not be the same as a user record already in the Class if the sid exists, it must be nine characters long. The phone number is optional; if given, the area code and number must be 3 and 7 digits respectively. *); precondition: (* * The given Student is in the given Class. *) (exists (student' in class.studs) (student.studentinfo.sid = student'.studentinfo.sid)) and (not (exists (student' in class.studs) student'.studentinfo.sid = student.studentinfo.sid)) and (if (student.studentinfo.sid != nil) then (#(student.studentinfo.sid) = 9)) and (if (student.studentinfo.homePhone.area != nil) then (#(student.studentinfo.homePhone.area) = 3)) and (if (student.studentinfo.homePhone.number != nil) then (#(student.studentinfo.homePhone.number) = 7)) and (* * student last and first name are required. * ) (student.studentinfo.firstname != nil) and (student.studentinfo.lastname != nil); postcondition: (* forall student in the output class, the student id of the edited student is not the same as the student id of the students in the input class unless it is the student that was edited. *) exists (student':Student) (student' in class'.studs) and forall (i:integer | (i >= 0) and (i < (#class.studs))) (class.studs[i].studentinfo.sid != class'.studs[i].studentinfo.sid) iff (student != student'); end EditStudent; operation DeleteStudent is inputs: class:Class, student:Student; outputs: class':Class; description: (* Delete the given Student from the given UserDB. The given Student must already be in the input Class. *); precondition: (* * The given Student is in the given Class. *) student in class.studs; postcondition: (* * A student is in the output class if and only if it is not the * existing student to be deleted and it is in the input class. *) (forall (student':Student) (student' in class'.studs) iff ((student' != student) and (student' in class.studs))); end DeleteStudent; end student;