Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class MnozenjeNaBroeviSoP_Z
- {
- protected:
- double manti;
- int EKPO;
- public:
- MnozenjeNaBroeviSoP_Z()
- {
- manti=0;
- EKPO=0;
- }
- MnozenjeNaBroeviSoP_Z(int BROJ)
- {
- manti = BROJ;
- sredi_normal();
- }
- void setMantisa(double Mantisa)
- {
- manti = Mantisa;
- }
- double getMantisa(void) const
- {
- return manti;
- }
- void setEKPO(int Ekspo)
- {
- EKPO = Ekspo;
- }
- int getEKPO(void) const
- {
- return EKPO;
- }
- void sredi_normal()
- {
- if(manti >= 2)
- {
- while(manti >= 2)
- {
- manti = manti / 2;
- EKPO = EKPO + 1;
- }
- }
- else
- {
- while(manti < 1)
- {
- manti = manti * 2;
- EKPO = EKPO - 1;
- }
- }
- }
- MnozenjeNaBroeviSoP_Z operator*(MnozenjeNaBroeviSoP_Z & Vrednost)
- {
- MnozenjeNaBroeviSoP_Z tmp;
- tmp.setMantisa(getMantisa() * Vrednost.getMantisa());
- tmp.setEKPO(getEKPO() + Vrednost.getEKPO());
- tmp.sredi_normal();
- return tmp;
- }
- void Postavi(int br)
- {
- manti = br;
- sredi_normal();
- }
- void MnozenjeNaBroeviSoP_Z::operator =(int b)
- {
- setMantisa(b);
- sredi_normal();
- }
- void Pecati(void)
- {
- sredi_normal();
- if(manti >= 1)
- {
- cout << "1,";
- manti = manti - 1;
- }
- int i=0;
- for(i=0;i<20;i++)
- {
- if(manti==0)
- {
- for(int i=0;i<20;i++) cout << "0" ;
- break;
- }
- manti = manti * 2;
- if(manti>=1)
- {
- cout << "1";
- manti = manti - 1;
- }
- else
- {
- cout << "0";
- }
- }
- cout << " * 2^" << EKPO << endl;
- }
- void MnozenjeNaBroeviSoP_Z::operator =(MnozenjeNaBroeviSoP_Z & Vrednost)
- {
- manti = Vrednost.getMantisa();
- EKPO = Vrednost.getEKPO();
- }
- };
- int main()
- {
- int Broj_1=0,Broj_2=0;
- cout<<" (: :) Dobre dojdovte vo programata za mnozenje na broevi so podvizna zapirka!!! (: :)"<<endl;
- cout<<endl;
- cout<<"Vnesi go broj 1 = ";
- cin>>Broj_1;
- cout<<"Vnesi go broj 2 = ";
- cin>>Broj_2;
- MnozenjeNaBroeviSoP_Z resenie;
- resenie=Broj_1*Broj_2;
- resenie.Pecati();
- system ("pause");
- }#include <iostream>
- using namespace std;
- class MnozenjeNaBroeviSoP_Z
- {
- protected:
- double manti;
- int EKPO;
- public:
- MnozenjeNaBroeviSoP_Z()
- {
- manti=0;
- EKPO=0;
- }
- MnozenjeNaBroeviSoP_Z(int BROJ)
- {
- manti = BROJ;
- sredi_normal();
- }
- void setMantisa(double Mantisa)
- {
- manti = Mantisa;
- }
- double getMantisa(void) const
- {
- return manti;
- }
- void setEKPO(int Ekspo)
- {
- EKPO = Ekspo;
- }
- int getEKPO(void) const
- {
- return EKPO;
- }
- void sredi_normal()
- {
- if(manti >= 2)
- {
- while(manti >= 2)
- {
- manti = manti / 2;
- EKPO = EKPO + 1;
- }
- }
- else
- {
- while(manti < 1)
- {
- manti = manti * 2;
- EKPO = EKPO - 1;
- }
- }
- }
- MnozenjeNaBroeviSoP_Z operator*(MnozenjeNaBroeviSoP_Z & Vrednost)
- {
- MnozenjeNaBroeviSoP_Z tmp;
- tmp.setMantisa(getMantisa() * Vrednost.getMantisa());
- tmp.setEKPO(getEKPO() + Vrednost.getEKPO());
- tmp.sredi_normal();
- return tmp;
- }
- void Postavi(int br)
- {
- manti = br;
- sredi_normal();
- }
- void MnozenjeNaBroeviSoP_Z::operator =(int b)
- {
- setMantisa(b);
- sredi_normal();
- }
- void Pecati(void)
- {
- sredi_normal();
- if(manti >= 1)
- {
- cout << "1,";
- manti = manti - 1;
- }
- int i=0;
- for(i=0;i<20;i++)
- {
- if(manti==0)
- {
- for(int i=0;i<20;i++) cout << "0" ;
- break;
- }
- manti = manti * 2;
- if(manti>=1)
- {
- cout << "1";
- manti = manti - 1;
- }
- else
- {
- cout << "0";
- }
- }
- cout << " * 2^" << EKPO << endl;
- }
- void MnozenjeNaBroeviSoP_Z::operator =(MnozenjeNaBroeviSoP_Z & Vrednost)
- {
- manti = Vrednost.getMantisa();
- EKPO = Vrednost.getEKPO();
- }
- };
- int main()
- {
- int Broj_1=0,Broj_2=0;
- cout<<" (: :) Dobre dojdovte vo programata za mnozenje na broevi so podvizna zapirka!!! (: :)"<<endl;
- cout<<endl;
- cout<<"Vnesi go broj 1 = ";
- cin>>Broj_1;
- cout<<"Vnesi go broj 2 = ";
- cin>>Broj_2;
- MnozenjeNaBroeviSoP_Z resenie;
- resenie=Broj_1*Broj_2;
- resenie.Pecati();
- system ("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement