Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.56 KB | None | 0 0
  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 _444
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void textBox1_TextChanged(object sender, EventArgs e)
  21.         {
  22.  
  23.         }
  24.         int stud_count, subj_count;
  25.         int[,] mark;
  26.         string[] stud = { "Путен", "KillREAL", "Зиленский", "Трамп", "Миркель", "Ким" };
  27.         string[] sudj = { "Православие", "УПД", "ОБЖ", "ИЗО" };
  28.         private void button1_Click(object sender, EventArgs e)
  29.         {
  30.             stud_count = (int)numericUpDown1.Value;
  31.             subj_count = (int)numericUpDown2.Value;
  32.             dataGridView1.RowCount = stud_count + 1;
  33.             dataGridView1.ColumnCount = subj_count + 1;
  34.  
  35.             mark = new int[stud_count, subj_count];
  36.             Random rnd = new Random();
  37.             for (int i = 0; i < stud_count; i++)
  38.             {
  39.                 for (int j = 0; j < subj_count; j++)
  40.                 {
  41.                     mark[i, j] = rnd.Next(2, 6);
  42.                 }
  43.                 for (int j = 0; j < subj_count; j++)
  44.                 {
  45.                     dataGridView1.Rows[0].Cells[j + 1].Value = sudj[j];
  46.                 }
  47.             }
  48.             for (int i = 0; i < stud_count; i++)
  49.             {
  50.                 dataGridView1.Rows[i + 1].Cells[0].Value = stud[i];
  51.                 for (int j = 0; j < subj_count; j++)
  52.                 {
  53.                     dataGridView1.Rows[i + 1].Cells[j + 1].Value = mark[i, j];
  54.                 }
  55.             }
  56.         }
  57.  
  58.         private void button2_Click(object sender, EventArgs e)
  59.         {
  60.             int a = 0, b = 0;
  61.             for (int i = 0; i < stud_count; i++)
  62.             {
  63.                 for (int j = 0; j < subj_count; j++)
  64.                 {
  65.                     if (mark[i, j] == 4)
  66.                         a++;
  67.                     else if (mark[i, j] == 3)
  68.                         b++;
  69.                 }
  70.             }
  71.             if (a == b)
  72.                 textBox1.Text = "Кол-во хороших и удовлетворительных оценок одинаково\r\n";
  73.             else if (a > b)
  74.                 textBox1.Text = "Кол-во хороших оценок преобладает\r\n";
  75.             else if (a < b)
  76.                 textBox1.Text = "Кол-во удовлетворительных оценок преобрадает\r\n";
  77.         }
  78.  
  79.         private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  80.         {
  81.             try
  82.             {
  83.                 mark[e.RowIndex - 1, e.ColumnIndex - 1] = int.Parse(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
  84.             }
  85.             catch
  86.             {
  87.                 MessageBox.Show("Плюха");
  88.                 dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = mark[e.RowIndex - 1, e.ColumnIndex - 1];
  89.             }
  90.         }
  91.  
  92.         private void Button3_Click(object sender, EventArgs e)
  93.         {
  94.             int c = 0;
  95.             for (int i = 0; i < stud_count; i++)
  96.             {
  97.                 bool f = true;
  98.                 for (int j = 0; j < subj_count; j++)
  99.                 {
  100.                     if (mark[i, j] <= 3)
  101.                     {
  102.                         f = false;
  103.                         break;
  104.                     }
  105.                 }
  106.                 if (f)
  107.                     c++;
  108.             }
  109.             textBox1.Text = c + " студентов сдало на стипендию\r\n";
  110.         }
  111.  
  112.         private void Button5_Click(object sender, EventArgs e)
  113.         {
  114.             textBox1.Clear();
  115.             int c = 0;
  116.             for (int i = 0; i < stud_count; i++)
  117.             {
  118.                 c = 0;
  119.                 textBox1.Text += "У " + stud[i] + " ";
  120.                 for (int j = 0; j < subj_count; j++)
  121.                 {
  122.                     if (mark[i, j] == 3)
  123.                         c++;
  124.                 }
  125.                 if (c > 0)
  126.                     textBox1.Text += c + " удовлетворительных оценок\r\n";
  127.                 else
  128.                     textBox1.Text += " нет удовлетворительных оценок\r\n";
  129.             }
  130.         }
  131.  
  132.         private void Button4_Click(object sender, EventArgs e)
  133.         {
  134.             textBox1.Clear();
  135.             for (int i = 0; i < subj_count; i++)
  136.             {
  137.                 int a = 0, b = 0, c = 0;
  138.                 for (int j = 0; j < stud_count; j++)
  139.                 {
  140.                     if (mark[j, i] == 5)
  141.                         a++;
  142.                     else if (mark[j, i] == 4)
  143.                         b++;
  144.                     else if (mark[j, i] == 3)
  145.                         c++;
  146.                 }
  147.                 if (a > b && a > c)
  148.                     textBox1.Text += "По " + sudj[i] + " больше отличных оценок\r\n";
  149.                 else if (b > a && b > c)
  150.                     textBox1.Text += "По " + sudj[i] + " больше хороших оценок\r\n";
  151.                 else if (c > a && c > b)
  152.                     textBox1.Text += "По " + sudj[i] + " больше удовлетворительных оценок\r\n";
  153.             }
  154.         }
  155.  
  156.         private void Form1_Load(object sender, EventArgs e)
  157.         {
  158.  
  159.         }
  160.     }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement