Jump to content

Recommended Posts

Posted

Boa Noite será que me poderiam ajudar quando imprimo  o meu programa imprime joaoramos,e as suas notas ficam pegadas e outro problema é que já fiz varios ifs para aparecer na tela os alunos que são aprovados e os que sao reprovados  e não aparecem nenhum deles a.

Se me poder ajudar Ficaria muito agradecido de preferência em código  .

Class Program

using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace ConsoleApplication1
{
    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 , 18);
            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, 8);
            turma.Add(estundante);
            
         

       
            //imprime cabecalho
            System.Console.WriteLine("╔═════════════════════════════════╦═══════════╦══════════╦═══════════════════════════╗");
            System.Console.WriteLine("║ Nome                            ║ Teste 1   ║ Teste 2  ║   Classificação Final     ║");
            System.Console.WriteLine("╠═════════════════════════════════╬═══════════╬══════════╬═══════════════════════════╣");


            foreach (EstudanteInf est in turma)
            {
                string toPrint  = "║" + est.lerNome() + est.lerTeste1() + est.lerTeste2() + est.classFinal() + "║";
                Console.WriteLine(toPrint);
            }
            //imprime a ultima linha
            System.Console.WriteLine("╚═════════════════════════════════╩═══════════╩══════════╩═══════════════════════════╝");
            System.Console.Read();

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

            }
            

        }

    }
}

class estudante inf

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    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";
                }



            }
        }

        public void imprimir()
        {
            ;
        }
    }
}
Posted

Bom dia,

Depois de ver o código apenas se me ocorreu que não chegas-te a ler o que te foi dito no outro post.

Basta contares os espaços entre entre o texto a ser impresso e a grelha, para preencheres os campos correctamente. Não é nada do outro mundo!

Fica aqui a resposta à questão dos aprovados.

~using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace ConsoleApplication1
{
    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, 18);
            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, 8);
            turma.Add(estundante);




            //imprime cabecalho
            System.Console.WriteLine("╔═════════════════════════════════╦═══════════╦══════════╦═══════════════════════╦══════════════════════════════╗");
            System.Console.WriteLine("║ Nome                            ║ Teste 1   ║ Teste 2  ║   Classificação Final ║         Situação             ║");
            System.Console.WriteLine("╠═════════════════════════════════╬═══════════╬══════════╬═══════════════════════╬══════════════════════════════╣");

            string situacao;
            foreach (EstudanteInf est in turma)
            {
                string toPrint = "║" + est.lerNome() + "║" + est.lerTeste1() + "║" + est.lerTeste2() + "║" + est.classFinal() + "║";

                if (value.classFinal() >= 10)
                {
                    situacao == "aprovado";
                }
                else { situacao == "reprovado";}
                Console.WriteLine(toPrint);
            }
            //imprime a ultima linha
            System.Console.WriteLine("╚═════════════════════════════════╩═══════════╩══════════╩═══════════════════════╩══════════════════════════════╝");
            System.Console.Read();

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

            }


        }

    }
}

 

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"

Posted

Obrigado mas se eu meter a tua sugestão da-me 3 erros, Error    2    Only assignment, call, increment, decrement, and new object expressions can be used as a statement    C:\Users\joao\Desktop\Psi\ex89\ex89\Program.cs    54    21    ex89,Error    1    The name 'value' does not exist in the current context    C:\Users\joao\Desktop\Psi\ex89\ex89\Program.cs    52    21    ex89.

.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    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";
                }



            }
        }

        public void imprimir()
        {
            
        }
    }
}
Posted

Boa noite,

Vá, bem que poderias ter lido o código com atenção! 😄

 

using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace ConsoleApplication1
{
    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, 18);
            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, 8);
            turma.Add(estundante);




            //imprime cabecalho
            System.Console.WriteLine("╔═════════════════════════════════╦═══════════╦══════════╦═══════════════════════╦══════════════════════════════╗");
            System.Console.WriteLine("║ Nome                            ║ Teste 1   ║ Teste 2  ║   Classificação Final ║         Situação             ║");
            System.Console.WriteLine("╠═════════════════════════════════╬═══════════╬══════════╬═══════════════════════╬══════════════════════════════╣");

            string situacao;
            string spaceAux = " ";
            foreach (EstudanteInf est in turma)
            {
                int spaceNome = (33-(est.lerNome().Length));
                //blah blah blah wiskas saquetas e lê o código para fazeres os restantes
                string toPrint = "║" + est.lerNome() + spaceAux.PadRight(spaceNome) +  "║" + est.lerTeste1() + "║" + est.lerTeste2() + "║" + est.classFinal() + "║";

                if (est.classFinal() >= 10) //bastava ler
                {
                    situacao = "aprovado"; //ai se eu me desse ao trabalho de ler... teria reparado no sinal de igual que estava a mais!
                }
                else { situacao = "reprovado"; } //ai se eu me desse ao trabalho de ler... teria reparado no sinal de igual que estava a mais!
                System.Console.WriteLine(toPrint);
            }
            //imprime a ultima linha
            System.Console.WriteLine("╚═════════════════════════════════╩═══════════╩══════════╩═══════════════════════╩══════════════════════════════╝");
            System.Console.Read();

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

            }


        }

    }
}

 

Cordiais cumprimentos,

Apocsantos

"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.