Treceți la conținutul principal

program principal cpp

#include "clasa.h"
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>

#define DELAY 9000000

void delay()
{
 for(long i=0;i<DELAY;i++);
}

//constructor cu initializare de la tastatura
BigInt::BigInt()
{char x;
 signed char t[400];
 int i;
 printf("\nNumarul cu semn ");
 do 
 s=getche();
 while((s!='+')&&(s!='-'));
 n=0;
 do {x=getche();
  t[n]=x-'0';
  n++;
  }
 while((x>='0')&&(x<='9'));
 n--;
 for(i=0;i<n;i++)
  nr[i]=t[n-i-1];
}

//constructor cu initializare prin parametri
BigInt::BigInt(char semn,signed char numar[],int dim)
{int i;
 s=semn;
 n=dim;
 for(i=0;i<n;i++)
  nr[i]=numar[n-i-1];
}


//transform un int negativ in pozitiv
int BigInt::Pozitiv(int x)
{int a,vb;
 a=0; vb=0;
 while(vb==0)
  if((x+a)==0) vb=1;
  else a=a+1;
 x=a;
return x;
}

//constructor dintr-un nr int obisnuit
BigInt::BigInt(int x)
{int i;
 if(x>=0) s='+';
 else {s='-'; x=Pozitiv(x); }
 n=0; i=0;
 while(x!=0)
 {nr[i]=x%10; i++; n=i; x=x/10;}
}

//destructor
/*BigInt::~BigInt()
{
 printf("Mesaj!!!");

}*/

//metoda de afisare
void BigInt::Afisare()
{int i;
 putch(s);
 if(n==0) putch('0');
 else
  for(i=0;i<n;i++)
   printf("%d",nr[n-i-1]);
 printf(" ");
}

//metoda pt inmultirea unui numar foarte mare cu 10 la puterea p
BigInt Prod_10(int p,BigInt &a)
{int i;
 BigInt a2(0);
 for(i=0;i<a.n;i++)
  a2.nr[i+p]=a.nr[i];
 for(i=0;i<p;i++)
  a2.nr[i]=0;
 a2.n=p+a.n;
 a2.s=a.s;
return a2;
}

//metoda pt aflarea maximului in val absoluta
int BigInt::Max(BigInt a2)
{int i,m;
 m=n<a2.n?-1:(n==a2.n?0:1);
 i=n;
 while((m==0)&&(i>=0))
  {m=nr[i]-a2.nr[i];
   i--;
  }
return m;
}

//supraincarcare adunare doua nr BigInt
BigInt BigInt::operator+(BigInt a2)
{int i,k,max; 
 signed char p;
 BigInt a3(0);
 max=(n>a2.n)?n:a2.n;
 a3.s=s;
 k=0;
 for(i=0;i<max;i++)
  {p=(i<n?nr[i]:0)+(i<a2.n?a2.nr[i]:0)+k;
  a3.nr[i]=p%10;
  k=p/10;
  }
 if(k!=0) {a3.nr[max]=k; a3.n=max+1;}
 else a3.n=max;
 
return a3;
}

//adunare BigInt cu int
BigInt BigInt::operator+(int x)
{BigInt a3(0),a2(x);
 a3=*this+a2;
return a3; 
}


//supraincarcare scadere BigInt-BigInt
BigInt BigInt::operator-(BigInt a2)
{int i,m,impr;
 BigInt a3(0),aux(0);
 m=this->Max(a2);
 if(m>0) a3.s=this->s;
 else
  if(m<0) a3.s=(this->s=='+')?'-':'+';
  else {m=0; a3.n=0;a3.s='+';}
 if(m!=0)
  {if(m<0) 
   {aux=*this;
    *this=a2;
    a2=aux;
   }
  impr=0;
  for(i=0;i<this->n;i++)
   {a3.nr[i]=this->nr[i]-(i<a2.n?a2.nr[i]:0)-impr;
   if(a3.nr[i]<0)
    {a3.nr[i]+=10;
    impr=0;
    }
   else impr=0;
   a3.n=this->n;
   while(a3.nr[a3.n-1]==0) a3.n--;
   }
  }
return a3;
}

//supraincarcare scadere BigInt-int
BigInt BigInt::operator-(int x)
{BigInt a2(x),a3(0);
 a3=*this-a2;
return a3;
}

//inmultire cu un numar 
BigInt BigInt::operator*(int x)
{int i;
 signed char t,s1;
 BigInt a2(0);
 a2.s=s;
 t=0;
 for(i=0;i<n;i++)
 {s1=nr[i]* x+t;
  a2.nr[i]=s1%10;
  t=s1/10; 
 }
 if(t!=0) {a2.nr[n]=t;
     a2.n=n+1;
    }
 else a2.n=n;

 return a2;
}

//inmultire doua numere BigInt
BigInt BigInt::operator*(BigInt a2)
{int i;
 BigInt temp(0);
 BigInt a3(0);
 
 if(s==a2.s) a3.s='+';
 else a3.s='-';
 a3.n=0;
 for(i=0;i<a2.n;i++)
 {temp.n=0;
  temp.s=a2.s;
//inmultire BigInt cu int
  //x=a2.nr[i];
  temp=(*this)*a2.nr[i]; 
//inmultire BigInt cu 10 la put i
  temp=Prod_10(i,temp);
  a3=a3+temp;
  }
return a3;
}

//////////////////////


//prefixat returneaza valoarea incrementata
const BigInt& operator++(BigInt& a)
{int i,s,t;
 t=1;
 for(i=0;i<a.n;i++)
 {s=a.nr[i]+t;
  a.nr[i]=s%10;
  t=s/10; 
 }
 if(t!=0) {a.nr[a.n]=t; a.n=a.n+1;}
return a;
}

//postfixat returneaza valoarea de dinainte de incrementare
const BigInt operator++(BigInt& a,int)
{int i,s,t;
 BigInt aux(0);
 aux=a;
 t=1;
 for(i=0;i<a.n;i++)
 {s=a.nr[i]+t;
  a.nr[i]=s%10;
  t=s/10; 
 }
 if(t!=0) {a.nr[a.n]=t; a.n=a.n+1;}
return aux;
}

//prefixat
const BigInt& operator--(BigInt& a)
{int s,i,impr;
 impr=1;
 for(i=0;i<a.n;i++)
 {s=a.nr[i]-impr;
     if(s<0) {a.nr[i]=9; impr=1;}
  else {a.nr[i]=s; impr=0;}
 }
 if(a.nr[a.n-1]==0) a.n--;
return a;
}

//postfixat
const BigInt operator--(BigInt& a,int)
{int s,i,impr;
 BigInt aux(0);
 aux=a;
 impr=1;
 for(i=0;i<a.n;i++)
 {s=a.nr[i]-impr;
     if(s<0) {a.nr[i]=9; impr=1;}
  else {a.nr[i]=s; impr=0;}
 }
 if(a.nr[a.n-1]==0) a.n--;
return aux;
}

//supraincarcare egalitate nr mare cu un alt numar mare
int BigInt::operator==(BigInt a2)
{int i,vb;
 if((s==a2.s)&&(n==a2.n))
  {vb=0; i=0;
   while((vb==0)&&(i<n))
   {if(nr[i]!=a2.nr[i]) vb=1;
    i++;
   }
   if(vb==0) return 1;
  }
return 0;
}

//supraincarcare nr mare cu un int
int BigInt::operator==(int x)
{BigInt a2(x);
 if(*this==a2) return 1;
return 0;
}

//supraincarcare pt operatorul BigInt<BigInt
int BigInt::operator<(BigInt a2)
{int i,vb;
 if((s!=a2.s)&&(s=='-')) return 1;
 else
  if(s=='+')
   {if(n<a2.n) return 1;
    if(n==a2.n)
    {vb=0; i=n-1;
     while((vb==0)&&(i!=-1))
     {if(nr[i]<a2.nr[i]) vb=1;
      i--;
     }
     if(vb==1) return 1;
    }
   }
  else
   {if(s=='-')
    {if(n>a2.n) return 1;
     if(n==a2.n)
     {vb=0; i=n-1;
      while((vb==0)&&(i!=-1))
      {if(nr[i]>a2.nr[i]) vb=1;
       i--;
      }
      if(vb==1) return 1;
      }
    }   
   }
return 0;
}

//supraincarcare pt operatorul BigInt<int
int BigInt::operator<(int x)
{BigInt a2(x);
 if(*this<a2) return 1;
return 0;
}

//supraincarcare BigInt<=BigInt
int BigInt::operator<=(BigInt a2)
{
 if(*this<a2) return 1;
 if(*this==a2) return 1;
return 0;
}

//supraincarcare BigInt<=int
int BigInt::operator<=(int x)
{BigInt a2(x);
 if(*this<a2) return 1;
 if(*this==a2) return 1;
return 0;
}


//supraincarcare op BigInt>BigInt
int BigInt::operator>(BigInt a2)
{
 if(*this<a2) return 0;
 if(*this==a2) return 0;
return 1;
}

//supraincarcare BigInt>int
int BigInt::operator>(int x)
{BigInt a2(x);
 if(*this<a2) return 0;
 if(*this==a2) return 0;
return 1;
}

//supraincarcare operator >=
int BigInt::operator>=(BigInt a2)
{ if(*this>a2) return 1;
 if(*this==a2) return 1;
return 0;
}

int BigInt::operator>=(int x)
{BigInt a2(x);
  if(*this>a2) return 1;
 if(*this==a2) return 1;
return 0;
}

//supraincarcare operator diferit
int BigInt::operator!=(BigInt a2)
{int i,vb;
 if(s!=a2.s) return 1;
 else
  if(n!=a2.n) return 1;
  else 
   {vb=0; i=0;
    while((vb==0)&&(i<n))
    {if(nr[i]!=a2.nr[i]) vb=1;
     i++;
    }
   if(vb==1) return 1;
   }
return 0;
}

int BigInt::operator!=(int x)
{BigInt a2(x);
 if(*this!=a2) return 1;
return 0;
}

//test zero
int BigInt::operator!()
{
 if((n==0)&&(nr[n]==0))return 1;
return 0;
}



istream & operator>>(istream &intrare, BigInt &a)
{char t[400];
 int i;
 do
 intrare>>a.s;
 while((a.s!='+')&&(a.s!='-'));
 a.n=0;
 cin.get(t,40);
 for(i=0;i<strlen(t);i++)
  {if((t[i]>='0')&&(t[i]<='9'))
    {t[i]=t[i]-'0';
    a.n++;
    }
   else break;
  }
 for(i=0;i<a.n;i++)
  a.nr[i]=t[a.n-i-1];
return intrare;
}


ostream & operator<<(ostream &iesire,const BigInt &a)
{int i;
  
 iesire<<a.s;
 if(a.n==0) iesire<<0;
 else
  for(i=0;i<a.n;i++)
   iesire<<(int)a.nr[a.n-i-1];
 
return iesire;
}


BigInt BigInt::operator/(int x) 
{int i,r,k,temp[401];
BigInt t(0);
 t.s=s;
 if(x==0) cout<<"Operatie lipsita de sens!";
 else
 { t.n=1;
  if(nr[n-1]>=x)
   {temp[0]=nr[n-1]/x;
   r=nr[n-1]%x;
   i=2;
   while(i<n+2) 
    {t.n++;
    r=r*10+nr[n-i];
    temp[i-1]=r/x;
    r=r%x;
    i++;
    }
   }
  else
   {i=0;
    temp[0]=nr[n-1];
    while(temp[0]<x)
    {i++;
     temp[0]=temp[0]*10+nr[n-i-1];
     }
    r=temp[0]%x;
    temp[0]=temp[0]/x;
    k=1;
    while(i<n) 
    {t.n++;
    r=r*10+nr[n-i-2];
    temp[k]=r/x;
    r=r%x;
    i++;k++;
    }
   }
 }
 t.n--;
 for(i=0;i<t.n;i++)
  t.nr[i]=temp[t.n-i-1];
return t;
}
/*
BigInt BigInt::operator/(BigInt a2)
{BigInt a(0)

}
*/

BigInt BigInt::operator%(int x)
{BigInt r(0); 
 r=(*this)/x;
 r=(*this)-r*x;
return r;
}

void main()
{ 
/*  
 int p=8432,r=6,q=-8765,x=12345,y=123457,z=-4567888; 
 BigInt a(x),b(y),c(z),c2(0);
 
   
 cout<<"\t\tTESTAREA PROGRAMULUI\n";
 cout<<"Int:     p="<<p<<"  q="<<q<<"  r="<<r<<endl;
 cout<<"BigInt:  A="<<a<<"  B="<<b<<"  C="<<c<<endl;

 cout<<"\n\n\t\tCOMPARATII pe BigInt\n";
 cout<<"A >  B";
 a>b?cout<<"  True\n":cout<<"  False\n";
 cout<<"A >= B";
 a>=b?cout<<"  True\n":cout<<"  False\n";
 cout<<"A <  B";
 a<b?cout<<"  True\n":cout<<"  False\n";
 cout<<"A <= B";
 a<=b?cout<<"  True\n":cout<<"  False\n";
 cout<<"A != B";
 a!=b?cout<<"  True\n":cout<<"  False\n";
 cout<<"A == B";
 a==b?cout<<"  True\n":cout<<"  False\n";
 cout<<" ! A";
 !a?cout<<"  True\n":cout<<"  False\n";
 
 cout<<"\n\t\tCOMPARATII BigInt cu Int\n";
 cout<<"C >  q";
 c>q?cout<<"  True\n":cout<<"  False\n";
 cout<<"C >= q";
 c>=q?cout<<"  True\n":cout<<"  False\n";
 cout<<"C <  q";
 c<q?cout<<"  True\n":cout<<"  False\n";
 cout<<"C <= q";
 c<=q?cout<<"  True\n":cout<<"  False\n";
 cout<<"C != q";
 c!=q?cout<<"  True\n":cout<<"  False\n";
 cout<<"C == q";
 c==q?cout<<"  True\n":cout<<"  False\n";
 cout<<" ! p";
 !p?cout<<"  True\n":cout<<"  False\n"; 


 cout<<"\n\t\tOPERATII \n";
 cout<<"C * r= "<<(c*r)<<endl;
 cout<<"A * B= "<<(a*b)<<endl;
 cout<<"B / p= "<<(b/p)<<endl;
 cout<<"B % r= "<<(b%r)<<endl;
 cout<<"A + r= "<<(a+r)<<endl;
 cout<<"A + B= "<<(a+b)<<endl;
 cout<<"B - r= "<<(b-r)<<endl;
 cout<<"A - B= "<<(a-b)<<endl;
 cout<<"  A=  "<<a<<endl;
 cout<<" A++  "<<a++<<endl;
 cout<<" ++A  "<<++a<<endl;
 cout<<" A--  "<<a--<<endl;
 cout<<" --A  "<<--a<<endl;

 
*/
}

Comentarii

Postări populare de pe acest blog

WINDOWS 10 COMPUTER FREEZING PROBLEM SOLVED

good news : a BIOS UPDATE can resolve the problem but just for a Windows 7 on 64 bits o.s. and the system is not stable all the time. even after  bios update the system can freeze.
new info : u can try to low the screen brightness and see if this error appear so often after 
news: last info !!! maybe a virus. scann our system now with an antivirus i generate this error using other device ( a tablet pc) connected in the same network and the laptop i have this problem just freeze  http://thehackernews.com/2013/10/backdoor-found-in-chinese-tenda.html

news : if u use a tenda router this make couse all this problems



what i discover so far :
1.the electric company have many failure and affect the main ISP router/switch for building  also the router/switch installed by the ISP may be affected by overheating and will crash after a long utilisation on heat conditions 2.the router/switch of ISP affect any router of the user between this router and pc/laptop of client 3.the router and any other device of t…

o aplicatie php localitati romania

//APLICATIA SE REFERA LA BAZA DE DATE SIRUTA

//dragtable.js


/* dragtable v1.0 June 26, 2008 Dan Vanderkam, http://danvk.org/dragtable/ http://code.google.com/p/dragtable/ \Bsortabledraggable\B Instructions: - Download this file - Add <script src="dragtable.js"></script> to your HTML. - Add class="draggable" to any table you might like to reorder. - Drag the headers around to reorder them. This is code was based on: - Stuart Langridge's SortTable (kryogenix.org/code/browser/sorttable) - Mike Hall's draggable class (http://www.brainjar.com/dhtml/drag/) - A discussion of permuting table columns on comp.lang.javascript Licensed under the MIT license. */ // Here's the notice from Mike Hall's draggable script: //***************************************************************************** // Do not remove this notice. // // Copyright 2001 by Mike Hall. // See http…