Jump to content

Recommended Posts

Posted

Boa tarde estou aqui com  um problema em meter este programa funcionar o programa tem de imprimir dez alunos com resultado do teste 1 e teste 2 e a media dois testes .

Também preciso de ajuda a fazer uma tabela onde tem aparecer escrito em cima dos nome dos alunos e as notas deles ,Nome do Aluno ,nota do teste1,nota do teste 2 , classificação final.

 

Se me alguém puder ajudar ficaria muito grato Precisava mesmo de ajuda Se pudessem dar exemplos de como fazer uma tabela também era uma boa ajuda  mas o principal era conseguir meter este programa a funcionar  .

Class Program .

using System.Collections;

namespace ex1
{
    class Program
    {
        static void Main(string[] args)
        {
            ArrayList turma = new ArrayList();
            EstudanteInf estundante = new EstudanteInf("joao Ramos", 20, 15);
            turma.Add(estundante);
            estundante = new EstudanteInf("tiago", 15, 16);
            turma.Add(estundante);
            estundante = new EstudanteInf("andre", 13, 13);
            turma.Add(estundante);
            estundante = new EstudanteInf("pedro", 13, 13);
            turma.Add(estundante);
            estundante = new EstudanteInf("diogo", 13, 15);
            turma.Add(estundante);
            estundante = new EstudanteInf("goncalo", 13, 16);
            turma.Add(estundante);
            estundante = new EstudanteInf("bruno", 13, 17);
            turma.Add(estundante);
            estundante = new EstudanteInf("francisco", 13, 18);
            turma.Add(estundante);
            estundante = new EstudanteInf("andre", 13, 19);
            turma.Add(estundante);
            estundante = new EstudanteInf("pascoal", 8, 3);
            turma.Add(estundante);
            estundante = new EstudanteInf("afonso", 9, 5);
            turma.Add(estundante);

            foreach (EstudanteInf value in turma)
            {
                if (value.situacaoDoAluno().Equals("Aprovado"))
                {
                    value.imprimir();
                }

            }


            System.Console.WriteLine();
            System.Console.Read();

          
        }
    }
}

 

Class EstudanteInf

using System; 

namespace ex1
{
    class EstudanteInf
    {
        string Nome;
        Double Teste1;
        Double Teste2;
        private string p;


        public EstudanteInf(string NomeDoAluno, Double NotaTeste1, Double NotaTeste2)
        {
            Nome = NomeDoAluno;
            Teste1 = NotaTeste1;
            Teste2 = NotaTeste2;
        }

        public EstudanteInf(string p)
        {
            // TODO: Complete member initialization
            this.p = p;
        }

        public Double classFinal()
        {
            Double media = (Teste1 + Teste2) / 2;
            return media;
        }
        public string lerNome()
        {
            return Nome;
        }

        public void escreveNome(string NomeDoAluno)
        {
            Nome = NomeDoAluno;

        }

        public void escrevenotaTeste1(Double notaTeste1)
        {
            Teste1 = notaTeste1;
        }

        public void escrevenotaTeste2(Double notaTeste2)
        {
            Teste2 = notaTeste2;
        }

        public void imprimir(Double classificacaoFinal)
        {
            System.Console.WriteLine("| " + lerNome() + " | " + Teste1 + " | " + Teste2 + " | " + classFinal());
        }
        public string situacaoDoAluno()
        {
            double classificacaoFinal = classFinal();
            if (classificacaoFinal >= 10)
            {
                return "Aprovado";

            }

            else
            {
                if (classificacaoFinal >= 8)
                    return "Admitido a oral";

                else
                {
                    return "reprovado";
                }



            }
        }

        internal void imprimir()
        {
            throw new NotImplementedException();
        }
    }
}
Posted

Certo. E qual é o problema? O que já tentaste e que resultados estás a obter?
Repara que tens duas assinaturas para o imprimir, e estás a usar precisamente a que não está implementada.

Sérgio Ribeiro


"Great coders aren't born. They're compiled and released"
"Expert coders do not need a keyboard. They just throw magnets at the RAM chips"

Posted

Boa tarde,

using System.Collections;

namespace ex1
{
    class Program
    {
        static void Main(string[] args)
        {
            ArrayList turma = new ArrayList();
            EstudanteInf estundante = new EstudanteInf("joao Ramos", 20, 15);
            turma.Add(estundante);
            estundante = new EstudanteInf("tiago", 15, 16);
            turma.Add(estundante);
            estundante = new EstudanteInf("andre", 13, 13);
            turma.Add(estundante);
            estundante = new EstudanteInf("pedro", 13, 13);
            turma.Add(estundante);
            estundante = new EstudanteInf("diogo", 13, 15);
            turma.Add(estundante);
            estundante = new EstudanteInf("goncalo", 13, 16);
            turma.Add(estundante);
            estundante = new EstudanteInf("bruno", 13, 17);
            turma.Add(estundante);
            estundante = new EstudanteInf("francisco", 13, 18);
            turma.Add(estundante);
            estundante = new EstudanteInf("andre", 13, 19);
            turma.Add(estundante);
            estundante = new EstudanteInf("pascoal", 8, 3);
            turma.Add(estundante);
            estundante = new EstudanteInf("afonso", 9, 5);
            turma.Add(estundante);
			//imprime cabecalho
           Console.WriteLine("╔═════════════════════════════════╦═══════════╦══════════╦═══════════════════════════╗");
           Console.WriteLine("║ Nome                            ║ Teste 1   ║ Teste 2  ║   Classificação Final     ║");
           Console.WriteLine("╠═════════════════════════════════╬═══════════╬══════════╬═══════════════════════════╣");
           
          
          foreach (EstudanteInf value in turma)
            {
             string toPrint = "║" + Value.lernome() + Value.lerTeste1() + Value.lerTeste2() + Value.classFinal() + "║";
            }
			//imprime a ultima linha
          Console.WriteLine("╚═════════════════════════════════╩═══════════╩══════════╩═══════════════════════════╝");
//
            System.Console.WriteLine();
            System.Console.Read();

          
        }
    }
}

 

Class

using System;

namespace ex1
{
    class EstudanteInf
    {
        string Nome;
        Double Teste1;
        Double Teste2;
        private string p;


        public EstudanteInf(string NomeDoAluno, Double NotaTeste1, Double NotaTeste2)
        {
            Nome = NomeDoAluno;
            Teste1 = NotaTeste1;
            Teste2 = NotaTeste2;
        }

        public EstudanteInf(string p)
        {
            // TODO: Complete member initialization
            this.p = p;
        }

        public Double classFinal()
        {
            Double media = (Teste1 + Teste2) / 2;
            return media;
        }
        public string lerNome()
        {
            return Nome;
        }
		public string lerTeste1()
        {
            return Teste1.toString();
        }
		public string lerTeste2()
        {
            return Teste2.toString();
        }

        public void escreveNome(string NomeDoAluno)
        {
            Nome = NomeDoAluno;

        }

        public void escrevenotaTeste1(Double notaTeste1)
        {
            Teste1 = notaTeste1;
        }

        public void escrevenotaTeste2(Double notaTeste2)
        {
            Teste2 = notaTeste2;
        }

        public string situacaoDoAluno()
        {
            double classificacaoFinal = classFinal();
            if (classificacaoFinal >= 10)
            {
                return "Aprovado";

            }

            else
            {
                if (classificacaoFinal >= 8)
                    return "Admitido a oral";

                else
                {
                    return "reprovado";
                }

            }
        }

        internal void imprimir()
        {
            throw new NotImplementedException();
        }
    }
}

Ainda podes optimizar imenso o código e por exemplo colocar uma validação para o nome dar o numero exacto de caracteres para obteres a "grelha" toda formatada correctamente, mas isso é um bom exercício para tu fazeres!

Cordiais cumprimentos,

Apocsantos

  • Vote 1

"A paciência é uma das coisas que se aprendeu na era do 48k" O respeito é como a escrita de código, uma vez perdido, dificilmente se retoma o habito"

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.