fork download
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <math.h>
  5. #include <malloc.h>
  6. #include <memory.h>
  7. #include <string>
  8.  
  9. using namespace std;
  10. class vector
  11. {
  12. public:
  13. //Указатель на double
  14. double *a;
  15. //Колличество элементов
  16. int size; //Передаваемый размер
  17. int size_vec; //Записываемый размер, важно для print_vector ибо не выходит за рамки массива
  18. //Переменная состояния
  19. int condition;
  20. public:
  21. vector()
  22. {
  23. size_vec = 1;
  24. a = new double(0);
  25. if(a[0] != NULL)
  26. {
  27. condition = 0; //Переполнения памяти нет
  28. }
  29. }
  30. vector(int size)
  31. {
  32. size_vec = size;
  33. a = new double[size_vec];
  34. if(a[size_vec] != NULL)
  35. {
  36. condition = 0; //Переполнения памяти нет
  37. } else
  38. {
  39. condition = 1;
  40. cout << "Perepoln pamyati" << endl;
  41. }
  42. for(int i = 0; i < size_vec; i++)
  43. {
  44. a[i] = size_vec;
  45. }
  46. }
  47. vector(int size, double p_double)
  48. {
  49. size_vec = size;
  50. a = new double[size_vec];
  51. if(a[size_vec] != NULL)
  52. {
  53. condition = 0; //Переполнения памяти нет
  54. } else
  55. {
  56. condition = 1;
  57. cout << "Perepoln pamyati" << endl;
  58. }
  59. for(int i = 0; i <= size_vec; i++)
  60. {
  61. a[i] = p_double;
  62. }
  63. }
  64. vector(vector &V1, char sign, vector &V2) //Вектор являющийся результатом арифметических действий
  65. {
  66. if (sign == '+' or sign == '-' or sign == '*')
  67. {
  68. if (V1.size_vec > V2.size_vec)
  69. {
  70. switch(sign)
  71. {
  72. case '*':
  73. size = 1;
  74. size_vec = size;
  75. a = new double(0);
  76. if(a[size_vec] != NULL)
  77. {
  78. condition = 0; //Переполнения памяти нет
  79. } else
  80. {
  81. condition = 1;
  82. cout << "Perepoln pamyati" << endl;
  83. }
  84. for(int i = 0; i < V1.size_vec; i++)
  85. {
  86. if(i < V2.size_vec)
  87. {
  88. a[0] = a[0] + V1.a[i] * V2.a[i];
  89. }
  90. }
  91. break;
  92.  
  93. case '+':
  94. size = V1.size_vec;
  95. size_vec = size;
  96. a = new double[size_vec];
  97. if(a[size_vec] != NULL)
  98. {
  99. condition = 0; //Переполнения памяти нет
  100. } else
  101. {
  102. condition = 1;
  103. cout << "Perepoln pamyati" << endl;
  104. }
  105. for(int i = 0; i < size_vec; i++)
  106. {
  107. if(i < V2.size_vec)
  108. {
  109. a[i] = V1.a[i] + V2.a[i];
  110. } else
  111. {
  112. a[i] = V1.a[i];
  113. }
  114. }
  115. break;
  116.  
  117. case '-':
  118. size = V1.size_vec;
  119. size_vec = size;
  120. a = new double[size_vec];
  121. if(a[size_vec] != NULL)
  122. {
  123. condition = 0; //Переполнения памяти нет
  124. } else
  125. {
  126. condition = 1;
  127. cout << "Perepoln pamyati" << endl;
  128. }
  129. for(int i = 0; i < size_vec; i++)
  130. {
  131. if(i < V2.size_vec)
  132. {
  133. a[i] = V1.a[i] - V2.a[i];
  134. } else
  135. {
  136. a[i] = V1.a[i];
  137. }
  138. }
  139. break;
  140. }
  141. } else
  142. {
  143. if (V1.size_vec < V2.size_vec)
  144. {
  145. switch(sign)
  146. {
  147. case '*':
  148. size = 1;
  149. size_vec = size;
  150. a = new double(0);
  151. if(a[size_vec] != NULL)
  152. {
  153. condition = 0; //Переполнения памяти нет
  154. } else
  155. {
  156. condition = 1;
  157. cout << "Perepoln pamyati" << endl;
  158. }
  159. for(int i = 0; i < V2.size_vec; i++)
  160. {
  161. if(i < V1.size_vec)
  162. {
  163. a[0] = a[0] + V1.a[i] * V2.a[i];
  164. }
  165. }
  166. break;
  167.  
  168. case '+':
  169. size = V2.size_vec;
  170. size_vec = size;
  171. a = new double[size_vec];
  172. if(a[size_vec] != NULL)
  173. {
  174. condition = 0; //Переполнения памяти нет
  175. } else
  176. {
  177. condition = 1;
  178. cout << "Perepoln pamyati" << endl;
  179. }
  180. for(int i = 0; i < size_vec; i++)
  181. {
  182. if(i < V1.size_vec)
  183. {
  184. a[i] = V1.a[i] + V2.a[i];
  185. } else
  186. {
  187. a[i] = V2.a[i];
  188. }
  189. }
  190. break;
  191.  
  192. case '-':
  193. size = V2.size_vec;
  194. size_vec = size;
  195. a = new double[size_vec];
  196. if(a[size_vec] != NULL)
  197. {
  198. condition = 0; //Переполнения памяти нет
  199. } else
  200. {
  201. condition = 1;
  202. cout << "Perepoln pamyati" << endl;
  203. }
  204. for(int i = 0; i < size_vec; i++)
  205. {
  206. if(i < V1.size_vec)
  207. {
  208. a[i] = V1.a[i] - V2.a[i];
  209. } else
  210. {
  211. a[i] = V2.a[i];
  212. }
  213. }
  214. break;
  215. }
  216. } else //V1.size_vec == V2.size_vec
  217. {
  218. switch(sign)
  219. {
  220. case '*':
  221. size = 1;
  222. size_vec = size;
  223. a = new double(0);
  224. if(a[size_vec] != NULL)
  225. {
  226. condition = 0; //Переполнения памяти нет
  227. } else
  228. {
  229. condition = 1;
  230. cout << "Perepoln pamyati" << endl;
  231. }
  232. for(int i = 0; i < V1.size_vec; i++)
  233. {
  234. a[0] = a[0] + V1.a[i] * V2.a[i];
  235. }
  236. break;
  237.  
  238. case '+':
  239. size = V1.size_vec;
  240. size_vec = size;
  241. a = new double[size_vec];
  242. if(a[size_vec] != NULL)
  243. {
  244. condition = 0; //Переполнения памяти нет
  245. } else
  246. {
  247. condition = 1;
  248. cout << "Perepoln pamyati" << endl;
  249. }
  250. for(int i = 0; i < size_vec; i++)
  251. {
  252. a[i] = V1.a[i] + V2.a[i];
  253. }
  254. break;
  255.  
  256. case '-':
  257. size = V1.size_vec;
  258. size_vec = size;
  259. a = new double[size_vec];
  260. if(a[size_vec] != NULL)
  261. {
  262. condition = 0; //Переполнения памяти нет
  263. } else
  264. {
  265. condition = 1;
  266. cout << "Perepoln pamyati" << endl;
  267. }
  268. for(int i = 0; i < size_vec; i++)
  269. {
  270. a[i] = V1.a[i] - V2.a[i];
  271. }
  272. break;
  273. }
  274. }
  275. }
  276. } else
  277. {
  278. if (sign == '?') //Случайная операция
  279. {
  280.  
  281. }
  282. }
  283. }
  284. ~vector()
  285. {
  286. delete []a;
  287. size_vec = 0;
  288. }
  289. };//class vector
  290.  
  291. void rewrite_vector(vector &V, int numb = 0, int def = 0)
  292. {
  293. if (numb < V.size_vec and numb >= 0)
  294. {
  295. V.a[numb] = def;
  296. } else
  297. {
  298. cout << "Ukazanniy index vectora ne sushestvuet. Chislo ne bulo izmeneno." << endl;
  299. }
  300. }
  301.  
  302. void print_vector(vector &V, string text = "", string string_FirstVector = "", string string_SecondVector = "")
  303. {
  304. cout << "\n--- " << string_FirstVector << " " << text << " " << string_SecondVector << endl;
  305. for (int i = 0; i < V.size_vec; i++)
  306. cout << V.a[i] << " ";
  307. }
  308.  
  309. double get_num_vector(vector &V, int num)
  310. {
  311. if (num < V.size_vec and num >= 0)
  312. {
  313. return V.a[num];
  314. } else
  315. {
  316. cout << "Ukazanniy index vectora ne sushestvuet. Chislo ne bulo polucheno." << endl;
  317. }
  318. }
  319.  
  320. string eqv_vector(vector &V1, vector &V2, string string_FirstVector = "", string string_SecondVector = "")
  321. {
  322. if(V1.size_vec == V2.size_vec)
  323. {
  324. int i;
  325. for(i = 0; i < V1.size_vec; i++)
  326. {
  327. if(V1.a[i] != V2.a[i])
  328. break;
  329. }
  330. if(i != V1.size_vec)
  331. {
  332. cout << "\n---" << endl;
  333. cout << "Vectory " << string_FirstVector << " i " << string_SecondVector << " ne ravni" << endl;
  334. } else
  335. {
  336. cout << "\n---" << endl;
  337. cout << "Vectory " << string_FirstVector << " i " << string_SecondVector << " ravni" << endl;
  338. }
  339. } else
  340. {
  341. int tq = 0, tw = 0;
  342. for(int i = 0; i < V1.size_vec; i++)
  343. {
  344. tq = tq + V1.a[i]*V1.a[i];
  345. }
  346. for(int i = 0; i < V2.size_vec; i++)
  347. {
  348. tw = tw + V2.a[i]*V2.a[i];
  349. }
  350. tq = sqrt(tq);
  351. tw = sqrt(tw);
  352. if(tq > tw)
  353. {
  354. cout << "\n---" << endl;
  355. cout << "Vector " << string_FirstVector << " bolshe po dline chem vector " << string_SecondVector << endl;
  356. } else
  357. {
  358. if(tq < tw)
  359. {
  360. cout << "\n---" << endl;
  361. cout << "Vector " << string_FirstVector << " menshe po dline chem vector " << string_SecondVector << endl;
  362. } else
  363. {
  364. cout << "\n---" << endl;
  365. cout << "Vector " << string_FirstVector << " raven vectory " << string_SecondVector << endl;
  366. }
  367. }
  368. }
  369. }
  370.  
  371.  
  372. #endif
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:372:2: error: #endif without #if
 #endif
  ^~~~~
prog.cpp: In constructor ‘vector::vector()’:
prog.cpp:25:20: warning: NULL used in arithmetic [-Wpointer-arith]
         if(a[0] != NULL)
                    ^~~~
prog.cpp: In constructor ‘vector::vector(int)’:
prog.cpp:34:27: warning: NULL used in arithmetic [-Wpointer-arith]
         if(a[size_vec] != NULL)
                           ^~~~
prog.cpp: In constructor ‘vector::vector(int, double)’:
prog.cpp:51:27: warning: NULL used in arithmetic [-Wpointer-arith]
         if(a[size_vec] != NULL)
                           ^~~~
prog.cpp: In constructor ‘vector::vector(vector&, char, vector&)’:
prog.cpp:76:39: warning: NULL used in arithmetic [-Wpointer-arith]
                     if(a[size_vec] != NULL)
                                       ^~~~
prog.cpp:97:39: warning: NULL used in arithmetic [-Wpointer-arith]
                     if(a[size_vec] != NULL)
                                       ^~~~
prog.cpp:121:39: warning: NULL used in arithmetic [-Wpointer-arith]
                     if(a[size_vec] != NULL)
                                       ^~~~
prog.cpp:151:43: warning: NULL used in arithmetic [-Wpointer-arith]
                         if(a[size_vec] != NULL)
                                           ^~~~
prog.cpp:172:43: warning: NULL used in arithmetic [-Wpointer-arith]
                         if(a[size_vec] != NULL)
                                           ^~~~
prog.cpp:196:43: warning: NULL used in arithmetic [-Wpointer-arith]
                         if(a[size_vec] != NULL)
                                           ^~~~
prog.cpp:224:43: warning: NULL used in arithmetic [-Wpointer-arith]
                         if(a[size_vec] != NULL)
                                           ^~~~
prog.cpp:242:43: warning: NULL used in arithmetic [-Wpointer-arith]
                         if(a[size_vec] != NULL)
                                           ^~~~
prog.cpp:260:43: warning: NULL used in arithmetic [-Wpointer-arith]
                         if(a[size_vec] != NULL)
                                           ^~~~
prog.cpp: In function ‘std::__cxx11::string eqv_vector(vector&, vector&, std::__cxx11::string, std::__cxx11::string)’:
prog.cpp:369:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
prog.cpp: In function ‘double get_num_vector(vector&, int)’:
prog.cpp:316:88: warning: control reaches end of non-void function [-Wreturn-type]
         cout << "Ukazanniy index vectora ne sushestvuet. Chislo ne bulo polucheno." << endl;
                                                                                        ^~~~
stdout
Standard output is empty