Guest User

Untitled

a guest
Jan 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. // Bart³omiej Kozyra
  2.  
  3.  
  4. #include <iostream>
  5. #include <cstdlib>
  6. #include <cmath>
  7. #include <sstream>
  8. using namespace std;
  9.  
  10. class NapBon {
  11. public:
  12. double x;
  13.  
  14. NapBon (double arg = 0) {
  15. if(arg < 0){
  16. cout << "!!!";
  17. x = 0;
  18. }
  19. else if(arg > 157){
  20. cout << "!!!";
  21. x = 157;
  22. }
  23. else {
  24. x = arg;
  25. }
  26. }
  27.  
  28. friend ostream& operator<<(ostream& out, NapBon arg){
  29. out << arg.x;
  30. return out;
  31. }
  32.  
  33. friend istream& operator>>(istream& in, NapBon& arg){
  34. in >> arg.x;
  35.  
  36. if(arg.x < 0){
  37. cout << "!!!";
  38. arg.x = 0;
  39. }
  40. else if (arg.x > 157){
  41. cout << "!!!";
  42. arg.x = 157;
  43. }
  44. return in;
  45.  
  46. }
  47.  
  48. friend NapBon operator+(NapBon left, NapBon right){
  49. NapBon arg;
  50. if((left.x + right.x) > 157){
  51. cout << "!!!";
  52. arg.x = 157;
  53. }
  54. else{
  55. arg.x = left.x + right.x;
  56. }
  57. return arg;
  58. }
  59.  
  60. friend NapBon operator-(NapBon left, NapBon right){
  61. NapBon arg;
  62. if((left.x - right.x) < 0){
  63. cout << "!!!";
  64. arg.x = 0;
  65. }
  66. else{
  67. arg.x = left.x - right.x;
  68. }
  69. return arg;
  70. }
  71.  
  72. friend NapBon operator*(NapBon left, NapBon right){
  73. NapBon arg;
  74. if((left.x * right.x) > 157){
  75. cout << "!!!";
  76. arg.x = 157;
  77. }
  78. else{
  79. arg.x = left.x * right.x;
  80. }
  81. return arg;
  82. }
  83.  
  84. friend NapBon operator/(NapBon left, NapBon right){
  85. NapBon arg;
  86. if((left.x / right.x) > 157){
  87. cout << "!!!";
  88. arg.x = 157;
  89. }
  90. else{
  91. arg.x = left.x / right.x;
  92. }
  93. return arg;
  94. }
  95.  
  96.  
  97. NapBon operator+(){
  98. return *this;
  99. }
  100. NapBon operator-(){
  101. NapBon arg(0);
  102. cout << "!!!";
  103. return arg;
  104. }
  105.  
  106. NapBon operator++(){
  107. if(x == 157){
  108. cout << "!!!";
  109. }
  110. else{
  111. x += 1.0;
  112. }
  113. return *this;
  114. }
  115.  
  116. NapBon operator--(){
  117. if(x == 0){
  118. cout << "!!!";
  119. }
  120. else{
  121. x -= 1.0;
  122. }
  123. return *this;
  124. }
  125.  
  126. NapBon operator++(int){
  127. NapBon arg(x);
  128. if(x == 157){
  129. cout<< "!!!";
  130. }
  131. else {
  132. x += 1.0;
  133. }
  134.  
  135. return arg;
  136. }
  137.  
  138. NapBon operator--(int){
  139. NapBon arg(x);
  140. if(x == 0){
  141. cout<< "!!!";
  142. }
  143. else {
  144. x -= 1.0;
  145. }
  146.  
  147. return arg;
  148. }
  149.  
  150. NapBon& operator=(const NapBon& arg){
  151. x = arg.x;
  152. return *this;
  153. }
  154.  
  155. NapBon operator+=(NapBon arg){
  156. if((x + arg.x) > 157){
  157. cout << "!!!";
  158. x = 157;
  159. }
  160. else{
  161. x = x + arg.x;
  162. }
  163. return *this;
  164. }
  165.  
  166. NapBon operator-=(NapBon arg){
  167. if((x - arg.x) < 0){
  168. cout << "!!!";
  169. x = 0;
  170. }
  171. else{
  172. x = x - arg.x;
  173. }
  174. return *this;
  175. }
  176.  
  177. NapBon operator*=(NapBon arg){
  178. if((x * arg.x) > 157){
  179. cout << "!!!";
  180. x = 157;
  181. }
  182. else{
  183. x = x * arg.x;
  184. }
  185. return *this;
  186. }
  187.  
  188. NapBon operator/=(NapBon arg){
  189.  
  190. if((x / arg.x) > 157){
  191. cout << "!!!";
  192. x = 157;
  193. }
  194. else{
  195. x = x / arg.x;
  196. }
  197. return *this;
  198. }
  199.  
  200. bool operator==(NapBon arg){
  201. if(x == arg.x)
  202. return true;
  203. else
  204. return false;
  205. }
  206.  
  207. bool operator!=(NapBon arg){
  208. if(x != arg.x)
  209. return true;
  210. else
  211. return false;
  212. }
  213.  
  214. bool operator>=(NapBon arg){
  215. if(x >= arg.x)
  216. return true;
  217. else
  218. return false;
  219. }
  220.  
  221. bool operator<=(NapBon arg){
  222. if(x <= arg.x)
  223. return true;
  224. else
  225. return false;
  226. }
  227.  
  228. bool operator<(NapBon arg){
  229. if(x < arg.x)
  230. return true;
  231. else
  232. return false;
  233. }
  234.  
  235.  
  236. bool operator>(NapBon arg){
  237. if(x > arg.x)
  238. return true;
  239. else
  240. return false;
  241. }
  242. };
  243.  
  244. string kampania(NapBon x1, NapBon y1, NapBon x2, NapBon y2){
  245.  
  246. a = (x2 - y2) / (x1 - y1);
  247. b = ((x1 * y2) - (x2 * y1)) / (x1 - y1);
  248.  
  249. double tmp = a * 100.0 + 0.5;
  250. a = floor(tmp) / 100.0;
  251.  
  252. double tmp2 = b * 100.0 + 0.5;
  253. b = floor(tmp2) / 100.0;
  254.  
  255. if(a >= 0 && a <= 157 && b >= 0 && b <= 157 ){
  256. //{(a,b)};
  257. double a,b;
  258.  
  259. ostringstream ss;
  260. ss << "{" << "(" << a << "," << b << ")" << "}";
  261. string str = ss.str();
  262.  
  263. return str;
  264. }
  265. else{
  266. // {}
  267. double a,b;
  268.  
  269. ostringstream ss;
  270. ss << "{" << "}";
  271. string str = ss.str();
  272.  
  273. return str;
  274. }
  275.  
  276. }
Add Comment
Please, Sign In to add comment