Описать структуру с именем NOTE - C# (181086)

Узнай цену своей работы

Формулировка задачи:

- фамилия, имя; - номер телефона; дата рождения (массив из трёх чисел). Написать программу, выполняющие следующие действия: -ввод с клавиатуры данных в массив, состоящий из восьми элементов типа NOTE; записи должны быть размещены по алфавиту

Решение задачи: «Описать структуру с именем NOTE»

textual
Листинг программы
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. class Program
  6. {
  7.     [Serializable]
  8.     public struct Note : IFormattable, IEquatable<Note>, IComparable<Note>
  9.  
  10.     {
  11.         public string FullName { get; set; }
  12.         public int[] Birthday { get; set; }
  13.         public string Phone { get; set; }
  14.  
  15.  
  16.         public Note(string fullName) :
  17.             this(fullName, new int[] {0,0,0}, "")
  18.         { }
  19.  
  20.         public Note(string fullName, int[] birthday) :
  21.          this(fullName, birthday, "")
  22.         { }
  23.  
  24.         public Note(string fullName, int[] birthday,
  25.             string phone)
  26.         {
  27.             FullName = fullName;
  28.             Birthday = birthday;
  29.             Phone = phone;
  30.         }
  31.  
  32.  
  33.         public override string ToString()
  34.         {
  35.             return FullName;
  36.         }
  37.  
  38.         public string ToString(string format, IFormatProvider formatProvider)
  39.         {
  40.             if (format == null)
  41.                 return ToString();
  42.  
  43.             switch (format.ToUpper())
  44.             {
  45.                 case "FN":
  46.                     return FullName;
  47.                 case "B":
  48.                     return String.Format("{1,2:D2}:{2,2:D2}:{3,4:D4}", Birthday); ;
  49.                 case "P":
  50.                     return Phone.ToString();
  51.  
  52.                 case "ALL":
  53.                     return String.Format(" Full name: {0}, Birthday: {1,2:D2}:{2,2:D2}:{3,4:D4},  Phone: {4}"
  54.                     , FullName, Birthday[0], Birthday[1], Birthday[2], Phone);
  55.  
  56.                 default:
  57.                     throw new FormatException(String.Format(formatProvider,
  58.                     "Format {0} is not supported", format));
  59.             }
  60.         }
  61.         public string ToString(string format)
  62.         {
  63.             return ToString(format, null);
  64.         }
  65.  
  66.         public override int GetHashCode()
  67.         {
  68.             return (FullName.GetHashCode() + Phone.GetHashCode());
  69.         }
  70.  
  71.         public bool Equals(Note other)
  72.         {
  73.             if (other == null)
  74.                 return false;
  75.  
  76.  
  77.             if (string.Compare(this.FullName, other.FullName, StringComparison.OrdinalIgnoreCase) == 0
  78.                 &&
  79.                 Enumerable.SequenceEqual(this.Birthday, other.Birthday) == true
  80.                 &&
  81.                 string.Compare(this.Phone, other.Phone, StringComparison.OrdinalIgnoreCase) == 0)
  82.  
  83.                 return true;
  84.             else
  85.                 return false;
  86.         }
  87.        
  88.         public override bool Equals(object other)
  89.         {
  90.             if (other == null)
  91.                 return false;
  92.             return this.Equals((Note)other);
  93.         }
  94.  
  95.         public int CompareTo(Note other)
  96.         {
  97.                 if (other == this)
  98.                     return 0;
  99.                     return string.Compare(this.FullName,other.FullName, StringComparison.OrdinalIgnoreCase);
  100.  
  101.         }
  102.  
  103.  
  104.  
  105.         public static bool operator ==(Note left, Note right)
  106.         {
  107.             return left.Equals(right);
  108.         }
  109.         public static bool operator !=(Note left, Note right)
  110.         {
  111.             return left != right;
  112.         }
  113.     }
  114.  
  115.  
  116.  
  117.  
  118.     public static void Main()
  119.     {
  120.  
  121.         var notes = new List<Note>();
  122.  
  123.         //notes.Add(new Note("Jones I.O.", new int[] { 1990, 2, 15 },"009-888-999-44"));
  124.         //notes.Add(new Note("Kimberly A.A.", new int[] {1991, 6, 4 }, "009-887-988-00"));
  125.         //notes.Add(new Note("Miller C.H.", new int[] {1990, 11, 1 }, "009-888-999-44"));
  126.         //notes.Add(new Note("Morgan B.V.", new int[] {1991, 4, 3 }, "009-088-000-55"));
  127.         //notes.Add(new Note("PhilLips P.V.", new int[] {1991, 4, 3 }, "009-888-444-77"));
  128.         //notes.Add(new Note("Lynn J.O.", new int[] {1991, 4, 3 }, "009-555-111-44"));
  129.  
  130.  
  131.         for (int i = 0; i < 8; i++)
  132.         {
  133.             Note note = new Note();
  134.             Console.WriteLine("Full name: ");          
  135.             note.FullName = Console.ReadLine();
  136.             Console.WriteLine("Birthday: (array) ");
  137.             var arr = new int[] { 0, 0, 0 };
  138.             for (int j = 0; j < arr.Length; j++)
  139.                arr[j] = Convert.ToInt32( Console.ReadLine());
  140.             note.Birthday = arr;
  141.             Console.WriteLine("Phone: ");
  142.             note.Phone = Console.ReadLine();
  143.             notes.Add(note);
  144.             Console.WriteLine();
  145.         }
  146.  
  147.         foreach (Note item in notes)
  148.             Console.WriteLine("{0:All}", item);
  149.  
  150.         notes.Sort();
  151.  
  152.         Console.WriteLine();
  153.  
  154.  
  155.         foreach (Note item in notes)
  156.            
  157.                 Console.WriteLine("{0:All}", item);
  158.         Console.ReadKey(true);
  159.  
  160.     }
  161.  
  162. }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

8   голосов , оценка 4.125 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут