NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

using System;

public class Student
{
public string FullName { get; set; }
public string GroupNumber { get; set; }
public int[] Grades { get; set; }

public Student(string fullName, string groupNumber, int[] grades)
{
FullName = fullName;
GroupNumber = groupNumber;
Grades = grades;
}

// Метод для вычисления среднего балла
public double GetAverageGrade()
{
double sum = 0;
foreach (var grade in Grades)
{
sum += grade;
}
return sum / Grades.Length;
}
}


Форма
using System;
using System.Windows.Forms;

public partial class Form1 : Form
{
// Массив из 5 студентов
private Student[] students = new Student[5];

public Form1()
{
InitializeComponent();
}

// Обработчик кнопки для ввода данных студентов
private void btnAddData_Click(object sender, EventArgs e)
{
try
{
// Ввод данных для 5 студентов
for (int i = 0; i < 5; i++)
{
string fullName = Microsoft.VisualBasic.Interaction.InputBox("Введите фамилию и инициалы студента " + (i + 1), "Ввод данных", "");
string groupNumber = Microsoft.VisualBasic.Interaction.InputBox("Введите номер группы студента " + (i + 1), "Ввод данных", "");
int[] grades = new int[5];

// Ввод оценок для студента
for (int j = 0; j < grades.Length; j++)
{
string gradeInput = Microsoft.VisualBasic.Interaction.InputBox("Введите оценку " + (j + 1) + " для студента " + (i + 1), "Ввод данных", "");
if (!int.TryParse(gradeInput, out grades[j]) || grades[j] < 1 || grades[j] > 5)
{
MessageBox.Show("Ошибка! Оценки должны быть целыми числами от 1 до 5.", "Некорректные данные", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}

// Создание объекта студента
students[i] = new Student(fullName, groupNumber, grades);
}

MessageBox.Show("Данные успешно введены!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show("Произошла ошибка: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

// Обработчик кнопки для вывода студентов с средним баллом больше 4.0
private void btnDisplayHighScores_Click(object sender, EventArgs e)
{
bool found = false;
string result = "";

foreach (var student in students)
{
if (student != null && student.GetAverageGrade() > 4.0)
{
result += $"Фамилия: {student.FullName}, Группа: {student.GroupNumber}n";
found = true;
}
}

if (found)
{
MessageBox.Show(result, "Студенты с высоким средним баллом", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Нет студентов с средним баллом больше 4.0.", "Результаты", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}

// Обработчик кнопки для вывода всех студентов с их данными
private void btnDisplayAllStudents_Click(object sender, EventArgs e)
{
string result = "";
foreach (var student in students)
{
if (student != null)
{
result += $"Фамилия: {student.FullName}, Группа: {student.GroupNumber}, Средний балл: {student.GetAverageGrade():F2}n";
}
}
MessageBox.Show(result, "Все студенты", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.