Advertisement
Djurex4u

Untitled

Oct 18th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. ///prvi
  2. #include <iostream>
  3. #include <stdlib.h>
  4. using namespace std;
  5.  
  6. class Die
  7. {
  8. private:
  9. int value;
  10. public:
  11. Die();
  12. Die(int x);
  13. void set(int x)
  14. {
  15. value = x;
  16.  
  17. }
  18. int access(void)
  19. {
  20. return value;
  21. }
  22. int roll(void)
  23. {
  24. return rand() % 6 + 1;
  25. }
  26.  
  27. };
  28. void jamb(Die polje[])
  29. {
  30. int br = 1 , i;
  31. for (i = 0; i < 5; i++)
  32. {
  33. if (polje[i].access() == polje[i + 1].access())
  34. br++;
  35.  
  36. }
  37. if (br == 5)
  38. cout << "jamb je bacen"<<endl;
  39. else
  40. cout << "nije bacen"<<endl;
  41. }
  42.  
  43. Die::Die()
  44. {
  45. value = 0;
  46. }
  47.  
  48. Die::Die(int x)
  49. {
  50. value = x;
  51. }
  52.  
  53. int main()
  54. {
  55. int i;
  56. Die polje[5];
  57. for (i = 0; i<5; i++)
  58. {
  59. polje[i].set(polje[i].roll());
  60.  
  61. }
  62. for (i = 0; i < 5; i++)
  63. {
  64. cout << polje[i].access()<<endl;
  65. }
  66. jamb(polje);
  67.  
  68.  
  69. return 0;
  70. }
  71.  
  72.  
  73. ///drugi
  74. #include <iostream>
  75. #include <math.h>
  76. using namespace std;
  77.  
  78. class Complex
  79. {
  80. friend Complex sum(Complex &x, Complex &y)
  81. {
  82. Complex z(x.real_part + y.real_part, x.imaginary_part + y.imaginary_part);
  83. return z;
  84. }
  85. private:
  86. float real_part;
  87. float imaginary_part;
  88. public:
  89. Complex();
  90. Complex(float x, float y);
  91. float access_real()
  92. {
  93. return real_part;
  94. }
  95. float access_imaginary()
  96. {
  97. return imaginary_part;
  98. }
  99. float abs(void)
  100. {
  101. return sqrt(pow(real_part,2) + pow(imaginary_part,2));
  102. }
  103. };
  104.  
  105. Complex::Complex()
  106. {
  107. real_part = 0;
  108. imaginary_part = 0;
  109. }
  110.  
  111. Complex::Complex(float x,float y)
  112. {
  113. real_part = x;
  114. imaginary_part = y;
  115. }
  116.  
  117. int main()
  118. {
  119. Complex z1(2,3);
  120. Complex z2(4,-2);
  121. Complex z3;
  122. z3 = sum(z1, z2);
  123. cout <<z3.access_real() << endl;
  124. cout << z3.access_imaginary() << endl;
  125. cout << z3.abs() << endl;
  126.  
  127. return 0;
  128. }
  129.  
  130.  
  131. //treci
  132. #include <iostream>
  133. using namespace std;
  134.  
  135. class Point2D
  136. {
  137. private:
  138. int xCor;
  139. int yCor;
  140. public:
  141. Point2D();
  142. Point2D(int x, int y);
  143. int accessX(void)
  144. {
  145. return xCor;
  146. }
  147. int accessY(void)
  148. {
  149. return yCor;
  150. }
  151. void setCor(int x, int y)
  152. {
  153. xCor = x;
  154. yCor = y;
  155. }
  156. };
  157.  
  158. class Line
  159. {
  160. private:
  161. Point2D dot1;
  162. Point2D dot2;
  163. public:
  164. Line(Point2D T1, Point2D T2);
  165.  
  166. void changeDot1(int x, int y)
  167. {
  168. dot1.setCor(x, y);
  169. }
  170.  
  171. void changeDot2(int x, int y)
  172. {
  173. dot2.setCor(x, y);
  174. }
  175.  
  176. void ispis(void)
  177. {
  178. cout << "T1(" << dot1.accessX() <<","<< dot1.accessY() << ")" << endl;
  179. cout << "T2(" << dot2.accessX() <<"," << dot2.accessY() << ")" << endl;
  180. }
  181. };
  182.  
  183. Point2D::Point2D()
  184. {
  185. xCor = 1;
  186. yCor = 1;
  187. }
  188. Point2D::Point2D(int x, int y)
  189. {
  190. xCor = x;
  191. yCor = y;
  192. }
  193.  
  194. Line::Line(Point2D T1, Point2D T2)
  195. {
  196. dot1 = T1;
  197. dot2 = T2;
  198. }
  199.  
  200. int main()
  201. {
  202. Point2D Tocka1;
  203. Point2D Tocka2;
  204. Line pravac(Tocka1,Tocka2);
  205. pravac.ispis();
  206. pravac.changeDot1(2, 3);
  207. pravac.changeDot2(3, 4);
  208. pravac.ispis();
  209.  
  210. return 0;
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement