Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace OOP_130922 {
- //Кротов Сергей КБ-21СО Лабораторная №1 Вариант 9. Печатное издание
- enum ChallengeType {
- Exam,
- Test
- }
- class Challenge {
- ChallengeType _type; //тип испытания(экзамен, зачёт)
- int _day; //день проведения
- int _month; //месяц
- string _handler; //проводящий экзамен
- List<string> _members; //участники экзамена
- List<int> _marks; //участники экзамена
- //Challenge primer = new ...
- //primer.Day = 5; //работает set
- //Console.WriteLine(primer.Day); //работает get
- //
- public int Day { //день испытания
- get {
- return _day;
- }
- set {
- if (value > 31 || value < 1) {
- Console.WriteLine("Введён неверный день. Пересоздайте объект");
- } else
- _day = value;
- }
- }
- public int Month { //месяц испытания
- get {
- return _month;
- }
- set {
- if (value > 12 || value < 1) {
- Console.WriteLine("Введён неверный месяц. Пересоздайте объект");
- } else
- _month = value;
- }
- }
- public string Handler { //Проводящий испытание
- get {
- return _handler;
- }
- set {
- if (string.IsNullOrEmpty(value)) {
- Console.WriteLine("Не введён проводящий испытание. Пересоздайте объект");
- } else
- _handler = value;
- }
- }
- //"List<string>"
- public List<string> Members { //Проводящий испытание
- get {
- return _members;
- }
- set {
- bool fl = false;
- for (int i = 0; i < value.Count; i++) {
- if (string.IsNullOrEmpty(value[i])) {
- fl = true;
- break;
- }
- }
- if (fl) {
- Console.WriteLine("Некорректный список участников испытания. Пересоздайте объект");
- } else
- _members = value;
- }
- }
- public List<int> Marks { //Проводящий испытание
- get {
- return _marks;
- }
- set {
- bool fl = false;
- for (int i = 0; i < value.Count; i++) {
- if (value[i] < 2 || value[i] > 5) {
- fl = true;
- break;
- }
- }
- if (fl) {
- Console.WriteLine("Некорректный список результатов участников испытания. Пересоздайте объект");
- } else
- _marks = value;
- }
- }
- public Challenge(ChallengeType type, int day, int month, string handler = "ЯрГУ", List<string> members = null, List<int> marks = null) {
- if (members == null)
- members = new List<string>();
- if (marks == null)
- marks = new List<int>();
- this._type = type; //тип испытания(экзамен, зачёт)
- this.Day = day; //день проведения
- this.Month = month; //месяц
- this.Handler = handler; //проводящий экзамен
- this.Members = members; //участники экзамена
- this.Marks = marks; //оценки участников
- }
- public Challenge() : this(ChallengeType.Exam, 1, 1) { }
- public void addMemberWithMark(string name, int mark) {
- if (string.IsNullOrEmpty(name)) {
- Console.WriteLine("Пустое имя");
- return;
- }
- if (mark < 2 || mark > 5) {
- Console.WriteLine("Некорректная оценка");
- return;
- }
- _members.Add(name);
- _marks.Add(mark);
- }
- public void printMembers() {
- //String.Join("\n", _members);
- Console.WriteLine("Список участников испытания: ");
- foreach (string name in _members)
- Console.WriteLine(name);
- }
- public override string ToString() {
- return string.Format("{0}: ({1}.{2})", _type, Day, Month);
- }
- //Challenge ch1, ch2;
- //if(ch1 > ch2)
- public static bool operator >(Challenge t1, Challenge t2) {
- return t1.Day > t2.Day;
- }
- public static bool operator <(Challenge t1, Challenge t2) {
- return t1.Day < t2.Day;
- }
- public static bool operator <=(Challenge t1, Challenge t2) {
- return t1.Day <= t2.Day;
- }
- public static bool operator >=(Challenge t1, Challenge t2) {
- return t1.Day >= t2.Day;
- }
- }
- class Program {
- static void Main(string[] args) {
- List<string> names = new List<string>() { "Misha", "Gosha", "Masha" };
- List<int> marks = new List<int>() { 5, 3, 4 };
- var misha = new Challenge(ChallengeType.Test, 20, 9, "Артём", names, marks);
- var vasya = new Challenge();
- //вместо var компилятор подставит Student
- /*misha._fio = "Бабкевич Михаил";
- misha._groupName = "KB-21";
- misha._status = "academ";
- misha._number = 123456;*/
- Console.WriteLine(misha);
- Console.WriteLine(vasya);
- Console.WriteLine(misha.GetType());
- Console.WriteLine(misha.GetHashCode());
- Console.WriteLine(vasya.GetHashCode());
- Console.WriteLine(misha.Equals(vasya));
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement