Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <windows.h>
- #include <conio.h>
- using namespace std;
- class BigInt
- {
- private:
- int *numar,lungime_sir;
- public:
- BigInt();
- BigInt(BigInt &c);
- BigInt(BigInt &c,int v[],int lg);
- ~BigInt();
- BigInt& operator = (const BigInt&a);
- friend istream & operator >>(istream&is,BigInt &r);
- friend ostream & operator <<(ostream&os,BigInt &r);
- friend BigInt operator + (BigInt a,BigInt b);
- friend BigInt operator - (BigInt a,BigInt b);
- friend BigInt operator * (BigInt a,BigInt b);
- friend int compara(BigInt a, BigInt b);
- friend bool operator > (BigInt a,BigInt b);
- friend bool operator < (BigInt a,BigInt b);
- friend bool par(BigInt a);
- };
- BigInt::BigInt()
- {
- lungime_sir=0;
- numar=NULL;
- }
- BigInt::BigInt(BigInt &c)
- {
- lungime_sir=c.lungime_sir;
- numar=new int[lungime_sir];
- for(int i=0; i<lungime_sir; i++)
- numar[i]=c.numar[i];
- }
- BigInt::BigInt(BigInt &c,int v[],int lg)
- {
- c.lungime_sir=lg;
- c.numar=new int[c.lungime_sir];
- for(int i=0; i<lg; i++)
- c.numar[i]=v[i];
- }
- BigInt::~BigInt()
- {
- delete numar;
- }
- BigInt& BigInt::operator = (const BigInt&a)
- {
- int i;
- lungime_sir=a.lungime_sir;
- numar=new int[lungime_sir];
- for(i=0; i<lungime_sir; i++)
- numar[i]=a.numar[i];
- }
- istream & operator >>(istream & is,BigInt & r)
- {
- char sir[256];
- is.getline(sir,256);
- r.lungime_sir=strlen(sir);
- r.numar=new int[r.lungime_sir];
- for(int i=0; i<strlen(sir); i++)
- r.numar[i]=sir[strlen(sir)-1-i]-48;
- return is;
- }
- ostream & operator <<(ostream & os,BigInt & r)
- {
- for(int i=r.lungime_sir-1; i>=0; i--)
- os<<r.numar[i];
- return os;
- }
- BigInt operator + (BigInt a,BigInt b)
- {
- BigInt c;
- int i, t=0,v[256],lungime_sir;
- lungime_sir=max(a.lungime_sir,b.lungime_sir);
- for(i=0;i<lungime_sir;i++)
- {
- if(a.numar[i]>9 || a.numar[i]<0)
- a.numar[i]=0;
- if(b.numar[i]>9 || b.numar[i]<0)
- b.numar[i]=0;
- }
- for(i=0; i<lungime_sir; ++i)
- {
- v[i]=a.numar[i]+b.numar[i]+t;
- t=v[i]/10;
- v[i]=v[i]%10;
- }
- if(t)
- v[lungime_sir++]=t;
- BigInt(c,v,lungime_sir);
- return c;
- }
- BigInt operator - (BigInt a,BigInt b)
- {
- BigInt c;
- int i, t=0,dif[256],lungime_sir;
- for(i=0; i<256; i++)
- dif[i]=0;
- for(i=0; i<a.lungime_sir; i++)
- dif[i]=a.numar[i];
- for(i=0; i<b.lungime_sir; ++i)
- {
- dif[i]=dif[i]-b.numar[i]+t;
- if(dif[i]<0)
- {
- dif[i]=dif[i]+10;
- t=-1;
- }
- else
- t=0;
- }
- i=a.lungime_sir;
- while(i>1 && dif[i]==0)
- i--;
- lungime_sir=i;
- BigInt(c,dif,lungime_sir);
- return c;
- }
- BigInt operator * (BigInt a,BigInt b)
- {
- BigInt c;
- int i,j,t,v[256],lungime_sir;
- for(i=0; i<256; i++)
- v[i]=0;
- for(i=0; i<a.lungime_sir; ++i)
- {
- t=0;
- for(j=0; j<b.lungime_sir; ++j)
- {
- v[i+j]=v[i+j]+a.numar[i]*b.numar[j]+t;
- t=v[i+j]/10;
- v[i+j]=v[i+j]%10;
- }
- if(t)
- v[i+j]=t;
- }
- lungime_sir=a.lungime_sir+b.lungime_sir;
- if(v[lungime_sir]==0)
- lungime_sir--;
- BigInt(c,v,lungime_sir);
- return c;
- }
- int compara(BigInt a, BigInt b)
- {
- int i;
- if(a.lungime_sir<b.lungime_sir)
- return -1;
- if(b.lungime_sir<a.lungime_sir)
- return 1;
- for(i=0; i<a.lungime_sir; ++i)
- if(a.numar[i]<b.numar[i])
- return -1;
- else if(a.numar[i]>b.numar[i])
- return 1;
- return 0;
- }
- bool operator > (BigInt a,BigInt b)
- {
- return compara(a,b)>0;
- }
- bool operator < (BigInt a,BigInt b)
- {
- return compara(a,b)<0;
- }
- bool par(BigInt a)
- {
- if(a.numar[0]%2)
- return true;
- return false;
- }
- void menu()
- {
- system("cls");
- cout<<"\n\n Clasa Numere Mari \n";
- cout<<"\n\t1. Citire numere \n";
- cout<<"\n\t2. Afisare numere \n";
- cout<<"\n\t3. Suma \n";
- cout<<"\n\t4. Diferenta \n";
- cout<<"\n\t5. Inmultire \n";
- cout<<"\n\t6. Paritate \n";
- cout<<"\n\t7. Comparare \n";
- //cout<<"\n\t8. Copiere \n";
- cout<<"\n\t0. Exit\n";
- //getch();
- }
- int main()
- {
- BigInt a,b,c;
- int op;
- while(1)
- {
- menu();
- cout<<"\n\tOptiunea Dumneavoastra: ";
- //getch();
- cin>>op;
- cin.get();
- switch(op)
- {
- case 0:
- return 0;
- case 1:
- cin>>a>>b;
- //getch();
- break;
- case 2:
- cout<<'\n';
- cout<<a<<' '<<b;
- getch();
- break;
- case 3:
- c=a+b;
- cout<<'\n';
- cout<<c;
- getch();
- break;
- case 4:
- if(a>b)
- {
- c=a-b;
- cout<<'\n';
- cout<<c;
- }
- else
- {
- c=b-a;
- cout<<'\n';
- cout<<'-'<<c;
- }
- getch();
- break;
- case 5:
- c=a*b;
- cout<<'\n';
- cout<<c;
- getch();
- break;
- case 6:
- cout<<'\n';
- if(!par(a))
- cout<<"primul numar este par";
- else
- cout<<"primul numar este impar";
- cout<<'\n';
- if(!par(b))
- cout<<"al doilea numar numar este par";
- else
- cout<<"al doilea numar este impar";
- getch();
- break;
- case 7:
- cout<<'\n';
- if(a > b)
- cout<<"primul numar este mai mare ca al doilea";
- else
- {
- if(a < b)
- cout<<"al doilea numar este mai mare ca primul";
- else
- cout<<"numerele sunt egale";
- }
- getch();
- break;
- case 8:
- system("cls");
- cout<<" ---- ---- -------- ------------ ---- ---- ------------ ------ ----------- ------ ------------ -------- ---- ---- ------ \n";
- cout<<" ***** **** ******** ************ **** **** ************ ******** ************ ******** ************ ******** ***** **** ******** \n";
- cout<<" ------ ---- ---- --- ---- ---- --- ---------- --- --- ---------- ------------ ---- ------ ---- ---------- \n";
- cout<<" ************ **** *** **** **** *** **** **** ************ **** **** **** **** ************ **** **** \n";
- cout<<" ------------ ---- --- ---- ---- --- ------------ ----------- ------------ ---- ---- ------------ ------------ \n";
- cout<<" **** ****** **** *** ************ *** ************ **** ************ **** **** **** ****** ************ \n";
- cout<<" ---- ----- -------- ------------ ------------ ------------ ---- ---- ---- ---- ---- ---- -------- ---- ----- ---- ---- \n";
- cout<<" **** **** ******** ************ ************ ************ **** **** **** **** **** **** ******** **** **** **** **** \n";
- getch();
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement