Skip to content

Commit

Permalink
Soma e Subtração reais com erros e outras definições de funções privadas
Browse files Browse the repository at this point in the history
ricardo authored and ricardo committed Aug 18, 2016
1 parent db0853f commit a5f7b05
Showing 5 changed files with 93 additions and 5 deletions.
5 changes: 5 additions & 0 deletions InteiroLovelace.cpp
Original file line number Diff line number Diff line change
@@ -22,7 +22,12 @@ InteiroLovelace::InteiroLovelace(const Lovelace &copiarLovelace)
if (!copiarLovelace.eZero())
copiarAlgarismos(copiarLovelace, *this);
}
InteiroLovelace::InteiroLovelace(const char *algarismos,int tamanho,int quantidadeAlgarismos,bool zero,bool sinal)
: Lovelace(algarismos,tamanho,quantidadeAlgarismos,zero)
{
setSinal(sinal);

}
void InteiroLovelace::inicializar(){
Lovelace::inicializar();
setSinal(true);
3 changes: 3 additions & 0 deletions InteiroLovelace.hpp
Original file line number Diff line number Diff line change
@@ -16,6 +16,9 @@ class InteiroLovelace: public Lovelace
InteiroLovelace();
InteiroLovelace(const InteiroLovelace &copiarInteiroLovelace);
InteiroLovelace(const Lovelace &copiarLovelace);
InteiroLovelace(const char *algarismos,int tamanho,int quantidadeAlgarismos,bool zero,bool sinal);


// ~InteiroLovelace(); // Não é necessário

void imprimir() const;
1 change: 1 addition & 0 deletions Lovelace.hpp
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ class Lovelace{//Representa numero natural
bool vefEhZeroBF();
int removeZerosNaoSignificativos();


int getMenorDivisao(const Lovelace &maior,const Lovelace &menor,Lovelace &saida) const;
void concatenaNumeros(const Lovelace &maisSiginificativo,const Lovelace &menosSignificativo,Lovelace &saida) const;
void inverteNumero(Lovelace &saida) const;
87 changes: 82 additions & 5 deletions RealLovelace.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
#include "RealLovelace.hpp"
long long int RealLovelace::casasDecimaisExibicao=100;
void RealLovelace::digitosToBitwise(long long int tamanho,char * entrada,char* saida)
{
int c;
if(saida)
delete []saida;

saida = new char[tamanho/2];

for(c=0;((2*c)+1)<tamanho;c++)
saida[c]=((entrada[2*c]<<4)+(entrada[2*c+1]));

if(tamanho&1)//Se for impar seta um digito inválido na ultima posição
saida[c]=((entrada[2*c]<<4)+15);



}
InteiroLovelace& RealLovelace::toInteiroLovelace(long long int zeros)
{ int qtdAlgs = zeros+getQuantidadeAlgarismos() ;
char *digitos = new char[qtdAlgs];
char *algs;

for(int c=0;c<zeros;c++)
digitos[c]=0;
for(int c=zeros;c<getQuantidadeAlgarismos();c++)
digitos[c]= getDigito(c-zeros);

digitosToBitwise(qtdAlgs,digitos,algs);
InteiroLovelace *resultado = new InteiroLovelace(algs,qtdAlgs/2,qtdAlgs,eZero(),getSinal());
//Mozila Warming
return *resultado;
}
RealLovelace::RealLovelace()
:InteiroLovelace()//Talvez isso já fosse feito de forma automática.... mas...
{
setExpoente(0);
}
@@ -15,7 +47,7 @@ RealLovelace::RealLovelace(string A)
}
RealLovelace::RealLovelace(const RealLovelace &A)
{
//Utilizar atribuir como base
atribuir(A);
}
void RealLovelace::setExpoente(long long int X)
{
@@ -42,18 +74,63 @@ RealLovelace & RealLovelace::atribuir(const string A)
}
RealLovelace & RealLovelace::atribuir(const RealLovelace &A)
{

this->copiarAlgarismos(A,*this);
this->setQuantidadeAlgarismos(A.getQuantidadeAlgarismos());
this->setTamanho(A.getTamanho());
this->setZero(A.eZero());
this->setExpoente(A.getExpoente());
this->setSinal(A.getSinal());
}
RealLovelace RealLovelace::somar(const RealLovelace B) const
{

{ if(this->getExpoente()==B.getExpoente())
{
InteiroLovelace auxA((toInteiroLovelace(0)));//Bug estranho, checar!
InteiroLovelace auxB(B.toInteiroLovelace(0));
return auxA.somar(B);//Tem que converter esse resultado
}
if(this->getExpoente()>B.getExpoente())
{
long long int zeros = (this->getExpoente()-B.getExpoente());
InteiroLovelace auxA((toInteiroLovelace(zeros)));
InteiroLovelace auxB(B.toInteiroLovelace(0));
return auxA.somar(B);
}
else
{
long long int zeros = (this->getExpoente()-B.getExpoente());
InteiroLovelace auxA((toInteiroLovelace(0)));
InteiroLovelace auxB(B.toInteiroLovelace(zeros));
return auxA.somar(B);
}
}
RealLovelace RealLovelace::subtrair(RealLovelace B) const
{

if(this->getExpoente()==B.getExpoente())
{
InteiroLovelace auxA((toInteiroLovelace(0)));
InteiroLovelace auxB(B.toInteiroLovelace(0));
return auxA.subtrair(B);
}
if(this->getExpoente()>B.getExpoente())
{
long long int zeros = (this->getExpoente()-B.getExpoente());
InteiroLovelace auxA((toInteiroLovelace(zeros)));
InteiroLovelace auxB(B.toInteiroLovelace(0));
return auxA.subtrair(B);
}
else
{
long long int zeros = (this->getExpoente()-B.getExpoente());
InteiroLovelace auxA((toInteiroLovelace(0)));
InteiroLovelace auxB(B.toInteiroLovelace(zeros));
return auxA.subtrair(B);
}
}
RealLovelace RealLovelace::multiplicar(RealLovelace B) const
{
InteiroLovelace auxA((toInteiroLovelace(0)));
InteiroLovelace auxB(B.toInteiroLovelace(0));


}
RealLovelace RealLovelace::dividir(RealLovelace B) const
2 changes: 2 additions & 0 deletions RealLovelace.hpp
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@ class RealLovelace: public InteiroLovelace{
private:
long long int expoente;
static long long int casasDecimaisExibicao;
InteiroLovelace& toInteiroLovelace(long long int zeros=0);
void digitosToBitwise(long long int tamanho,char * entrada,char* saida);
public:

//Construtores

0 comments on commit a5f7b05

Please sign in to comment.