Advertisement
moni_qwerty

Untitled

Apr 11th, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class MnozenjeNaBroeviSoP_Z
  5. {
  6. protected:
  7. double manti;
  8. int EKPO;
  9. public:
  10. MnozenjeNaBroeviSoP_Z()
  11. {
  12. manti=0;
  13. EKPO=0;
  14. }
  15. MnozenjeNaBroeviSoP_Z(int BROJ)
  16. {
  17. manti = BROJ;
  18. sredi_normal();
  19. }
  20. void setMantisa(double Mantisa)
  21. {
  22. manti = Mantisa;
  23. }
  24. double getMantisa(void) const
  25. {
  26. return manti;
  27. }
  28. void setEKPO(int Ekspo)
  29. {
  30. EKPO = Ekspo;
  31. }
  32. int getEKPO(void) const
  33. {
  34. return EKPO;
  35. }
  36. void sredi_normal()
  37. {
  38. if(manti >= 2)
  39. {
  40. while(manti >= 2)
  41. {
  42. manti = manti / 2;
  43. EKPO = EKPO + 1;
  44. }
  45. }
  46. else
  47. {
  48. while(manti < 1)
  49. {
  50. manti = manti * 2;
  51. EKPO = EKPO - 1;
  52. }
  53. }
  54. }
  55. MnozenjeNaBroeviSoP_Z operator*(MnozenjeNaBroeviSoP_Z & Vrednost)
  56. {
  57. MnozenjeNaBroeviSoP_Z tmp;
  58. tmp.setMantisa(getMantisa() * Vrednost.getMantisa());
  59. tmp.setEKPO(getEKPO() + Vrednost.getEKPO());
  60. tmp.sredi_normal();
  61. return tmp;
  62. }
  63. void Postavi(int br)
  64. {
  65. manti = br;
  66. sredi_normal();
  67. }
  68. void MnozenjeNaBroeviSoP_Z::operator =(int b)
  69. {
  70. setMantisa(b);
  71. sredi_normal();
  72. }
  73. void Pecati(void)
  74. {
  75. sredi_normal();
  76. if(manti >= 1)
  77. {
  78. cout << "1,";
  79. manti = manti - 1;
  80. }
  81. int i=0;
  82. for(i=0;i<20;i++)
  83. {
  84. if(manti==0)
  85. {
  86. for(int i=0;i<20;i++) cout << "0" ;
  87. break;
  88. }
  89. manti = manti * 2;
  90. if(manti>=1)
  91. {
  92. cout << "1";
  93. manti = manti - 1;
  94. }
  95. else
  96. {
  97. cout << "0";
  98. }
  99.  
  100. }
  101. cout << " * 2^" << EKPO << endl;
  102. }
  103.  
  104. void MnozenjeNaBroeviSoP_Z::operator =(MnozenjeNaBroeviSoP_Z & Vrednost)
  105. {
  106. manti = Vrednost.getMantisa();
  107. EKPO = Vrednost.getEKPO();
  108. }
  109. };
  110.  
  111. int main()
  112. {
  113. int Broj_1=0,Broj_2=0;
  114. cout<<" (: :) Dobre dojdovte vo programata za mnozenje na broevi so podvizna zapirka!!! (: :)"<<endl;
  115. cout<<endl;
  116. cout<<"Vnesi go broj 1 = ";
  117. cin>>Broj_1;
  118. cout<<"Vnesi go broj 2 = ";
  119. cin>>Broj_2;
  120. MnozenjeNaBroeviSoP_Z resenie;
  121. resenie=Broj_1*Broj_2;
  122. resenie.Pecati();
  123. system ("pause");
  124. }#include <iostream>
  125. using namespace std;
  126.  
  127. class MnozenjeNaBroeviSoP_Z
  128. {
  129. protected:
  130. double manti;
  131. int EKPO;
  132. public:
  133. MnozenjeNaBroeviSoP_Z()
  134. {
  135. manti=0;
  136. EKPO=0;
  137. }
  138. MnozenjeNaBroeviSoP_Z(int BROJ)
  139. {
  140. manti = BROJ;
  141. sredi_normal();
  142. }
  143. void setMantisa(double Mantisa)
  144. {
  145. manti = Mantisa;
  146. }
  147. double getMantisa(void) const
  148. {
  149. return manti;
  150. }
  151. void setEKPO(int Ekspo)
  152. {
  153. EKPO = Ekspo;
  154. }
  155. int getEKPO(void) const
  156. {
  157. return EKPO;
  158. }
  159. void sredi_normal()
  160. {
  161. if(manti >= 2)
  162. {
  163. while(manti >= 2)
  164. {
  165. manti = manti / 2;
  166. EKPO = EKPO + 1;
  167. }
  168. }
  169. else
  170. {
  171. while(manti < 1)
  172. {
  173. manti = manti * 2;
  174. EKPO = EKPO - 1;
  175. }
  176. }
  177. }
  178. MnozenjeNaBroeviSoP_Z operator*(MnozenjeNaBroeviSoP_Z & Vrednost)
  179. {
  180. MnozenjeNaBroeviSoP_Z tmp;
  181. tmp.setMantisa(getMantisa() * Vrednost.getMantisa());
  182. tmp.setEKPO(getEKPO() + Vrednost.getEKPO());
  183. tmp.sredi_normal();
  184. return tmp;
  185. }
  186. void Postavi(int br)
  187. {
  188. manti = br;
  189. sredi_normal();
  190. }
  191. void MnozenjeNaBroeviSoP_Z::operator =(int b)
  192. {
  193. setMantisa(b);
  194. sredi_normal();
  195. }
  196. void Pecati(void)
  197. {
  198. sredi_normal();
  199. if(manti >= 1)
  200. {
  201. cout << "1,";
  202. manti = manti - 1;
  203. }
  204. int i=0;
  205. for(i=0;i<20;i++)
  206. {
  207. if(manti==0)
  208. {
  209. for(int i=0;i<20;i++) cout << "0" ;
  210. break;
  211. }
  212. manti = manti * 2;
  213. if(manti>=1)
  214. {
  215. cout << "1";
  216. manti = manti - 1;
  217. }
  218. else
  219. {
  220. cout << "0";
  221. }
  222.  
  223. }
  224. cout << " * 2^" << EKPO << endl;
  225. }
  226.  
  227. void MnozenjeNaBroeviSoP_Z::operator =(MnozenjeNaBroeviSoP_Z & Vrednost)
  228. {
  229. manti = Vrednost.getMantisa();
  230. EKPO = Vrednost.getEKPO();
  231. }
  232. };
  233.  
  234. int main()
  235. {
  236. int Broj_1=0,Broj_2=0;
  237. cout<<" (: :) Dobre dojdovte vo programata za mnozenje na broevi so podvizna zapirka!!! (: :)"<<endl;
  238. cout<<endl;
  239. cout<<"Vnesi go broj 1 = ";
  240. cin>>Broj_1;
  241. cout<<"Vnesi go broj 2 = ";
  242. cin>>Broj_2;
  243. MnozenjeNaBroeviSoP_Z resenie;
  244. resenie=Broj_1*Broj_2;
  245. resenie.Pecati();
  246. system ("pause");
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement