Доработать решение задачи. Вывод списка студентов по итогам аттестации - C#
Формулировка задачи:
Была дана задача, вывести список студентов у которых по итогам аттестации только "2". Реализовал для одной оценки, а нужно для 7.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Struct
{
public struct Student
{
public string f;
public int m;
public int g;
public Student(string f1, int m1, int g1)
{
f = f1;
m = m1;
g = g1;
}
}
class Program
{
static void Main(string[] args)
{
Student[] st = new Student[5];
for (int i = 0; i < st.Length; i++)
{
Console.WriteLine("Введите фамилию студента");
st[i].f = Console.ReadLine();
Console.WriteLine("Введите оценку студента");
st[i].m = Int32.Parse(Console.ReadLine());
Console.WriteLine("Введите группу студента");
st[i].g = Int32.Parse(Console.ReadLine());
}
{
for (int i = 0; i < st.Length; i++)
{
if (st[i].m == 2)
Console.WriteLine("Студент получивший 2 по итогам аттестации {0}\t, Оценка{1}, Группа{2} ", st[i].f, st[i].m, st[i].g);
}
}
}
}
}Решение задачи: «Доработать решение задачи. Вывод списка студентов по итогам аттестации»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Struct
{
public struct Student
{
public string f;
public int[] m;
public int g;
public Student(string f1, int[] m1, int g1)
{
f = f1;
m = m1;
g = g1;
}
}
class Program
{
static void Main(string[] args)
{
Student[] st = new Student[5];
for (int i = 0; i < st.Length; i++)
{
Console.Clear();
st[i].m = new int[7];
Console.WriteLine("Введите фамилию {0} студента", i + 1);
st[i].f = Console.ReadLine();
for (int j = 0; j < st[i].m.Length; j++)
{
Console.WriteLine("Введите {0} оценку студента", j + 1);
st[i].m[j] = Int32.Parse(Console.ReadLine());
}
Console.WriteLine("Введите группу {0} студента", i + 1);
st[i].g = Int32.Parse(Console.ReadLine());
}
{
for (int i = 0; i < st.Length; i++)
{
if (st[i].m.Average() <= 2) // если среднее значение среди всех оценок <= 2
Console.WriteLine("Студент получивший 2 по итогам аттестации: {0}\t, Оценки: {1}; Группа:{2} ",
st[i].f, String.Join(" ",st[i].m), st[i].g);
}
}
Console.ReadLine();
}
}
}