Структуры.Определить количество женщин, имеющих наибольший рост - C#
Формулировка задачи:
Листинг программы
- class Program
- {
- static void Main(string[] args)
- {
- int number;
- CountMaxHeight[] group =
- { new CountMaxHeight("Mary", 140, true),
- new CountMaxHeight ("Jane", 180, true),
- new CountMaxHeight("Kim", 160, true),
- new CountMaxHeight("Bob", 197, false),
- new CountMaxHeight("Jan", 173, true),
- new CountMaxHeight("Pit", 180, false),
- new CountMaxHeight("Tom", 190, false),
- new CountMaxHeight ("Sara", 170, true)};
- if (CountMaxHeight.GetCount(group,x, out number))
- Console.WriteLine("У {0} женщин рост наибольший(выше 170-ти см)",number);
- }
- }
- struct CountMaxHeight
- {
- public string name;
- public bool male;
- public int height;
- public CountMaxHeight(string name, int height, bool male) { this.name = name; this.height = height; this.male = male; }
- public static bool GetCount(CountMaxHeight[] G, int x, out int number)
- {
- number = 0;
- foreach (CountMaxHeight m in G)
- if (m.height >= 170 & m.male != false)
- {
- number++;
- return true;
- }
- return false;
- }
- }
Листинг программы
- if (CountMaxHeight.GetCount(group,x, out number))
Решение задачи: «Структуры.Определить количество женщин, имеющих наибольший рост»
textual
Листинг программы
- using System;
- class Program
- {
- static void Main(string[] args)
- {
- int number;
- CountMaxHeight[] group =
- { new CountMaxHeight("Mary", 140, true),
- new CountMaxHeight ("Jane", 180, true),
- new CountMaxHeight("Kim", 160, true),
- new CountMaxHeight("Bob", 197, false),
- new CountMaxHeight("Jan", 173, true),
- new CountMaxHeight("Pit", 180, false),
- new CountMaxHeight("Tom", 190, false),
- new CountMaxHeight ("Sara", 170, true)};
- if (CountMaxHeight.GetCount(group, 170, out number))
- Console.WriteLine("У {0} женщин рост наибольший(выше 170-ти см)", number);
- }
- }
- struct CountMaxHeight
- {
- public string name;
- public bool male;
- public int height;
- public CountMaxHeight(string name, int height, bool male) { this.name = name; this.height = height; this.male = male; }
- public static bool GetCount(CountMaxHeight[] G, int x, out int number)
- {
- number = 0;
- foreach (CountMaxHeight m in G)
- if (m.height >= x & m.male)
- {
- number++;
- }
- return number>0;
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д