Как создать приложение с помощью структур? - C#
Формулировка задачи:
Всем привет! Как с помощью структур создать приложение? У меня есть файл, в котором хранится информация об учениках автошколы: ФИО, учебная группа, количество долгов. Нужно вывести группу, у которой больше всего долгов. Прошу помочь.
Решение задачи: «Как создать приложение с помощью структур?»
textual
Листинг программы
using System;
using System.IO;
using System.Text;
struct AutoPupils
{
public int group;
public int credit;
public string FIO;
public void Show()
{
Console.WriteLine("ФИО : " + FIO);
Console.WriteLine("Группа : " + group);
Console.WriteLine("Долг : " + credit);
}
public static AutoPupils[] GetInfo(string s)
{
StreamReader input = null;
try
{
input = new StreamReader(s, Encoding.UTF8);
AutoPupils[] AllInfo = new AutoPupils[1000];
int i;
string str;
string[] Pupilinfo = null;
for (i = 0; i < AllInfo.Length; i++)
{
str = input.ReadLine();
if (str != null) Pupilinfo = str.Split(' ');
else break;
if (Pupilinfo.Length == 5)
{
AllInfo[i] = new AutoPupils
(Pupilinfo[0] + " " + Pupilinfo[1] + " " + Pupilinfo[2], Int32.Parse(Pupilinfo[3]), Int32.Parse(Pupilinfo[4]));
}
}
AutoPupils[] n = new AutoPupils[i];
for (i = 0; i < n.Length; i++) n[i] = AllInfo[i];
bool flag = true;
while (flag)
{
flag = false;
for (i = 0; i < n.Length - 1; i++)
if (n[i].group > n[i + 1].group)
{
AutoPupils b = n[i];
n[i] = n[i + 1];
n[i + 1] = b;
flag = true;
}
}
return n;
}
catch (Exception exc)
{
Console.WriteLine(exc.Message);
return null;
}
finally
{
if (input != null) input.Close();
}
}
public AutoPupils(string f, int g, int c)
{
FIO = f;
group = g;
credit = c;
}
}
class structdemo
{
static void Main()
{
Console.WriteLine("путь к файлу с данными : ");
AutoPupils[] arr = AutoPupils.GetInfo(Console.ReadLine());
Console.WriteLine("Информация об учениках : \n");
foreach (AutoPupils pupil in arr)
{
pupil.Show();
Console.WriteLine();
}
int ng, maxquan = 0 ;
string mg = "";
ng = arr[0].group;
for (int i = 0, j = 0; i < arr.Length; i++)
{
if (arr[i].group == ng && arr[i].credit > 0) j++;
if(arr[i].group != ng ||i==arr.Length-1)
{
if (maxquan <j)
{
maxquan = j;
mg = Convert.ToString(ng);
}
else if (maxquan == j)
{
mg +=", " + Convert.ToString(ng);
}
j = 0;
if (arr[i].credit > 0) j++;
ng = arr[i].group;
}
}
Console.WriteLine("Больше всего должников в группе(-ах) {0}. Их кол-во = {1}",mg,maxquan);
}
}