Формировать очередь из фамилий и имен тех из них, у которых количество положительных оценок больше, чем отрицательных - C#
Формулировка задачи:
Для каждого из N студентов группы известны ФИО и оценки (в баллах) по пяти дисциплинам. Сформировать очередь из фамилий и имен тех из них, у которых количество положительных оценок больше, чем отрицательных.
Решение задачи: «Формировать очередь из фамилий и имен тех из них, у которых количество положительных оценок больше, чем отрицательных»
textual
Листинг программы
public partial class Form1 : Form
{
List<Person> student;
public Form1()
{
student = new List<Person>();
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
dataGridView1.Rows.Clear();
dataGridView1.AllowUserToAddRows = false;
try
{
int n = Convert.ToInt32(textBox1.Text);
dataGridView1.Rows.Add(n);
Generate(n);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
button1.Enabled = false;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
student.Add(new Person
(dataGridView1[0, i].Value.ToString(), dataGridView1[1, i].Value.ToString(),
dataGridView1[2, i].Value.ToString(),dataGridView1[3, i].Value.ToString(),
dataGridView1[4, i].Value.ToString(),dataGridView1[5, i].Value.ToString())
);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button3_Click(object sender, EventArgs e)
{
Queue<string> students = new Queue<string>();
foreach (Person z in student)
{
if (z.Count())
{
students.Enqueue(z.FIO);
}
}
foreach(string temp in students)
{
comboBox1.Items.Add(temp);
}
}
private void Generate(int n)
{
Random rand = new Random();
List<string> nick =
"Вася Коля Петя Саша Даша Рома Катя Поля Тома Жора Паша Гоша Тоша"
.Split(' ').ToList();
List<string> surname =
"Котелков Узелков Погромов Томошин Симонов Петров Иванов Котов Крошкин Енотов"
.Split(' ').ToList();
string abc = "ЦУКЕНГШЗХФВАПРОЛДЯЧСМИТБЮ";
string ball = "2345";
for (int i = 0; i < n; i++)
{
dataGridView1[0,i].Value = String.Format("{0} {1}.{2} ",
nick[rand.Next(0,nick.Count)],
surname[rand.Next(0, surname.Count)],
abc[rand.Next(0,abc.Count())]
);
for (int j = 1; j < 6; j++)
{
dataGridView1[j, i].Value = ball[rand.Next(0, ball.Count())];
}
}
}
}
public class Person
{
private string fio;
private int matan;
private int difuru;
private int funan;
private int mathphizik;
private int filosofy;
public string FIO
{
get { return fio; }
set { fio = value; }
}
public Person(string f, string a, string b, string c, string d, string e)
{
matan = Int32.Parse(a);
mathphizik = Int32.Parse(d);
difuru = Int32.Parse(b);
funan = Int32.Parse(c);
filosofy = Int32.Parse(e);
fio = f;
}
public bool Count()
{
int count = 0;
if (this.filosofy > 3) count++;
if (this.matan > 3) count++;
if (this.difuru > 3) count++;
if (this.funan > 3) count++;
if (this.mathphizik > 3) count++;
if (count >= 3) return true;
return false;
}
}