示例#1
0
        static void Main(string[] args)
        {
            aluno[] alunos       = new aluno[5];
            string  opcaoUsuario = ObterOpcaoUsuario();

            Console.WriteLine();
            int indiceAluno = 0;

            while (opcaoUsuario.ToUpper() != "X")
            {
                switch (opcaoUsuario)
                {
                case "1":
                    indiceAluno = NovoAluno(alunos, indiceAluno);
                    break;

                case "2":
                    ListarAlunos(alunos);
                    break;

                case "3":
                    MediaGeral(alunos);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                opcaoUsuario = ObterOpcaoUsuario();
            }
        }
示例#2
0
        private static int NovoAluno(aluno[] alunos, int indiceAluno)
        {
            Console.WriteLine("Informe o nome do aluno:");
            aluno aluno = new aluno();

            aluno.Nome = Console.ReadLine();

            Console.WriteLine("");

            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++;
            Console.WriteLine("");
            return(indiceAluno);
        }