Структуры: результаты соревнований по фигурному катанию - C#

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

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

Доброго времени суток. Помогите, пожалуйста, с прогой на тему "Структуры". Условие: Дан файл, содержащий сведения о результатах соревнований по фигурному катанию. Каждая запись содержит фамилию спортсмена и оценки восьми судей. Определить распределение спортсменов по местам. Дошел пока только вот до этого момента. Он у меня находит среднее значение оценок к. Но вот дальше как их сортировать - не знаю. Может кто подтолкнет? Буду очень благодарен!
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. namespace Структуры
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public struct abiturient
  15. {
  16. public string fam;
  17. public int sud1;
  18. public int sud2;
  19. public int sud3;
  20. public int sud4;
  21. public int sud5;
  22. public int sud6;
  23. public int sud7;
  24. public int sud8;
  25. }
  26. abiturient[] abit = new abiturient[100];
  27. int n = 0; //строк в файле
  28. public Form1()
  29. {
  30. InitializeComponent();
  31. StreamReader data = new StreamReader("abit.txt", Encoding.Default);
  32. dataGridView1.ColumnCount = 9;
  33. dataGridView1.RowCount = 1;
  34. dataGridView2.ColumnCount = 1;
  35. dataGridView2.RowCount = 1;
  36. dataGridView1.Rows.Add("Фамилия", "Судья 1", "Судья 2", "Судья 3", "Судья 4", "Судья 5", "Судья 6", "Судья 7", "Судья 8");
  37. dataGridView2.Rows.Add("Фамилия", "Судья 1", "Судья 2", "Судья 3", "Судья 4", "Судья 5", "Судья 6", "Судья 7", "Судья 8");
  38. for (n = 0; !data.EndOfStream; n++)
  39. {
  40. string[] temp = data.ReadLine().Split(' ');
  41. abit[n].fam = temp[0];
  42. abit[n].sud1 = Convert.ToInt32(temp[1]);
  43. abit[n].sud2 = Convert.ToInt32(temp[2]);
  44. abit[n].sud3 = Convert.ToInt32(temp[3]);
  45. abit[n].sud4 = Convert.ToInt32(temp[4]);
  46. abit[n].sud5 = Convert.ToInt32(temp[5]);
  47. abit[n].sud6 = Convert.ToInt32(temp[6]);
  48. abit[n].sud7 = Convert.ToInt32(temp[7]);
  49. abit[n].sud8 = Convert.ToInt32(temp[8]);
  50. dataGridView1.Rows.Add(abit[n].fam, abit[n].sud1.ToString(), abit[n].sud2.ToString(), abit[n].sud3.ToString(), abit[n].sud4.ToString(), abit[n].sud5.ToString(), abit[n].sud6.ToString(), abit[n].sud7.ToString(), abit[n].sud8.ToString()); //добавляем новую строку
  51. }
  52. data.Close();
  53. }
  54. private void button3_Click(object sender, EventArgs e)
  55. {
  56. Application.Exit();
  57. }
  58. private void button2_Click(object sender, EventArgs e)
  59. {
  60. for (int i = 0; i < n; i++)
  61. {
  62. int k;
  63. k = (abit[i].sud1 + abit[i].sud2 + abit[i].sud3 + abit[i].sud4 + abit[i].sud5 + abit[i].sud6 + abit[i].sud7 + abit[i].sud8)/8;
  64. if //как сортировать??
  65. {
  66. dataGridView2.Rows.Add(abit[i].fam);//, abit[i].sud1.ToString(), abit[i].sud2.ToString(), abit[i].sud3.ToString()); //добавляем новую строку
  67. }
  68. }
  69. button2.Enabled = false;
  70. }
  71. private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  72. {
  73. }
  74. }
  75. }

Решение задачи: «Структуры: результаты соревнований по фигурному катанию»

textual
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10.  
  11. namespace Структуры
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public struct sport
  16.         {
  17.             public string fam;
  18.             public int sud1;
  19.             public int sud2;
  20.             public int sud3;
  21.             public int sud4;
  22.             public int sud5;
  23.             public int sud6;
  24.             public int sud7;
  25.             public int sud8;
  26.             //эта переменная хранит среднюю оценку
  27.             public int ocenka;
  28.             //Эта переменная хранит место в общем зачете
  29.             public int mesto;
  30.         }
  31.         sport[] spor = new sport[100];
  32.         int n = 0; //строк в файле
  33.         public Form1()
  34.         {
  35.             InitializeComponent();
  36.             StreamReader data = new StreamReader("abit.txt", Encoding.Default);
  37.             dataGridView1.ColumnCount = 9;
  38.             dataGridView1.RowCount = 1;
  39.             dataGridView2.ColumnCount = 2;
  40.             dataGridView2.RowCount = 1;
  41.             dataGridView1.Rows.Add("Фамилия", "Судья 1", "Судья 2", "Судья 3", "Судья 4", "Судья 5", "Судья 6", "Судья 7", "Судья 8");
  42.             dataGridView2.Rows.Add("Фамилия", "Баллы");
  43.             for (n = 0; !data.EndOfStream; n++)
  44.             {
  45.                 string[] temp = data.ReadLine().Split(' ');
  46.                 spor[n].fam = temp[0];
  47.                 spor[n].sud1 = Convert.ToInt32(temp[1]);
  48.                 spor[n].sud2 = Convert.ToInt32(temp[2]);
  49.                 spor[n].sud3 = Convert.ToInt32(temp[3]);
  50.                 spor[n].sud4 = Convert.ToInt32(temp[4]);
  51.                 spor[n].sud5 = Convert.ToInt32(temp[5]);
  52.                 spor[n].sud6 = Convert.ToInt32(temp[6]);
  53.                 spor[n].sud7 = Convert.ToInt32(temp[7]);
  54.                 spor[n].sud8 = Convert.ToInt32(temp[8]);
  55.                 dataGridView1.Rows.Add(spor[n].fam, spor[n].sud1.ToString(), spor[n].sud2.ToString(), spor[n].sud3.ToString(), spor[n].sud4.ToString(), spor[n].sud5.ToString(), spor[n].sud6.ToString(), spor[n].sud7.ToString(), spor[n].sud8.ToString()); //добавляем новую строку
  56.             }
  57.             data.Close();
  58.         }
  59.  
  60.      
  61.  
  62.         private void button2_Click(object sender, EventArgs e)
  63.         {
  64.              for (int i = 0; i < n; i++)
  65.             {
  66.                 spor[i].ocenka = (spor[i].sud1 + spor[i].sud2 + spor[i].sud3 + spor[i].sud4 + spor[i].sud5 + spor[i].sud6 + spor[i].sud7 + spor[i].sud8);
  67.                 dataGridView2.Rows.Add(spor[i].fam, spor[i].ocenka.ToString());
  68.             }
  69.             button2.Enabled = false;
  70.         }
  71.  
  72.         private void выходToolStripMenuItem_Click(object sender, EventArgs e)
  73.         {
  74.             Application.Exit();
  75.          }
  76.  
  77.         private void условиеИАвторToolStripMenuItem_Click(object sender, EventArgs e)
  78.         {
  79.             Form2 A = new Form2();
  80.             A.Show();
  81.             this.Hide();
  82.  
  83.         }
  84.  
  85.      
  86.     }
  87. }

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


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

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

6   голосов , оценка 3.833 из 5

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

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

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