示例#1
0
 private void AddUpdateDialog_Load(object sender, System.EventArgs e)
 {
     this.student                = (Student) this.Tag;
       this.idDisplay.Text         = this.student.ID.ToString("d4");
       this.nameETextBox.Text      = this.student.Name;
       this.birthDateETextBox.Text = this.student.BirthDate.ToString("MM/dd/yyyy");
       this.majorETextBox.Text     = this.student.Major;
       this.hoursETextBox.Text     = this.student.Hours.ToString("f");
       this.gpaETextBox.Text       = this.student.GPA.ToString("f");
 }
示例#2
0
        static void Main()
        {
            int         index;
              Student     student;
              StudentList studentList1 = new StudentList();
              StudentList studentList2;

              ConsoleApp.ClrScr();                                    IdentifyApplication();
              OpenFiles();
              studentList1.Fill(fileIn);                              studentList1.AppendReport(fileOut, "List One - ID Order");
              studentList1.SelectionSort(Student.CompareNames);       studentList1.AppendReport(fileOut, "List One - Name Order");
              studentList1.SelectionSort(Student.CompareBirthDates);  studentList1.AppendReport(fileOut, "List One - Birth Date Order");
              studentList1.SelectionSort(Student.CompareMajors);      studentList1.AppendReport(fileOut, "List One - Major Order");
              studentList1.SelectionSort(Student.CompareHours);       studentList1.AppendReport(fileOut, "List One - Hours Order");
              studentList1.SelectionSort(Student.CompareGPAs);        studentList1.AppendReport(fileOut, "List One - GPA Order");
              studentList1.SelectionSort(Student.CompareNames);
              student = new Student(studentList1.AssignID(), "Rogers, Marshall", "January 31, 1994", "CI05", 115.5, 3.68);
              index   = ~studentList1.BinarySearch(student, Student.CompareNames);
              studentList1.InsertAt(index, student);          studentList1.AppendReport(fileOut, "List One - Name Order");
              studentList2 = studentList1.Clone();            studentList1.Clear();
              studentList2.RemoveAt(index);
              studentList1.AppendReport(fileOut, "List1 - Cleared");  studentList2.AppendReport(fileOut, "List Two - Name Order");
              CloseFiles();
        }
示例#3
0
        // Locate and return the list index
        public int LinearSearch(Student student, CompareDelegate compareMethod)
        {
            // of data in the list.  Does not require the
              int listIndex = 1;                                                     // the list to be ordered.
                                                                             // Uses a CompareDelegate method.

              while ((listIndex<=this.count) && (compareMethod(this[listIndex],student)!=0))
            listIndex++;
              if (listIndex>this.count)
            listIndex = ~listIndex;
              return listIndex;
        }
示例#4
0
        // Locate and return the list index
        public int LinearSearch(Student student)
        {
            // of data in the list.  Does not require the
              int listIndex = 1;                      // the list to be ordered.
                                              // Uses the Student class CompareTo method.

              //while ((listIndex<=this.count) && (this[listIndex].ID!=student.ID))
              while ((listIndex<=this.count) && (this[listIndex].CompareTo(student)!=0))  // Searching loop
            listIndex++;
              if (listIndex>this.count)
            listIndex = ~listIndex;
              return listIndex;
        }
示例#5
0
        public void InsertAt(int position, Student student)
        {
            int i;

              if ((position>=1) && (position<=this.count+1))
              {
            if (this.count==this.capacity)
              this.IncreaseCapacity();
            this.count++;
            for (i=this.count; i>position; i--)
              this[i] = this[i-1];
            this[position] = student;
              }
              else
            ProcessError(String.Format("StudentList InsertAt index must be between 1 and {0}\n",this.count+1));
        }
示例#6
0
        // Locate and return the listIndex
        public int BinarySearch(Student student, OrderEnum listOrder)
        {
            // position of element in the list.
              int listIndex = 1;                                           // Assumes the list is ordered in listOrder.

              switch (listOrder)
              {
            case OrderEnum.IDOrder        : listIndex = this.BinarySearch(student);                            break;
            case OrderEnum.NameOrder      : listIndex = this.BinarySearch(student, Student.CompareNames);      break;
            case OrderEnum.BirthDateOrder : listIndex = this.BinarySearch(student, Student.CompareBirthDates); break;
            case OrderEnum.MajorOrder     : listIndex = this.BinarySearch(student, Student.CompareMajors);     break;
            case OrderEnum.HoursOrder     : listIndex = this.BinarySearch(student, Student.CompareHours);      break;
            case OrderEnum.GPAOrder       : listIndex = this.BinarySearch(student, Student.CompareGPAs);       break;
              }
              return listIndex;
        }
示例#7
0
        // Locate and return the list index
        public int BinarySearch(Student student, CompareDelegate compareMethod)
        {
            // of data in the list.  The list must
              int listIndex, lowIndex = 1, highIndex = this.count;                  // be ordered by ascending CompareDelegate category.
                                                                            // Uses a CompareDelegate method.

              listIndex = (lowIndex+highIndex)/2;
              while ((lowIndex<=highIndex) && (compareMethod(this[listIndex],student)!=0))
              {
            if (compareMethod(this[listIndex],student)>0)
              highIndex = listIndex - 1;
            else
              lowIndex = listIndex + 1;
            listIndex = (lowIndex+highIndex)/2;
              }
              if (listIndex==0)
            listIndex = 1;
              else if ((lowIndex>highIndex) && (compareMethod(this[listIndex],student)<0))  // Make listIndex point to element that should follow
            listIndex++;                                                                // student, if student is to be inserted
              if (lowIndex>highIndex)
            listIndex = ~listIndex;
              return listIndex;
        }
示例#8
0
        // Locate and return the list index
        public int BinarySearch(Student student)
        {
            // of data in the list.  The list must
              int listIndex, lowIndex=1, highIndex=this.count;  // be ordered by ascending student ID
                                                        // Uses the Student class CompareTo method.

              listIndex = (lowIndex+highIndex)/2;
              while ((lowIndex<=highIndex) && (this[listIndex].CompareTo(student)!=0))
              {
            if (this[listIndex].CompareTo(student)>0)
              highIndex = listIndex - 1;
            else
              lowIndex = listIndex + 1;
            listIndex = (lowIndex+highIndex)/2;
              }
              if (listIndex==0)
            listIndex = 1;
              else if ((lowIndex>highIndex) && (this[listIndex].CompareTo(student)<0))  // Make listIndex point to element that should follow
            listIndex++;                                                            // student, if student is to be inserted
              if (lowIndex>highIndex)
            listIndex = ~listIndex;  // Make list index negative
              return listIndex;
        }
示例#9
0
        private void findTextBox_DoubleClick(object sender, System.EventArgs e)
        {
            bool   valueOk=true;  int     listIndex=1, id;  Date    birthDate;
              double hours, gpa;    string  name, major;      Student student = new Student();

              if (this.listOrder==StudentList.OrderEnum.IDOrder &&
              this.findETextBox.ReadInt(out id, TBounds.Both, 1, 9999))
            student.ID = id;
              else if (this.listOrder==StudentList.OrderEnum.NameOrder &&
               this.findETextBox.ReadString(out name))
            student.Name = name.Trim();
              else if (this.listOrder==StudentList.OrderEnum.BirthDateOrder &&
               this.findETextBox.ReadDate(out birthDate))
            student.BirthDate = birthDate;
              else if (this.listOrder==StudentList.OrderEnum.MajorOrder &&
               this.findETextBox.ReadString(out major, validMajors))
            student.Major = major;
              else if (this.listOrder==StudentList.OrderEnum.HoursOrder &&
               this.findETextBox.ReadDouble(out hours, TBounds.Both, 0.0, 250.0))
            student.Hours = hours;
              else if (this.listOrder==StudentList.OrderEnum.GPAOrder &&
               this.findETextBox.ReadDouble(out gpa, TBounds.Both, 0.0, 4.0))
            student.GPA = gpa;
              else
            valueOk = false;
              if (valueOk)
              {
            listIndex = this.studentList.BinarySearch(student, listOrder);
            if (listIndex<0)
              listIndex = ~listIndex;
            this.ProcessSelectedRowChanged(listIndex);
              }
        }
示例#10
0
 public void Copy(Student sourceStudent)
 {
     this.id   = sourceStudent.id;    this.major = sourceStudent.major;
       this.name = sourceStudent.name;  this.hours = sourceStudent.hours;
       this.gpa  = sourceStudent.gpa;   this.birthDate.Copy(sourceStudent.birthDate);
 }
示例#11
0
 public int CompareTo(Student student)
 {
     //return this.id - student.id;
       return this.id.CompareTo(student.id);
 }
示例#12
0
        public static Student Parse(string stringValue)
        {
            string[] words;
              Student  student = new Student();

              words             = StringMethods.ParseCsvString(stringValue.Trim());
              student.ID        = Int32.Parse(words[0]);
              student.Name      = words[1];
              student.BirthDate = Date.Parse(words[2]);
              student.Major     = words[3];
              student.Hours     = Double.Parse(words[4]);
              student.GPA       = Double.Parse(words[5]);
              return student;
        }
示例#13
0
        public static int CompareNames(Student student1, Student student2)
        {
            string string1, string2;

              string1 = student1.name + student1.id.ToString("d4");
              string2 = student2.name + student2.id.ToString("d4");
              return string1.CompareTo(string2);
        }
示例#14
0
 public static int CompareIDs(Student student1, Student student2)
 {
     //return student1.id - student2.id;
       return student1.id.CompareTo(student2.id);
 }
示例#15
0
        public static int CompareBirthDates(Student student1, Student student2)
        {
            string string1, string2;

              string1 = student1.birthDate.ToString("yyyy/MM/dd") + student1.name + student1.id.ToString("d4");
              string2 = student2.birthDate.ToString("yyyy/MM/dd") + student2.name + student2.id.ToString("d4");
              return string1.CompareTo(string2);
        }
示例#16
0
 // Copy constructor
 public Student(Student sourceStudent)
 {
     this.birthDate = new Date();
       this.Copy(sourceStudent);
 }
示例#17
0
 public void Add(Student student)
 {
     this.InsertAt(this.count+1, student);
 }
示例#18
0
        private void addMenuItem_Click(object sender, System.EventArgs e)
        {
            int             listIndex = 0;
              Student         student;
              AddUpdateDialog addDialog = new AddUpdateDialog();

              student        = new Student();
              student.ID     = studentList.AssignID();
              addDialog.Text = "Add Student";
              addDialog.Tag  = student;
              if (addDialog.ShowDialog(this)==DialogResult.OK)
              {
            listIndex = ~this.studentList.BinarySearch(student, listOrder);
            this.studentList.InsertAt(listIndex, student);
            this.RefreshClientAreaControls(listIndex);
              }
              addDialog.Dispose();
        }