예제 #1
0
        // LoadFromFile loads the entire school from file, given as a parameter
        // returns -1 if unable to find file, in which case School is reset
        public int LoadFromFile(String fileName)
        {
            School tempSchool;

            if (!File.Exists(fileName))
            {
                // if the file doesn't exist return error code -1
                return(-1);
            }

            // Open the file containing the data that you want to deserialize.
            FileStream fs = new FileStream(fileName, FileMode.Open);

            try
            {
                Console.WriteLine("Deserializing vector");
                BinaryFormatter formatter = new BinaryFormatter();
                tempSchool = (School)formatter.Deserialize(fs);
                fs.Close();
                theSubjects = tempSchool.theSubjects;
                theTeachers = tempSchool.theTeachers;
                theStudents = tempSchool.theStudents;

                return(0);
            }
            catch (Exception e)
            {
                // we go here in the case of an exception
                Console.WriteLine("Failed to deserialize. Reason: " + e.Message);
                throw;
            }
            finally
            {
                fs.Close();
            }
        }
예제 #2
0
 // setSubjects procedure allows a user to set a Student's Subjects
 public void setSubjects(Subjects theSubjects)
 {
     studies = theSubjects;
 }
예제 #3
0
 // constructor allowing maximum sizes to be set for subjects, teachers and students.
 public School(int maxSubjects, int maxTeachers, int maxStudents)
 {
     theSubjects = new Subjects(maxSubjects);
     theTeachers = new Teachers(maxTeachers);
     theStudents = new SchoolRecords.Students(maxStudents);
 }
예제 #4
0
 public Teacher(String firstName, String lastName, int anAge) : base(firstName, lastName, anAge)
 {
     // initialise to an empty collection of subjects
     // assume that no teacher can teach more than the number of subjects a student can ytake e.g. 6
     teaches = new Subjects(6);
 }