示例#1
0
        private void frmPolinomio_Load(object sender, EventArgs e)
        {
            A = new Polinomio();
            StreamReader arquivo = new StreamReader("c:\\temp\\dadosPoliA.txt");
            string       linha   = "";

            while ((linha = arquivo.ReadLine()) != null)
            {
                A.InserirAposFim(new Termo(
                                     Convert.ToDouble(linha.Substring(0, 5)), // coeficiente
                                     Convert.ToInt32(linha.Substring(5)))     // expoente
                                 );
            }
            arquivo.Close();

            B       = new Polinomio();
            arquivo = new StreamReader("c:\\temp\\dadosPoliB.txt");
            linha   = "";
            while ((linha = arquivo.ReadLine()) != null)
            {
                B.InserirAposFim(new Termo(
                                     Convert.ToDouble(linha.Substring(0, 5)), // coeficiente
                                     Convert.ToInt32(linha.Substring(5)))     // expoente
                                 );
            }
            arquivo.Close();


            A.Exibir(txtA);
            B.Exibir(txtB);
        }
示例#2
0
        public Polinomio somar(Polinomio outra)
        {
            Polinomio lista3 = new Polinomio();

            this.iniciarPercursoSequencial();
            outra.iniciarPercursoSequencial();
            NoLista <Termo> aux = null;

            while (this.Atual != null && outra.Atual != null)
            {
                if (this.Atual.Info.CompareTo(
                        outra.Atual.Info) < 0)
                {
                    lista3.InserirAposFim(
                        new Termo(this.Atual.Info.Coeficiente,
                                  this.Atual.Info.Expoente)
                        );
                    this.atual = this.atual.Prox;
                }
                else
                if (outra.atual.Info.CompareTo(
                        this.atual.Info) < 0)
                {
                    lista3.InserirAposFim(new Termo(outra.Atual.Info.Coeficiente,
                                                    outra.Atual.Info.Expoente));
                    outra.atual = outra.atual.Prox;
                }
                else
                {
                    if (this.Atual.Info.Coeficiente + outra.Atual.Info.Coeficiente != 0)
                    {
                        lista3.InserirAposFim(
                            new Termo(this.Atual.Info.Coeficiente + outra.Atual.Info.Coeficiente,
                                      this.Atual.Info.Expoente));
                    }
                    this.atual  = this.atual.Prox;
                    outra.atual = outra.atual.Prox;
                }
            }  // while

            while (this.atual != null) // acabou o percurso da lista1
            {
                lista3.InserirAposFim(
                    new Termo(this.Atual.Info.Coeficiente,
                              this.Atual.Info.Expoente)
                    );
                this.atual = this.atual.Prox;
            }
            while (outra.atual != null) // acabou o percurso da lista1
            {
                lista3.InserirAposFim(new Termo(outra.Atual.Info.Coeficiente,
                                                outra.Atual.Info.Expoente));
                outra.atual = outra.atual.Prox;
            }

            return(lista3);
        }
示例#3
0
        private void btnSomar_Click(object sender, EventArgs e)
        {
            Polinomio res = A.somar(B);

            res.Exibir(txtResultado);
        }
示例#4
0
 public Polinomio multiplicar(Polinomio B)
 {
     return(default(Polinomio));
 }