ООП. Работа со списком - C#
Формулировка задачи:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace СтруктурыИКлассы_7_ЛР
{
struct Stud
{
public int tel;
public string fio;
public int group;
public int[] ocenki;
public override string ToString()
{
string marks = string.Empty;
foreach (int i in this.ocenki)
marks = marks + i + " ";
return "ФИО: " + this.fio + " телефон: " + this.tel +
" группа: " + this.group + " оценки: " + marks +
" Средняя оценка: " + this.AverageMarks();
}
public double AverageMarks()
{ return this.ocenki.Average(); }
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("введите количество записей");
int n = Int16.Parse(Console.ReadLine());
List<Stud> students = new List<Stud>(); // использование списка
for (int i = 0; i < n; i++)
{
Stud temp = new Stud();
Console.WriteLine("Введите ФИО");
temp.fio = Console.ReadLine();
Console.WriteLine("введите телефон");
temp.tel = Int32.Parse(Console.ReadLine());
Console.WriteLine("введите группу");
temp.group = Int16.Parse(Console.ReadLine());
Console.WriteLine("введите оценки");
temp.ocenki = new int[5];
for (int j = 0; j < temp.ocenki.Length; j++)
{
int m = Int16.Parse(Console.ReadLine());
if (m > 0 && m < 6) temp.ocenki[j] = m;
else temp.ocenki[j] = 3;
}
students.Add(temp);
}
foreach (Stud s in students)
{
Console.Write(s);
}
Console.ReadKey();
}
}
}Решение задачи: «ООП. Работа со списком»
textual
Листинг программы
public static List<Stud> RemoveStudent(List<Stud> nameList, double ocenkaAverage)
{
List<Stud> tmp = new List<Stud>();
for (int i = 0; i < nameList.Count; i++)
if (nameList[i].AverageMarks() == ocenkaAverage)
tmp.Add(nameList[i]);
return tmp;
}