Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
lab2.docx
Скачиваний:
71
Добавлен:
16.03.2016
Размер:
167.4 Кб
Скачать

Int rating;

DateTime dateExam;

public Exam(string name, int rating, DateTime dateExam)

{

this.name = name;

this.rating = rating;

this.dateExam = dateExam;

}

public Exam()

{

name = "name";

rating = 5;

dateExam = new DateTime(1900, 1, 1);

}

public string Name

{

get { return name; }

set { name = value; }

}

public int Rating

{

get { return rating; }

set { rating = value; }

}

public DateTime Date

{

get { return dateExam; }

set { dateExam = value; }

}

public override string ToString()

{

return "Название экзамена: " +name + "\n оценка: " + rating.ToString() + "\n Дата экзамена: " + dateExam.ToShortDateString();

}

public object DeepCopy()

{

Exam exam = new Exam(this.name, this.rating, this.dateExam);

return exam;

}

public override bool Equals(Object obj)

{

Exam exam = (Exam)obj;

bool result=false;

if (name == exam.name)

if (rating == exam.rating)

if (dateExam == exam.dateExam)

result = true;

return result;

}

public static bool operator ==(Exam p1, Exam p2)

{

bool result = false;

if (p1.name == p2.name)

if (p1.rating == p2.rating)

if (p1.dateExam == p2.dateExam)

result = true;

return result;

}

public static bool operator !=(Exam p1, Exam p2)

{

bool result = true;

if (p1.name == p2.name)

if (p1.rating == p2.rating)

if (p1.dateExam == p2.dateExam)

result = false;

return result;

}

public override int GetHashCode()

{

return name.Length + rating + dateExam.Day + dateExam.Month + dateExam.Year;

}

}

class Student:Person,IDateAndCopy

{

private Education education;

private int numberGroup;

private ArrayList listTests;

private Exam[] exams;

public Student(Person person, Education education, int numberGroup)

{

Person = person;

this.education = education;

this.numberGroup = numberGroup;

exams=new Exam[0];

listTests = new ArrayList();

}

public Student()

{

Person = new Person();

education = Education.Bachelor;

numberGroup = 1;

exams = new Exam[0];

listTests = new ArrayList();

}

public Person Person

{

get { return (Person)this; }

set

{

Name = value.Name;

SecondName = value.SecondName;

Date = value.Date;

}

}

public ArrayList ListTests

{

get { return listTests; }

set { listTests = value; }

}

public Exam[] Exams

{

get { return exams; }

set { exams = value; }

}

public double AverageRating

{

get

{

int sum = 0;

for (int i = 0; i < exams.Length; i++)

{

sum += exams[i].Rating;

}

if (exams.Length != 0)

return sum / exams.Length;

else

return 0;

}

}

public int NumberGroup

{

get { return numberGroup; }

set

{

if (value <= 100 || value > 599)

throw new Exception("Номер группы должен быть меньше 599 и не равен 100");

}

}

public void AddExam(params Exam[] examAdd)

{

int Length = exams.Length;

Array.Resize<Exam>(ref exams, Length +examAdd.Length);

examAdd.CopyTo(exams, Length);

}

public void AddTest(params Test[] tests)

{

listTests.AddRange(tests);

}

public override string ToString()

{

string result=base.ToString()+ "\n Тип образования: "+education.ToString()+ "\n Номер группы"+ numberGroup.ToString()+"\n";

//if(exams.Length != 0)

foreach (Exam e in exams)

{

result += e.ToString() + "\n";

}

//if(listTests.Count !=0)

foreach (Test t in listTests)

{

result += t.ToString()+"\n";

}

return result;

}

new public string ToShortString()

{

string result = base.ToString() + "\n Тип образования: " + education.ToString() + "\n Номер группы: " + numberGroup.ToString() + "\n Средний балл: " + AverageRating.ToString();

return result;

}

public override bool Equals(object obj)

{

Student student = (Student)obj;

bool result = false;

if (base.Equals(student))

{

if (exams.Length == student.exams.Length && listTests.Count == student.listTests.Count)

{

for (int i = 0; i < exams.Length; i++)

{

if (exams[i] != student.exams[i])

return result;

}

for (int i = 0; i < listTests.Count; i++)

{

if (listTests[i] != student.listTests[i])

return result;

}

if (education == student.education)

if (numberGroup == student.numberGroup)

result = true;

}

}

return result;

}

public override int GetHashCode()

{

return ToString().Length;

}

new public object DeepCopy()

{

Student student = new Student((Person)this, education, numberGroup);

for (int i = 0; i < exams.Length; i++)

{

student.exams[i] = (Exam)exams[i].DeepCopy();

}

for (int i = 0; i < listTests.Count; i++)

{

student.listTests[i] = (Test)listTests[i];

}

return student;

}

}

enum Education

{

Specialist,Bachelor,SecondEducation

}

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]