Недоступен из-за своего уровня защиты - C#

Узнай цену своей работы

Формулировка задачи:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Microsoft.VisualBasic;
 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        public struct Students
        {
            string fio, math, rus, fiz;
        }
 
        Students[] str = new Students[50];
        int i, n, r;
        //var fileSW = new StreamWriter();
 
        public void button1_Click(object sender, EventArgs e)
        {
            dataGridView2.Rows.Clear();
            double SrClass = 0, SumClass = 0;
            string S;
            for (int i = 0; i <= n; i++)
            {
                int Sum = 0; double Sr = 0;
                Sum = Convert.ToInt32(str[i]).math + Convert.ToInt32(str[i]).rus + Convert.ToInt32(str[i]).fiz;
                Sr = Sum / 3;
                S &= Convert.ToString(str[i].fio + " " & Sum + " / " + Sr + "\n");
                SumClass += Sr;
                SrClass = SumClass / (n + 1);
            }
 
            r = 0;
            for (int i = 0; i <= dataGridView1.RowCount - 1; i++)
            {
                int Sum = 0; double Sr = 0;
                Sum = str[i].math + +str[i].rus + +str[i].fiz;
                Sr = Sum / 3;
                if (Sr > SrClass)
                {
                    dataGridView1.Rows.Add();
                    dataGridView1.Rows[r].Cells[0].Value = i + 1;
                    dataGridView1.Rows[r].Cells[0].Value = str[i].fio;
                    dataGridView1.Rows[r].Cells[0].Value = str[i].math;
                    dataGridView1.Rows[r].Cells[0].Value = str[i].rus;
                    dataGridView1.Rows[r].Cells[0].Value = str[i].fiz;
                    r++;
                }
            }
            MessageBox.Show("Сумма и средний балл:" + "/n" + S + "/n" + "Средняя оценка в классе:" + " " + Math.Round(SrClass, 1), "Ответ");
        }
 
        public void Form1_Load(object sender, EventArgs e)
        {
            dataGridView1.Rows.Clear(); dataGridView2.Rows.Clear();
            var settingsfile = new System.IO.StreamReader("settings.txt");
            var strSettings = settingsfile.ReadLine();
            if (strSettings == "")
            {
                MessageBox.Show("В settings.txt не прописан файл!", "Упс!");
                settingsfile.Close();
                if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    var fileSR = new System.IO.StreamReader(openFileDialog1.FileName);
                    var settingsfileNew = new System.IO.StreamWriter("settings.txt");
                    settingsfileNew.WriteLine(System.IO.Path.GetFileName(openFileDialog1.FileName)); // Запись в файл имени файла
                    while (!fileSR.EndOfStream)
                    {
                        str[n].fio = fileSR.ReadLine();
                        str[n].math = fileSR.ReadLine();
                        str[n].rus = fileSR.ReadLine();
                        str[n].fiz = fileSR.ReadLine();
                        n++;
                    }
                    n--;
                    fileSR.Close(); settingsfileNew.Close();
                }
            }
            else
            {
                var fileSR = new System.IO.StreamReader(strSettings);
                while (!fileSR.EndOfStream)
                {
                    str[n].fio = fileSR.ReadLine();
                    str[n].math = fileSR.ReadLine();
                    str[n].rus = fileSR.ReadLine();
                    str[n].fiz = fileSR.ReadLine();
                    n++;
                }
                n--;
                fileSR.Close(); settingsfile.Close();
            }
 
            for (i = 0; i <= n; i++)
            {
                dataGridView1.Rows.Add();
                dataGridView1.Rows[i].Cells[0].Value = i + 1;
                dataGridView1.Rows[i].Cells[0].Value = str[i].fio;
                dataGridView1.Rows[i].Cells[0].Value = str[i].math;
                dataGridView1.Rows[i].Cells[0].Value = str[i].rus;
                dataGridView1.Rows[i].Cells[0].Value = str[i].fiz;
            }
        }
    }
}
Жалуется на fio, math, rus, fiz. Оригинал на Vb.net
Public Class Form1
    Private Structure Students
        Dim fio As String
        Dim math, rus, fiz As String
    End Structure
 
    Dim str(50) As Students
    Dim i, n, r As Integer
    Dim fileSW As IO.StreamWriter
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        DataGridView2.Rows.Clear()
        Dim SrClass As Single = 0, SumClass As Single = 0
        Dim S As String
        For Me.i = 0 To n
            Dim Sum As Integer = 0, Sr As Single = 0
            Sum = str(i).math + +str(i).rus + +str(i).fiz
            Sr = Sum / 3
            S &= CStr(str(i).fio & Space(1) & Sum & " / " & Sr & vbCrLf)
            SumClass += Sr
            SrClass = SumClass / (n + 1)
        Next
 
        r = 0
        For Me.i = 0 To DataGridView1.RowCount - 1
            Dim Sum As Integer = 0, Sr As Single = 0
            Sum = str(i).math + +str(i).rus + +str(i).fiz
            Sr = Sum / 3
            If Sr > SrClass Then
                DataGridView2.Rows.Add()
                DataGridView2.Rows(r).Cells(0).Value = i + 1
                DataGridView2.Rows(r).Cells(1).Value = str(i).fio
                DataGridView2.Rows(r).Cells(2).Value = str(i).math
                DataGridView2.Rows(r).Cells(3).Value = str(i).rus
                DataGridView2.Rows(r).Cells(4).Value = str(i).fiz
                r += 1
            End If
        Next i
        MsgBox("Сумма и средний балл:" & vbCrLf & S & vbCrLf & "Средняя оценка в классе:" & Space(1) & Math.Round(SrClass, 1))
    End Sub
 
    Private Sub ВыходToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ВыходToolStripMenuItem.Click
        End
    End Sub
 
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        DataGridView1.Rows.Clear() : DataGridView2.Rows.Clear()
        Dim settingsfile = New System.IO.StreamReader("settings.txt")
        Dim strSettings = settingsfile.ReadLine()
        If strSettings = "" Then
            MsgBox("В settings.txt не прописан файл!")
            settingsfile.Close()
            If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
                Dim fileSR As New System.IO.StreamReader(OpenFileDialog1.FileName)
                Dim settingsfileNew = New System.IO.StreamWriter("settings.txt")
                settingsfileNew.WriteLine(System.IO.Path.GetFileName(OpenFileDialog1.FileName)) 'запись в файл имени файла
                While (Not fileSR.EndOfStream)
                    str(n).fio = fileSR.ReadLine()
                    str(n).math = fileSR.ReadLine()
                    str(n).rus = fileSR.ReadLine()
                    str(n).fiz = fileSR.ReadLine()
                    n += 1
                End While
                n -= 1
                fileSR.Close() : settingsfileNew.Close()
            End If
        Else
            Dim fileSR As New System.IO.StreamReader(strSettings)
            While (Not fileSR.EndOfStream)
                str(n).fio = fileSR.ReadLine()
                str(n).math = fileSR.ReadLine()
                str(n).rus = fileSR.ReadLine()
                str(n).fiz = fileSR.ReadLine()
                n += 1
            End While
            n -= 1
            fileSR.Close() : settingsfile.Close()
        End If
 
        For Me.i = 0 To n
            DataGridView1.Rows.Add()
            DataGridView1.Rows(i).Cells(0).Value = i + 1
            DataGridView1.Rows(i).Cells(1).Value = str(i).fio
            DataGridView1.Rows(i).Cells(2).Value = str(i).math
            DataGridView1.Rows(i).Cells(3).Value = str(i).rus
            DataGridView1.Rows(i).Cells(4).Value = str(i).fiz
        Next i
    End Sub
 
    Private Sub ОткрытьToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ОткрытьToolStripMenuItem.Click
        DataGridView1.Rows.Clear() : DataGridView2.Rows.Clear()
        Dim settingsfile = New System.IO.StreamWriter("settings.txt")
        If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
            Dim fileSR As New System.IO.StreamReader(OpenFileDialog1.FileName)
            settingsfile.WriteLine(System.IO.Path.GetFileName(OpenFileDialog1.FileName))
            n = 0
            While (Not fileSR.EndOfStream)
                str(n).fio = fileSR.ReadLine()
                str(n).math = fileSR.ReadLine()
                str(n).rus = fileSR.ReadLine()
                str(n).fiz = fileSR.ReadLine()
                n += 1
            End While
            n -= 1
            fileSR.Close() : settingsfile.Close()
        End If
 
        For Me.i = 0 To n
            DataGridView1.Rows.Add()
            DataGridView1.Rows(i).Cells(0).Value = i + 1
            DataGridView1.Rows(i).Cells(1).Value = str(i).fio
            DataGridView1.Rows(i).Cells(2).Value = str(i).math
            DataGridView1.Rows(i).Cells(3).Value = str(i).rus
            DataGridView1.Rows(i).Cells(4).Value = str(i).fiz
        Next i
    End Sub
 
    Private Sub ТитульныйЛистToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ТитульныйЛистToolStripMenuItem.Click
        Form2.Show()
    End Sub
End Class

Решение задачи: «Недоступен из-за своего уровня защиты»

textual
Листинг программы
public struct Students
* * * * {
* * * * * * string fio, math, rus, fiz;
* * * * }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

13   голосов , оценка 3.923 из 5
Похожие ответы