Beispiel #1
0
        static void Main(string[] args)
        {
            Aluno[] alunos       = new Aluno[5];//indica Aluno.Length
            var     indicealuno  = 0;
            string  opcaoUsuario = ObterOpçãoUsuário();

            while (opcaoUsuario.ToUpper() != "4")
            //sair do programa
            {
                switch (opcaoUsuario)
                {
                case "1":
                    Console.WriteLine("Informe o nome do aluno.");
                    Aluno aluno = new Aluno();
                    aluno.Nome = Console.ReadLine();

                    Console.WriteLine("Informe a nota do aluno.");

                    if (decimal.TryParse(Console.ReadLine(), out decimal Nota))
                    {
                        aluno.Nota = Nota;
                    }
                    else
                    {
                        throw new ArgumentException("Valor da nota deve ser decimal.");
                    }

                    alunos[indicealuno] = aluno;
                    indicealuno++;
                    //adicionar um aluno e nota
                    break;

                case "2":

                    foreach (var a in alunos)
                    {
                        if (!string.IsNullOrEmpty(a.Nome))    //ocultar espaços no array nulos
                        {
                            Console.WriteLine($"ALUNO: {a.Nome} - Nota: {a.Nota}");
                        }
                    }
                    //escrever a lista de alunos
                    break;

                case "3":
                    decimal notaTotal = 0;
                    var     nrAlunos  = 0;

                    for (int i = 0; i < alunos.Length; i++)
                    {
                        if (!string.IsNullOrEmpty(alunos[i].Nome))
                        {
                            notaTotal = notaTotal + alunos[i].Nota;
                            nrAlunos++;
                        }
                    }

                    var      mediaGeral = notaTotal / nrAlunos;
                    Conceito conceitoGeral;

                    if (mediaGeral < 2)
                    {
                        conceitoGeral = Conceito.E;
                    }
                    else if (mediaGeral < 4)
                    {
                        conceitoGeral = Conceito.D;
                    }
                    else if (mediaGeral < 6)
                    {
                        conceitoGeral = Conceito.C;
                    }
                    else if (mediaGeral < 8)
                    {
                        conceitoGeral = Conceito.B;
                    }
                    else
                    {
                        conceitoGeral = Conceito.A;
                    }

                    Console.WriteLine($"MÉDIA GERAL: {mediaGeral} - CONCEITO: {conceitoGeral}");
                    //calcular media geral dos alunos e um conceito para a mesma
                    break;

                default:
                    throw new ArgumentOutOfRangeException();    //exceção utilizada para parar o programa
                }
                opcaoUsuario = ObterOpçãoUsuário();
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Aluno[] alunos       = new Aluno [5];
            var     indiceAluno  = 0;
            string  opcaoUsuario = ObterOpcaoUsuario();

            while (opcaoUsuario.ToUpper() != "X")
            {
                switch (opcaoUsuario)
                {
                case "1":
                    Console.WriteLine("Informe o nome do aluno:");
                    Aluno aluno = new Aluno();
                    aluno.Nome = Console.ReadLine();
                    Console.WriteLine("Informe a nota:");

                    if (decimal.TryParse(Console.ReadLine(), out decimal nota))
                    {
                        aluno.Nota = nota;
                    }
                    else
                    {
                        throw new ArgumentException("O valor da nota deve ser decimal");
                    }
                    alunos[indiceAluno] = aluno;
                    indiceAluno++;



                    // Adicionar aluno


                    break;

                case "2":
                    foreach (var a in alunos)
                    {
                        if (!string.IsNullOrEmpty(a.Nome))
                        {
                            Console.WriteLine($"Aluno: {a.Nome} Nota: {a.Nota} ");
                        }
                    }
                    //Listar alunos

                    break;

                case "3":
                    decimal notaTotal = 0;
                    var     nrAlunos  = 0;
                    for (int i = 0; i < alunos.Length; i++)
                    {
                        if (!string.IsNullOrEmpty(alunos[i].Nome))
                        {
                            notaTotal = notaTotal + alunos[i].Nota;
                            nrAlunos++;
                        }
                    }
                    var mediaGeral = notaTotal / nrAlunos;
                    Console.WriteLine($"Média geral:{mediaGeral}");
                    //Calcular média geral

                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }


                opcaoUsuario = ObterOpcaoUsuario();
            }
        }