Advertisement
VolodiaKost

nothing

Jul 22nd, 2020 (edited)
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 176.31 KB | None | 0 0
  1. //#include <iostream>
  2. //#include <string>
  3. //#include <cctype>
  4. //
  5. //int main()
  6. //{
  7. //  using namespace std;
  8. // 
  9. //  char ch;
  10. //  while (cin.get(ch) && ch != '@')
  11. //  {
  12. //      if (isdigit(ch))
  13. //          continue;
  14. //      else if (islower(ch))
  15. //          ch = toupper(ch);
  16. //      else if (isupper(ch))
  17. //          ch = tolower(ch);
  18. //      cout << ch;
  19. //  }
  20. //
  21. //  return 0;
  22. //}                                 //задача 1
  23.  
  24. //#include <iostream>
  25. //#include <string>
  26. //#include <cctype>
  27. //
  28. //int main()
  29. //{
  30. //  using namespace std;
  31. //
  32. //  double arr[10];
  33. //  int i = 0;
  34. //  double middle = 0;
  35. //  while (i < 10 && cin >> arr[i])
  36. //      middle += arr[i++];
  37. //  middle /= i;
  38. //  cout << endl << middle << endl;
  39. //  for (int j = 0; j < i; ++j)
  40. //      if (arr[j] > middle)
  41. //          cout << arr[j] << "\t";
  42. //
  43. //  return 0;
  44. //}
  45.  
  46. //#include <iostream>
  47. //
  48. //int main()
  49. //{
  50. //  using namespace std;
  51. //  cout << "Please enter one of the following choices: \n";
  52. //  cout << "c) carnivore \t p) pianist\n";
  53. //  cout << "t) tree      \t g) game   \n";
  54. // 
  55. //  char ch;
  56. // 
  57. //  while(!(cin >> ch) || (ch != 'c' && ch != 't' && ch != 'p' && ch != 'g'))
  58. //  {
  59. //      cin.clear();
  60. //      while (cin.get() != '\n')
  61. //          continue;
  62. //      cout << "Please enter a, c, p, t or g: ";
  63. //  }
  64. //  switch (ch)
  65. //  {
  66. //  case 'c': cout << "Dinosaur" << endl; break;
  67. //  case 't': cout << "Tree" << endl; break;
  68. //  case 'p': cout << "Plant" << endl; break;
  69. //  case 'g': cout << "Game" << endl; break;
  70. //  }
  71. //}
  72.  
  73. //#include <iostream>
  74. //
  75. //const int strsize = 50;
  76. //const int numOfLoxs = 3;
  77. //
  78. //struct bop {
  79. //  char fullname[strsize];
  80. //  char title[strsize];
  81. //  char bopname[strsize];
  82. //  int preference;
  83. //};
  84. //
  85. //char getChoiceForMenu();
  86. //void showLoxByName(bop arr[]);
  87. //void showLoxByTitle(bop arr[]);
  88. //void showLoxByBopname(bop arr[]);
  89. //void showLoxByPreference(bop arr[]);
  90. //
  91. //using namespace std;
  92. //
  93. //int main()
  94. //{
  95. //  struct bop arr[numOfLoxs] = { {"Wimp Macho", "Junior Programmer", "WIMP", 0},
  96. //      {"Raki Rhodes", "Trainee", "TIMP", 1}, {"Hoppy Hitman", "Senior", "SIMP", 2} };
  97. //
  98. //  cout << "Benevolent Order of Programmers Report\n";
  99. //  cout << "a. display by name       b. display by title\n";
  100. //  cout << "c. display by bopname    d. display by preference\n";
  101. //  cout << "q. quit" << endl << "Enter your choice: ";
  102. //
  103. //  char choice;
  104. //  while ((choice = getChoiceForMenu()) != 'q')
  105. //  {
  106. //      switch (choice)
  107. //      {
  108. //      case 'a': showLoxByName(arr); break;
  109. //      case 'b': showLoxByTitle(arr); break;
  110. //      case 'c': showLoxByBopname(arr); break;
  111. //      case 'd': showLoxByPreference(arr); break;
  112. //      }
  113. //      cout << "Next choice: ";
  114. //  }
  115. //  cout << "Bye";
  116. //
  117. //  return 0;
  118. //}
  119. //
  120. //char getChoiceForMenu()
  121. //{
  122. //  char ch = 0;
  123. //  while ((!(cin >> ch) || ch < 'a' || ch > 'd') && ch != 'q')
  124. //  {
  125. //      cin.clear();
  126. //      while (cin.get() != '\n')
  127. //          continue;
  128. //      cout << "Enter the new letter: ";
  129. //  }
  130. //  cin.clear();
  131. //  while (cin.get() != '\n')
  132. //      continue;
  133. //  return ch;
  134. //}
  135. //
  136. //void showLoxByName(bop arr[])
  137. //{
  138. //  for (int i = 0; i < numOfLoxs; ++i)
  139. //      cout << arr[i].fullname << endl;
  140. //}
  141. //
  142. //void showLoxByTitle(bop arr[])
  143. //{
  144. //  for (int i = 0; i < numOfLoxs; ++i)
  145. //      cout << arr[i].title << endl;
  146. //}
  147. //
  148. //void showLoxByBopname(bop arr[])
  149. //{
  150. //  for (int i = 0; i < numOfLoxs; ++i)
  151. //      cout << arr[i].bopname << endl;
  152. //}
  153. //
  154. //void showLoxByPreference(bop arr[])
  155. //{
  156. //  for (int i = 0; i < numOfLoxs; ++i)
  157. //  {
  158. //      if (arr[i].preference == 0)
  159. //          cout << arr[i].fullname << endl;
  160. //      else if (arr[i].preference == 1)
  161. //          cout << arr[i].title << endl;
  162. //      else if (arr[i].preference == 2)
  163. //          cout << arr[i].bopname << endl;
  164. //  }
  165. //}
  166. //
  167.  
  168. //#include <iostream>
  169. //
  170. //using namespace std;
  171. //
  172. //int main()
  173. //{
  174. //  const int sumForTax4 = 35000;
  175. //  const int sumForTax3 = 20000;
  176. //  const int sumForTax2 = 10000;
  177. //  const int sumForTax1 = 5000;
  178. //  const float tax1 = 0;
  179. //  const float tax2 = 0.10;
  180. //  const float tax3 = 0.15;
  181. //  const float tax4 = 0.20;
  182. //
  183. //  int salary = 0;
  184. //  double taxes = 0;
  185. //  while (cin >> salary && salary > 0)
  186. //  {
  187. //      if (salary >= sumForTax4)
  188. //          taxes = sumForTax1 * tax1 + sumForTax2 * tax2 + sumForTax3 * tax3 + (salary - sumForTax4) * tax4;
  189. //      else if (salary >= sumForTax2 + sumForTax1)
  190. //          taxes = sumForTax1 * tax1 + sumForTax2 * tax2 + (salary - sumForTax2 - sumForTax1) * tax3;
  191. //      else if (salary >= sumForTax1)
  192. //          taxes = sumForTax1 * tax1 + (salary - sumForTax1) * tax2;
  193. //      else
  194. //          taxes = salary * tax1;
  195. //      cout << "Taxes = " << taxes << endl;
  196. //      cout << "Enter new salary = ";
  197. //  }
  198. //
  199. //  return 0;
  200. //}
  201.  
  202. //#include <iostream>
  203. //#include <string>
  204. //
  205. //using namespace std;
  206. //
  207. //const int bigDonate = 10000;
  208. //
  209. //struct patron
  210. //{
  211. //  string name;
  212. //  float donation;
  213. //};
  214. //
  215. //int main()
  216. //{
  217. //  int numOfDonators = 0;
  218. //  cout << "Enter the number of donators: ";
  219. //  cin >> numOfDonators;
  220. //
  221. //  patron* donatorsArray = new patron[numOfDonators];
  222. //
  223. //  for (int i = 0; i < numOfDonators; ++i)
  224. //  {
  225. //      cout << "Enter info about #" << i << " donator\n";
  226. //      cout << "Enter name: ";
  227. //      cin >> donatorsArray[i].name;
  228. //      cout << "Enter donate sum: ";
  229. //      cin >> donatorsArray[i].donation;
  230. //      cout << endl;
  231. //  }
  232. //  int count = 0;
  233. //  cout << "\t\tGrand Patrons\n";
  234. //  for (int i = 0; i < numOfDonators; ++i)
  235. //  {
  236. //      if (donatorsArray[i].donation > bigDonate)
  237. //      {
  238. //          cout << donatorsArray[i].name << endl;
  239. //          count++;
  240. //      }
  241. //  }
  242. //  if (count == 0)
  243. //      cout << "None\n";
  244. //  count = 0;
  245. //  cout << "\t\tPatrons\n";
  246. //  for (int i = 0; i < numOfDonators; ++i)
  247. //  {
  248. //      if (donatorsArray[i].donation < bigDonate)
  249. //      {
  250. //          cout << donatorsArray[i].name << endl;
  251. //          count++;
  252. //      }
  253. //  }
  254. //  if (count == 0)
  255. //      cout << "None\n";
  256. //
  257. //  delete[] donatorsArray;
  258. //  donatorsArray = 0;
  259. // 
  260. //  return 0;
  261. //}
  262.  
  263. //#include <iostream>
  264. //#include <string>
  265. //#include <cctype>
  266. //
  267. //int main()
  268. //{
  269. //  using namespace std;
  270. //  string str{};
  271. //  int vowel = 0, consonants = 0, other = 0;
  272. //
  273. //  while (cin >> str && str != "q")
  274. //  {
  275. //      if (tolower(str[0]) == 'a' || tolower(str[0]) == 'e' || tolower(str[0]) == 'o' || tolower(str[0]) == 'y'
  276. //          || tolower(str[0]) == 'u' || tolower(str[0]) == 'i')
  277. //          ++vowel;
  278. //      else if (isalpha(str[0]))
  279. //          ++consonants;
  280. //      else
  281. //          ++other;
  282. //  }
  283. //
  284. //  cout << "Vowel = " << vowel << endl;
  285. //  cout << "Consonants = " << consonants << endl;
  286. //  cout << "Other = " << other << endl;
  287. //
  288. //  return 0;
  289. //}
  290.  
  291. //#include <iostream>
  292. //#include <fstream>
  293. //
  294. //int main()
  295. //{
  296. //  using namespace std;
  297. //  ifstream in;
  298. //  in.open("in.txt");
  299. //  if (!in.is_open())
  300. //      exit(EXIT_FAILURE);
  301. //  int count = 0;
  302. //  while (in.get() && in.good())
  303. //      ++count;
  304. //  cout << count;
  305. //  in.close();
  306. //  return 0;
  307. //}
  308.  
  309. //#include <iostream>
  310. //#include <fstream>
  311. //
  312. //using namespace std;
  313. //
  314. //const int maxSize = 256;
  315. //
  316. //struct donator
  317. //{
  318. //  string name;
  319. //  float donation;
  320. //};
  321. //
  322. //int main()
  323. //{
  324. //  ifstream in;
  325. //  in.open("in.txt");
  326. //  if (!in.is_open())
  327. //      exit(EXIT_FAILURE);
  328. //  int numOfDonators = 0;
  329. //  in >> numOfDonators;
  330. //
  331. //  donator* arr = new donator[numOfDonators];
  332. //  for (int i = 0; i < numOfDonators; ++i)
  333. //  {
  334. //      in >> arr[i].name;
  335. //      in >> arr[i].donation;
  336. //  }
  337. //
  338. //  for (int i = 0; i < numOfDonators; ++i)
  339. //      cout << arr[i].name << " = " << arr[i].donation;
  340. //
  341. //  delete[] arr;
  342. //
  343. //  return 0;
  344. //}
  345.  
  346. //#include <iostream>
  347. //
  348. //using namespace std;
  349. //
  350. //float harmony(int a, int b)
  351. //{
  352. //  return 2.0 * a * b / (a + b);
  353. //}
  354. //
  355. //int main()
  356. //{
  357. //  int a, b;
  358. //  while (cin >> a >> b && a != 0 && b != 0)
  359. //      cout << "Harmony of " << a << " and " << b << " = " << harmony(a, b);
  360. //
  361. //  return 0;
  362. //}
  363.  
  364. //#include <iostream>
  365. //
  366. //using namespace std;
  367. //
  368. //const int maxSize = 10;
  369. //
  370. //int getResults(int result[])
  371. //{
  372. //  int i = 0;
  373. //  while (i < maxSize && cin >> result[i] && result[i] > 0)
  374. //      ++i;
  375. //  return i;
  376. //}
  377. //
  378. //void showResults(int res[], int size)
  379. //{
  380. //  for (int i = 0; i < size; ++i)
  381. //      cout << res[i];
  382. //}
  383. //
  384. //float calcMiddle(int res[], int size)
  385. //{
  386. //  float middle = 0;
  387. //  for (int i = 0; i < size; ++i)
  388. //      middle += res[i];
  389. //  return middle / size;
  390. //}
  391. //
  392. //int main()
  393. //{
  394. //  int result[maxSize];
  395. //  int numOfRes = getResults(result);
  396. //  showResults(result, numOfRes);
  397. //  float middle = calcMiddle(result, numOfRes);
  398. //  cout << endl << middle;
  399. //  return 0;
  400. //}
  401.  
  402. //#include <iostream>
  403. //
  404. //using namespace std;
  405. //
  406. //const int numOfBoxes = 4;
  407. //
  408. //struct box
  409. //{
  410. //    char maker[40];
  411. //    float height;
  412. //    float width;
  413. //    float length;
  414. //    float volume;
  415. //};
  416. //
  417. //void showBoxes(const box boxArr[])
  418. //{
  419. //    for (int i = 0; i < numOfBoxes; ++i)
  420. //        cout << "Box #" << i << "\t" << boxArr[i].height << "\t" << boxArr[i].width << "\t" <<
  421. //            boxArr[i].length << "\t" << boxArr[i].volume << "\t" << boxArr[i].maker << endl;
  422. //}
  423. //
  424. //void changeBox(box boxArr[])
  425. //{
  426. //    boxArr[0].height = boxArr[1].height + boxArr[2].height + boxArr[3].height;
  427. //    boxArr[0].width = boxArr[1].width + boxArr[2].width + boxArr[3].width;
  428. //    boxArr[0].length = boxArr[1].length + boxArr[2].length + boxArr[3].length;
  429. //    boxArr[0].volume = boxArr[1].volume + boxArr[2].volume+ boxArr[3].volume;
  430. //}
  431. //
  432. //int main()
  433. //{
  434. //    box boxArr[numOfBoxes]{ {"SIMP", 1, 1, 1, 1}, {"DIMP", 2, 2, 2, 2}, {"VIMP", 3, 3, 3, 3}, {"LIMP", 4, 4, 4, 4} };
  435. //    showBoxes(boxArr);
  436. //    changeBox(boxArr);
  437. //    showBoxes(boxArr);
  438. //    return 0;
  439. //}
  440.  
  441. //#include <iostream>
  442. //
  443. //using namespace std;
  444. //
  445. //unsigned long long f(int n)
  446. //{
  447. //  unsigned long long q;
  448. //  if (n == 1)
  449. //      q = 1;
  450. //  else
  451. //      q = n * f(n - 1);
  452. //  return q;
  453. //}
  454. //
  455. //int main()
  456. //{
  457. //  unsigned long long n;
  458. //  cin >> n;
  459. //  cout << f(n);
  460. //  return 0;
  461. //}
  462. //
  463. //#include <iostream>
  464. //
  465. //using namespace std;
  466. //
  467. //void fillArray(int* arr, int size)
  468. //{
  469. //  for (int i = 0; i < size; ++i)
  470. //  {
  471. //      cout << "Enter #" << i + 1 << ": ";
  472. //      cin >> arr[i];
  473. //  }
  474. //}
  475. //
  476. //void showArray(int* arr, int size)
  477. //{
  478. //  for (int i = 0; i < size; ++i)
  479. //      cout << arr[i];
  480. //  cout << endl;
  481. //}
  482. //
  483. //void reverseArray(int* arr, int size)
  484. //{
  485. //  int temp = 0;
  486. //  for (int i = 0; i < size / 2; ++i)
  487. //  {
  488. //      temp = arr[i];
  489. //      arr[i] = arr[size - i - 1];
  490. //      arr[size - i - 1] = temp;
  491. //  }
  492. //}
  493. //
  494. //int main()
  495. //{
  496. //  int numOfElem = 0;
  497. //  cout << "Enter the num of elements: ";
  498. //  cin >> numOfElem;
  499. //  int* arr = new int[numOfElem];
  500. //  fillArray(arr, numOfElem);
  501. //  showArray(arr, numOfElem);
  502. //  reverseArray(arr, numOfElem);
  503. //  showArray(arr, numOfElem);
  504. //  return 0;
  505. //}
  506.  
  507. //#include <iostream>
  508. //using namespace std;
  509. //
  510. //const int SLEN = 30;
  511. //struct student
  512. //{
  513. //  char fullname[SLEN];
  514. //  char hobby[SLEN];
  515. //  int ooplevel;
  516. //};
  517. //
  518. //int getinfo(student pa[], int n)
  519. //{
  520. //  int i;
  521. //  for (i = 0; i < n; ++i)
  522. //  {
  523. //      cout << "Enter full name: ";
  524. //      cin.getline(pa[i].fullname, SLEN, '\n');
  525. //      if (!strcmp(pa[i].fullname, ""))
  526. //          break;
  527. //      cout << "Enter hobby: ";
  528. //      cin.getline(pa[i].hobby, SLEN, '\n');
  529. //      cout << "Enter ooplevel: ";
  530. //      cin >> pa[i].ooplevel;
  531. //      while (cin.get() != '\n')
  532. //          continue;
  533. //  }
  534. //  return i;
  535. //}
  536. //
  537. //void display1(student st)
  538. //{
  539. //  cout << "Name: " << st.fullname << "\t";
  540. //  cout << "Hobby: " << st.hobby << "\t";
  541. //  cout << "Ooplevel: " << st.ooplevel << endl;
  542. //}
  543. //
  544. //void display2(const student* ps)
  545. //{
  546. //  cout << "Name: " << ps->fullname << "\t";
  547. //  cout << "Hobby: " << ps->hobby << "\t";
  548. //  cout << "Ooplevel: " << ps->ooplevel << endl;
  549. //}
  550. //
  551. //void display3(const student pa[], int n)
  552. //{
  553. //  for (int i = 0; i < n; ++i)
  554. //  {
  555. //      cout << "Name: " << pa[i].fullname << "\t";
  556. //      cout << "Hobby: " << pa[i].hobby << "\t";
  557. //      cout << "Ooplevel: " << pa[i].ooplevel << endl;
  558. //  }
  559. //}
  560. //
  561. //int main()
  562. //{
  563. //  cout << "Enter class size: ";
  564. //  int class_size;
  565. //  cin >> class_size;
  566. //  while (cin.get() != '\n')
  567. //      continue;
  568. //  student* ptr_stu = new student[class_size];
  569. //  int entered = getinfo(ptr_stu, class_size);
  570. //  for (int i = 0; i < entered; ++i)
  571. //  {
  572. //      display1(ptr_stu[i]);
  573. //      display2(&ptr_stu[i]);
  574. //  }
  575. //  display3(ptr_stu, entered);
  576. //  delete[]ptr_stu;
  577. //  cout << "Done\n";
  578. //  return 0;
  579. //}
  580.  
  581. //#include <iostream>
  582. //using namespace std;
  583. //const int Max = 5;
  584. //double * fill_array(double ar[], int limit);
  585. //void show_array(const double ar[], double *end );
  586. //void revalue(double r, double ar[], double *end);
  587. //int main()
  588. //{
  589. //  double properties[Max];
  590. //  double * end = fill_array(properties, Max);
  591. //  show_array(properties, end);
  592. //  if (end != 0)
  593. //  {
  594. //      cout << "Enter revaluation factor: ";
  595. //      double factor;
  596. //      while (!(cin >> factor))
  597. //      {
  598. //          cin.clear();
  599. //          while (cin.get() != '\n')
  600. //              continue;
  601. //          cout << "Bad input; Please enter a number: ";
  602. //      }
  603. //      revalue(factor, properties, end);
  604. //      show_array(properties, end);
  605. //  }
  606. //  cout << "Done.\n";
  607. //  cin.get();
  608. //  return 0;
  609. //}
  610. //
  611. //double * fill_array(double ar[], int limit)
  612. //{
  613. //  double temp;
  614. //  int i = 0;
  615. //  for (i = 0; i < limit; ++i)
  616. //  {
  617. //      cout << "Enter value #" << (i + 1) << ": ";
  618. //      cin >> temp;
  619. //      if (!cin)
  620. //      {
  621. //          cin.clear();
  622. //          while (cin.get() != '\n')
  623. //              continue;
  624. //          cout << "Bad input; input process terminated. \n";
  625. //          break;
  626. //      }
  627. //      else if (temp < 0)
  628. //          break;
  629. //      ar[i] = temp;
  630. //  }
  631. //  return ar + i;
  632. //}
  633. //
  634. //void show_array(const double ar[], double *end)
  635. //{
  636. //  int i = 0;
  637. //  for (; ar != end; ++ar, ++i)
  638. //  {
  639. //      cout << "Property #" << (i + 1) << ": $";
  640. //      cout << *ar << endl;
  641. //  }
  642. //}
  643. //
  644. //void revalue(double r, double ar[], double *end)
  645. //{
  646. //  for (; ar != end; ++ar)
  647. //      (*ar) *= r;
  648. //}
  649.  
  650. //#include <iostream>
  651. //using namespace std;
  652. //
  653. //double calculate(double x, double y, double (*f)(double m, double n))
  654. //{
  655. //  return f(x, y);
  656. //}
  657. //
  658. //double add(double x, double y)
  659. //{
  660. //  return x + y;
  661. //}
  662. //
  663. //double substract(double x, double y)
  664. //{
  665. //  return x - y;
  666. //}
  667. //
  668. //double divide(double x, double y)
  669. //{
  670. //  if (y == 0)
  671. //      return 0;
  672. //  return x / y;
  673. //}
  674. //
  675. //double multiplicate(double x, double y)
  676. //{
  677. //  return x * y;
  678. //}
  679. //
  680. //int main()
  681. //{
  682. //  double (*pf[4])(double x, double y) { add, substract, divide, multiplicate };
  683. //  char choice;
  684. //  double x, y;
  685. //  cout << "Choose operation: \n";
  686. //  cout << "a. add; b. substract; c. divide; d. multiplicate;\nYour choice: ";
  687. //  while (cin >> choice && choice >= 'a' && choice <= 'd')
  688. //  {
  689. //      cout << "Enter two numbers: ";
  690. //      cin >> x >> y;
  691. //      cout << "Result = ";
  692. //      switch (choice)
  693. //      {
  694. //      case 'a': cout << calculate(x, y, pf[0]); break;
  695. //      case 'b': cout << calculate(x, y, pf[1]); break;
  696. //      case 'c': cout << calculate(x, y, pf[2]); break;
  697. //      case 'd': cout << calculate(x, y, pf[3]); break;
  698. //      }
  699. //      cout << "\nChoose another operatior or press 'q' to quit: ";
  700. //  }
  701. //  return 0;
  702. //}
  703.  
  704. //#include <iostream>
  705. //using namespace std;
  706. //
  707. //void showStr(const char* str)
  708. //{
  709. //  cout << str << endl;
  710. //}
  711. //
  712. //void showStr(const char* str, int &n)
  713. //{
  714. //  for (int i = 0; i < n; ++i)
  715. //      cout << str << "\t";
  716. //  cout << endl;
  717. //  ++n;
  718. //}
  719. //int main()
  720. //{
  721. //  const char* str = "Millenium";
  722. //  int n = 1;
  723. //  showStr(str);
  724. //  showStr(str);
  725. //  showStr(str, n);
  726. //  showStr(str, n);
  727. //  showStr(str, n);
  728. //  showStr(str);
  729. //  showStr(str, n);
  730. //  showStr(str, n);
  731. //  showStr(str, n);
  732. //  showStr(str);
  733. //  return 0;
  734. //}
  735.  
  736. //#include <iostream>
  737. //
  738. //#define _CRT_SECURE_NO_WARNINGS
  739. //#pragma warning(disable:4996)
  740. //
  741. //using namespace std;
  742. //
  743. //const int maxSize = 64;
  744. //
  745. //struct CandyBar
  746. //{
  747. //  char name[maxSize];
  748. //  double weigth;
  749. //  int calories;
  750. //};
  751. //
  752. //void setCandyBar(CandyBar& bar, const char* str = "Millennium Munch", double we = 2.85, int ca = 350);
  753. //
  754. //void showCandyBar(const CandyBar& bar)
  755. //{
  756. //  cout << endl;
  757. //  cout << "Name: " << bar.name << "\t";
  758. //  cout << "Weigth: " << bar.weigth << "\t";
  759. //  cout << "Calories: " << bar.calories << "\t";
  760. //}
  761. //
  762. //int main()
  763. //{
  764. //  CandyBar X, Y;
  765. //  setCandyBar(X, "Roshen", 3.00, 400);
  766. //  showCandyBar(X);
  767. //  setCandyBar(X);
  768. //  showCandyBar(X);
  769. //  return 0;
  770. //}
  771. //
  772. //void setCandyBar(CandyBar& bar, const char* str, double we, int ca)
  773. //{
  774. //  strncpy(bar.name, str, maxSize);
  775. //  bar.weigth = we;
  776. //  bar.calories = ca;
  777. //}
  778.  
  779. //#include <iostream>
  780. //
  781. //using namespace std;
  782. //
  783. //void showString(const string& str)
  784. //{
  785. //  cout << str << endl;
  786. //}
  787. //
  788. //void changeStr(string& str)
  789. //{
  790. //  int i = 0;
  791. //  while (str[i] != '\0')
  792. //  {
  793. //      if (islower(str[i]))
  794. //          str[i] = toupper(str[i]);
  795. //      ++i;
  796. //  }
  797. //  showString(str);
  798. //}
  799. //
  800. //int main()
  801. //{
  802. //  string userStr;
  803. //  cout << "Enter a string (q to quit): ";
  804. //  cin >> userStr;
  805. //  while (userStr != "q")
  806. //  {
  807. //      changeStr(userStr);
  808. //      cout << "Next string (q to quit): ";
  809. //      cin >> userStr;
  810. //  }
  811. //
  812. //  return 0;
  813. //}
  814.  
  815. //#include <iostream>
  816. //using namespace std;
  817. //#include <cstring>
  818. //
  819. //#define _CRT_SECURE_NO_WARNINGS
  820. //#pragma warning(disable:4996)
  821. //
  822. //struct stringy
  823. //{
  824. //  char* str;
  825. //  int ct;
  826. //};
  827. //
  828. //void set(stringy& beany, const char* testing);
  829. //void show(const stringy& beany, int n = 1);
  830. //void show(const char* str, int n = 1);
  831. //
  832. //int main()
  833. //{
  834. //  stringy beany;
  835. //  char testing[] = "Reality ins't what it used to be.";
  836. //  set(beany, testing);
  837. //  show(beany);
  838. //  cout << endl;
  839. //  show(beany, 2);
  840. //  testing[0] = 'D';
  841. //  testing[1] = 'u';
  842. //  show(testing);
  843. //  cout << endl;
  844. //  show(testing, 3);
  845. //  show("Done!");
  846. //  return 0;
  847. //}
  848. //
  849. //void set(stringy& beany, const char* testing)
  850. //{
  851. //  beany.ct = strlen(testing);
  852. //  beany.str = new char[beany.ct + 1];
  853. //  strncpy(beany.str, testing, beany.ct + 1);
  854. //}
  855. //
  856. //void show(const stringy& beany, int n)
  857. //{
  858. //  for (int i = 0; i < n; ++i)
  859. //      cout << beany.str << endl;
  860. //}
  861. //
  862. //void show(const char* str, int n)
  863. //{
  864. //  for (int i = 0; i < n; ++i)
  865. //      cout << str << endl;
  866. //}
  867.  
  868. //#include <iostream>
  869. //using namespace std;
  870. //
  871. //const int numOfElem = 5;
  872. //
  873. //template <typename T>
  874. //T max5(T arr[])
  875. //{
  876. //  T max = arr[0];
  877. //  for (int i = 0; i < numOfElem; ++i)
  878. //      if (max < arr[i])
  879. //          max = arr[i];
  880. //  return max;
  881. //}
  882. //
  883. //int main()
  884. //{
  885. //  int arr1[numOfElem]{ 4, 3, 5, 1, 2 };
  886. //  double arr2[numOfElem]{ 2.5, 5.2, 6.1, 6.04, 0.2 };
  887. //  cout << max5(arr1) << endl;
  888. //  cout << max5(arr2) << endl;
  889. //  return 0;
  890. //}
  891.  
  892. //#include <iostream>
  893. //
  894. //using namespace std;
  895. //
  896. //template <typename T>
  897. //T maxn(const T arr[], int n)
  898. //{
  899. //  T max = arr[0];
  900. //  for (int i = 0; i < n; ++i)
  901. //      if (max < arr[i])
  902. //          max = arr[i];
  903. //  return max;
  904. //}
  905. //
  906. //template <> string maxn<string>(const string arr[], int n)
  907. //{
  908. //  size_t max = arr[0].size();
  909. //  int index = 0;
  910. //  for (int i = 0; i < n; ++i)
  911. //      if (max < arr[i].size())
  912. //      {
  913. //          max = arr[i].size();
  914. //          index = i;
  915. //      }
  916. //  return arr[index];
  917. //}
  918. //
  919. //int main()
  920. //{
  921. //  const int arr1[6]{ 4, 3, 1, 6, 3, 2 };
  922. //  const double arr2[4]{ 2.3, 4.2, 1.5, 0.3 };
  923. //  const string arr3[5]{ "Aba", "a", "Qwerty", "Alla", "q" };
  924. //
  925. //  cout << maxn(arr1, 6) << endl;
  926. //  cout << maxn(arr2, 4) << endl;
  927. //  cout << maxn(arr3, 5) << endl;
  928. //
  929. //  return 0;
  930. //}
  931.  
  932. //#include <iostream>
  933. //
  934. //template <typename T>
  935. //T ShowArray(T arr[], int n);
  936. //
  937. //template <typename T>
  938. //T ShowArray(T* arr[], int n);
  939. //
  940. //struct debts
  941. //{
  942. //  char name[50];
  943. //  double amount;
  944. //};
  945. //
  946. //int main()
  947. //{
  948. //  using namespace std;
  949. //  int things[6]{ 13, 31, 103, 301, 310, 130 };
  950. //  struct debts mr_E[3]
  951. //  {
  952. //      {"Ima Wolfe", 2400.0},
  953. //      {"Ura Foxe", 1300.0},
  954. //      {"Iby Stour", 1800.0}
  955. //  };
  956. //  double* pd[3];
  957. // 
  958. //  for (int i = 0; i < 3; ++i)
  959. //      pd[i] = &mr_E[i].amount;
  960. //  cout << "Listing Mr. E's counts of things: \n";
  961. // 
  962. //  cout << ShowArray(things, 6);
  963. //  cout << "Listing Mr. E's debts: \n";
  964. //
  965. //  cout << ShowArray(pd, 3);
  966. // 
  967. //  return 0;
  968. //}
  969. //
  970. //template <typename T>
  971. //T ShowArray(T arr[], int n)
  972. //{
  973. //  using namespace std;
  974. //  cout << "template A\n";
  975. //  T sum = 0;
  976. //  for (int i = 0; i < n; ++i)
  977. //      sum += arr[i];
  978. //  cout << endl;
  979. //  return sum;
  980. //}
  981. //
  982. //template <typename T>
  983. //T ShowArray(T* arr[], int n)
  984. //{
  985. //  using namespace std;
  986. //  cout << "template B\n";
  987. //  T sum = 0;
  988. //  for (int i = 0; i < n; ++i)
  989. //      sum += (*arr[i]);
  990. //  cout << endl;
  991. //  return sum;
  992. //}
  993.  
  994. //#include <iostream>
  995. //#include <string>
  996. //
  997. //class BankAccount
  998. //{
  999. //  std::string clientName;
  1000. //  std::string accNum;
  1001. //  float balance;
  1002. //  static int numOfClients;
  1003. //
  1004. //public:
  1005. //  BankAccount();
  1006. //  BankAccount(std::string clientName_, std::string accNum_, float balance_ = 0);
  1007. //  ~BankAccount();
  1008. // 
  1009. //  static int getHowManyClients();
  1010. // 
  1011. //  const std::string& getClientName() const;
  1012. //  const std::string& getAccNum() const;
  1013. //  float getBalance() const;
  1014. //
  1015. //  void setClientName(const std::string& clientName_);
  1016. //  void setAccNum(const std::string& accNum_);
  1017. //  void setBalance(const float balance_);
  1018. //
  1019. //  void deposit(const float cash);
  1020. //  void withdraw(const float cash);
  1021. // 
  1022. //  friend std::ostream& operator<<(std::ostream& os, const BankAccount &acc);
  1023. //  friend std::istream& operator>>(std::istream& is, BankAccount& acc);
  1024. //};
  1025. //
  1026. //int BankAccount::numOfClients = 0;
  1027. //
  1028. //BankAccount::BankAccount()
  1029. //{
  1030. //  clientName = "";
  1031. //  accNum = "";
  1032. //  balance = 0.0f;
  1033. //  ++numOfClients;
  1034. //}
  1035. //
  1036. //BankAccount::BankAccount(std::string clientName_, std::string accNum_, float balance_)
  1037. //{
  1038. //  clientName = clientName_;
  1039. //  accNum = accNum_;
  1040. //  balance = balance_;
  1041. //  ++numOfClients;
  1042. //}
  1043. //
  1044. //BankAccount::~BankAccount()
  1045. //{
  1046. //  clientName = "";
  1047. //  accNum = "";
  1048. //  balance = 0;
  1049. //  --numOfClients;
  1050. //}
  1051. //
  1052. //int BankAccount::getHowManyClients()
  1053. //{
  1054. //  return numOfClients;
  1055. //}
  1056. //
  1057. //
  1058. //const std::string& BankAccount::getClientName() const
  1059. //{
  1060. //  return clientName;
  1061. //}
  1062. //
  1063. //const std::string& BankAccount::getAccNum() const
  1064. //{
  1065. //  return accNum;
  1066. //}
  1067. //
  1068. //float BankAccount::getBalance() const
  1069. //{
  1070. //  return balance;
  1071. //}
  1072. //
  1073. //void BankAccount::setClientName(const std::string& clientName_)
  1074. //{
  1075. //  clientName = clientName_;
  1076. //}
  1077. //
  1078. //void BankAccount::setAccNum(const std::string& accNum_)
  1079. //{
  1080. //  accNum = accNum_;
  1081. //}
  1082. //
  1083. //void BankAccount::setBalance(const float balance_)
  1084. //{
  1085. //  balance = balance_;
  1086. //}
  1087. //
  1088. //void BankAccount::deposit(const float cash)
  1089. //{
  1090. //  balance += cash;
  1091. //}
  1092. //
  1093. //void BankAccount::withdraw(const float cash)
  1094. //{
  1095. //  balance -= cash;
  1096. //}
  1097. //
  1098. //std::ostream& operator<<(std::ostream& os, const BankAccount& acc)
  1099. //{
  1100. //  os << std::endl << "Client name: " << acc.clientName << std::endl <<
  1101. //      "Account num: " << acc.accNum << std::endl <<
  1102. //      "Balance: " << acc.balance << std::endl;
  1103. //  return os;
  1104. //
  1105. //}
  1106. //
  1107. //std::istream& operator>>(std::istream& is, BankAccount& acc)
  1108. //{
  1109. //  std::cout << std::endl << "Enter client name: ";
  1110. //  is >> acc.clientName;
  1111. //  std::cout << std::endl << "Enter account num: ";
  1112. //  is >> acc.accNum;
  1113. //  std::cout << std::endl << "Enter balance: ";
  1114. //  is >> acc.balance;
  1115. //  return is;
  1116. //}
  1117. //
  1118. //int main()
  1119. //{
  1120. //  {
  1121. //      BankAccount Acc1("Mark", "01", 23.56);
  1122. //      std::cout << std::endl << BankAccount::getHowManyClients();
  1123. //      BankAccount Acc2("Vol", "02");
  1124. //      std::cout << std::endl << BankAccount::getHowManyClients();
  1125. //      BankAccount Acc3;
  1126. //      std::cout << std::endl << BankAccount::getHowManyClients();
  1127. //      std::cin >> Acc3;
  1128. //      std::cout << Acc1 << Acc2 << Acc3;
  1129. //      Acc1.setAccNum("04");
  1130. //      Acc2.setClientName("Volodia");
  1131. //      Acc3.setBalance(500.0f);
  1132. //      std::cout << Acc1.getAccNum();
  1133. //      std::cout << Acc2.getClientName();
  1134. //      std::cout << Acc3.getBalance();
  1135. //      Acc3.deposit(500.0f);
  1136. //      std::cout << Acc3.getBalance();
  1137. //      Acc3.withdraw(500.0f);
  1138. //      std::cout << Acc3.getBalance();
  1139. //      std::cout << std::endl << BankAccount::getHowManyClients();
  1140. //  }
  1141. //  std::cout << std::endl << BankAccount::getHowManyClients();
  1142. //
  1143. //  return 0;
  1144. //}
  1145.  
  1146. //#include <iostream>
  1147. //#include <string>
  1148. //
  1149. //#define _crt_secure_no_warnings
  1150. //#pragma warning(disable:4996)
  1151. //
  1152. //using namespace std;
  1153. //
  1154. //class Person
  1155. //{
  1156. //private:
  1157. //  static const int LIMIT = 25;
  1158. //  string lname;
  1159. //  char fname[LIMIT];
  1160. //public:
  1161. //  Person() { lname = ""; fname[0] = '\0'; }
  1162. //  Person(const string& ln, const char* fn = "Heyyou");
  1163. //
  1164. //  void Show() const;
  1165. //  void FormalShow() const;
  1166. //};
  1167. //
  1168. //
  1169. //Person::Person(const string& ln, const char* fn)
  1170. //{
  1171. //  lname = ln;
  1172. //  strncpy(fname, fn, LIMIT);
  1173. //}
  1174. //
  1175. //void Person::Show() const
  1176. //{
  1177. //  cout << fname << " " << lname;
  1178. //}
  1179. //
  1180. //void Person::FormalShow() const
  1181. //{
  1182. //  cout << lname << " " << fname;
  1183. //}
  1184. //
  1185. //
  1186. //int main()
  1187. //{
  1188. //  Person one;
  1189. //  Person two("Smythecraft");
  1190. //  Person three("Dimwiddy", "Sam");
  1191. //
  1192. //  one.Show();
  1193. //  cout << endl;
  1194. //  one.FormalShow();
  1195. //
  1196. //  two.Show();
  1197. //  cout << endl;
  1198. //  two.FormalShow();
  1199. //
  1200. //  three.Show();
  1201. //  cout << endl;
  1202. //  three.FormalShow();
  1203. //
  1204. //  return 0;
  1205. //}
  1206.  
  1207. //#include <iostream>
  1208. //using namespace std;
  1209. //const int Len = 40;
  1210. //#define _crt_secure_no_warnings
  1211. //#pragma warning(disable:4996)
  1212. //
  1213. //class Golf
  1214. //{
  1215. //  char fullname[Len];
  1216. //  int handicap;
  1217. //public:
  1218. //  Golf();
  1219. //  Golf(const char* name, int hc);
  1220. //  void setgolf();
  1221. //  void changeHandicap(int hc);
  1222. //  void showgolf() const;
  1223. //};
  1224. //
  1225. //Golf::Golf()
  1226. //{
  1227. //  fullname[0] = '\0';
  1228. //  handicap = 0;
  1229. //}
  1230. //
  1231. //Golf::Golf(const char* name, int hc)
  1232. //{
  1233. //  strncpy(fullname, name, Len);
  1234. //  handicap = hc;
  1235. //}
  1236. //
  1237. //void Golf::setgolf()
  1238. //{
  1239. //  char fn[Len];
  1240. //  int hc;
  1241. //  cout << "Enter fullname: ";
  1242. //  cin >> fn;
  1243. //  cout << "Enter handicap: ";
  1244. //  cin >> hc;
  1245. //  *this = Golf(fn, hc);
  1246. //}
  1247. //
  1248. //void Golf::changeHandicap(int hc)
  1249. //{
  1250. //  handicap = hc;
  1251. //}
  1252. //
  1253. //void Golf::showgolf() const
  1254. //{
  1255. //  cout << "Fullname: " << fullname;
  1256. //  cout << "Handicap: " << handicap;
  1257. //}
  1258. //
  1259. //int main()
  1260. //{
  1261. //  Golf G1("Andriy", 6);
  1262. //  G1.showgolf();
  1263. //  Golf G2;
  1264. //  G2.setgolf();
  1265. //  G2.showgolf();
  1266. //  G1.changeHandicap(5);
  1267. //  G1.showgolf();
  1268. //
  1269. //  return 0;
  1270. //}
  1271.  
  1272. //#include <iostream>
  1273. //namespace SALES
  1274. //{
  1275. //  const int QUARTERS = 4;
  1276. //  class Sales
  1277. //  {
  1278. //      double sales[QUARTERS];
  1279. //      double average;
  1280. //      double max;
  1281. //      double min;
  1282. //  public:
  1283. //      Sales(const double ar[], int n);
  1284. //      Sales();
  1285. //      void setSales();
  1286. //      void showSales();
  1287. //  };
  1288. //}
  1289. //
  1290. //SALES::Sales::Sales()
  1291. //{
  1292. //  for (int i = 0; i < SALES::QUARTERS; ++i)
  1293. //      sales[i] = 0;
  1294. //  average = max = min = 0;
  1295. //}
  1296. //
  1297. //SALES::Sales::Sales(const double ar[], int n)
  1298. //{
  1299. //  double av = 0, min_ = ar[0], max_ = ar[n - 1];
  1300. //  for (int i = 0; i < n; ++i)
  1301. //  {
  1302. //      SALES::Sales::sales[i] = ar[i];
  1303. //      av += SALES::Sales::sales[i];
  1304. //      if (min_ > SALES::Sales::sales[i])
  1305. //          min_ = SALES::Sales::sales[i];
  1306. //      else if (max_ < SALES::Sales::sales[i])
  1307. //          max_ = SALES::Sales::sales[i];
  1308. //  }
  1309. //  av /= n;
  1310. //  for (int i = n; i < SALES::QUARTERS; ++i)
  1311. //      SALES::Sales::sales[i] = 0;
  1312. //  SALES::Sales::average = av;
  1313. //  SALES::Sales::min = min_;
  1314. //  SALES::Sales::max = max_;
  1315. //}
  1316. //
  1317. //void SALES::Sales::setSales()
  1318. //{
  1319. //  double sale[QUARTERS];
  1320. //  std::cout << "Enter " << SALES::QUARTERS << " sales: ";
  1321. //  for (int i = 0; i < SALES::QUARTERS; ++i)
  1322. //      std::cin >> sale[i];
  1323. //  *this = SALES::Sales::Sales(sale, SALES::QUARTERS);
  1324. //}
  1325. //
  1326. //void SALES::Sales::showSales()
  1327. //{
  1328. //  std::cout << std::endl << "Min = " << min << " Max = " << max << " Av = " << average << std::endl;
  1329. //}
  1330. //
  1331. //int main()
  1332. //{
  1333. //  const double arr[SALES::QUARTERS]{ 1.0, 1.2, 1.4 };
  1334. //  SALES::Sales S1(arr, 3);
  1335. //  SALES::Sales S2;
  1336. //  S1.showSales();
  1337. //  S2.setSales();
  1338. //  S2.showSales();
  1339. //  return 0;
  1340. //}
  1341.  
  1342. //#include <iostream>
  1343. //#include <string>
  1344. //
  1345. //struct Customer
  1346. //{
  1347. //  std::string name;
  1348. //  std::string surname;
  1349. //  float payment;
  1350. //
  1351. //};
  1352. //
  1353. //
  1354. //class Stack
  1355. //{
  1356. //  struct Node
  1357. //  {
  1358. //      Customer cus;
  1359. //      Node* next;
  1360. //      Node* prev;
  1361. //  };
  1362. // 
  1363. //  Node* top;
  1364. //  int numOfNodes;
  1365. //  const int maxSize = 10;
  1366. //  static float totalPayment;
  1367. //public:
  1368. //  Stack();
  1369. //  bool isFull() const;
  1370. //  bool isEmpty() const;
  1371. //  void addNode(const Customer &cus);
  1372. //  void popNode();
  1373. //  void show();
  1374. //  static int getTotal();
  1375. //};
  1376. //
  1377. //float Stack::totalPayment = 0.0;
  1378. //
  1379. //int Stack::getTotal()
  1380. //{
  1381. //  return totalPayment;
  1382. //}
  1383. //
  1384. //Stack::Stack() : top(nullptr), numOfNodes(0)
  1385. //{
  1386. //}
  1387. //
  1388. //bool Stack::isFull() const
  1389. //{
  1390. //  return numOfNodes == maxSize;
  1391. //}
  1392. //
  1393. //bool Stack::isEmpty() const
  1394. //{
  1395. //  return numOfNodes == 0;
  1396. //}
  1397. //
  1398. //void Stack::addNode(const Customer& buyer)
  1399. //{
  1400. //  if (numOfNodes == maxSize)
  1401. //  {
  1402. //      std::cout << std::endl << "Max num of nodes " << std::endl;
  1403. //  }
  1404. //  else if (top == nullptr)
  1405. //  {
  1406. //      Node* temp = new Node;
  1407. //      temp->cus = buyer;
  1408. //      temp->prev = nullptr;
  1409. //      temp->prev = nullptr;
  1410. //      top = temp;
  1411. //      ++numOfNodes;
  1412. //  }
  1413. //  else
  1414. //  {
  1415. //      Node* temp = new Node;
  1416. //      temp->cus = buyer;
  1417. //      temp->prev = top;
  1418. //      temp->next = nullptr;
  1419. //      top->next = temp;
  1420. //      top = temp;
  1421. //      ++numOfNodes;
  1422. //  }
  1423. //}
  1424. //
  1425. //void Stack::popNode()
  1426. //{
  1427. //  if (top == nullptr)
  1428. //      return;
  1429. //  else if (top->prev == nullptr)
  1430. //  {
  1431. //      totalPayment += top->cus.payment;
  1432. //      delete top;
  1433. //      top = nullptr;
  1434. //      numOfNodes = 0;
  1435. //  }
  1436. //  else
  1437. //  {
  1438. //      Node* temp = top->prev;
  1439. //      totalPayment += top->cus.payment;
  1440. //      delete top;
  1441. //      top = temp;
  1442. //      --numOfNodes;
  1443. //  }
  1444. //}
  1445. //
  1446. //void Stack::show()
  1447. //{
  1448. //  using std::cout;
  1449. //  using std::endl;
  1450. //  Node* temp = top;
  1451. //  while (temp != nullptr)
  1452. //  {
  1453. //      cout << endl << temp->cus.name << "\t" << temp->cus.surname << "\t" << temp->cus.payment;
  1454. //      temp = temp->prev;
  1455. //  }
  1456. //}
  1457. //
  1458. //int main()
  1459. //{
  1460. //  using std::cout;
  1461. //  using std::cin;
  1462. //  using std::endl;
  1463. //  Stack stack;
  1464. //  Customer buyer{ "A", "b", 50.0f };
  1465. //  cout << endl << stack.isEmpty() << endl;
  1466. //  cout << endl << stack.isFull() << endl;
  1467. //  stack.addNode(buyer);
  1468. //  stack.show();
  1469. //  cout << stack.isEmpty() << endl;
  1470. //  cout << stack.isFull() << endl;
  1471. //  stack.addNode(buyer);
  1472. //  cout << stack.isEmpty() << endl;
  1473. //  cout << stack.isFull() << endl;
  1474. //  stack.addNode(buyer);
  1475. //  stack.addNode(buyer);
  1476. //  stack.addNode(buyer);
  1477. //  stack.addNode(buyer);
  1478. //  stack.addNode(buyer);
  1479. //  stack.addNode(buyer);
  1480. //  stack.addNode(buyer);
  1481. //  stack.addNode(buyer);
  1482. //  stack.addNode(buyer);
  1483. //  stack.addNode(buyer);
  1484. //  stack.show();
  1485. //  cout << endl << stack.isEmpty() << endl;
  1486. //  cout << endl << stack.isFull() << endl << endl << endl;
  1487. //
  1488. //  cout << stack.getTotal();
  1489. //
  1490. //  stack.popNode();
  1491. //  stack.popNode();
  1492. //
  1493. //  cout << stack.getTotal();
  1494. //
  1495. //  stack.popNode();
  1496. //  stack.popNode();
  1497. //  stack.popNode();
  1498. //  stack.popNode();
  1499. //  stack.popNode();
  1500. //  stack.popNode();
  1501. //  stack.popNode();
  1502. //  stack.popNode();
  1503. //
  1504. //  cout << stack.getTotal();
  1505. //  stack.popNode();
  1506. //  stack.popNode();
  1507. //  cout << stack.isEmpty() << endl;
  1508. //  cout << stack.isFull() << endl;
  1509. //
  1510. //  return 0;
  1511. //}
  1512. //
  1513. //#include <iostream>
  1514. //
  1515. //class Move
  1516. //{
  1517. //private:
  1518. //  double x;
  1519. //  double y;
  1520. //public:
  1521. //  Move(double a = 0, double b = 0);
  1522. //  void showmove() const;
  1523. //  Move add(const Move& m) const;
  1524. //  void reset(double a = 0, double b = 0);
  1525. //};
  1526. //
  1527. //Move::Move(double a, double b)
  1528. //{
  1529. //  x = a;
  1530. //  y = b;
  1531. //}
  1532. //
  1533. //void Move::showmove() const
  1534. //{
  1535. //  using std::cout;
  1536. //  cout << "X = " << x << "\t" << "Y = " << y << std::endl;
  1537. //}
  1538. //
  1539. //void Move::reset(double a, double b)
  1540. //{
  1541. //  x = a;
  1542. //  y = b;
  1543. //}
  1544. //
  1545. //Move Move::add(const Move& m) const
  1546. //{
  1547. //  Move temp(x + m.x, y + m.y);
  1548. //  return temp;
  1549. //}
  1550. //
  1551. //int main()
  1552. //{
  1553. //  using std::cout;
  1554. //  using std::endl;
  1555. //
  1556. //  Move A;
  1557. //  A.showmove();
  1558. //  Move B(1, 2);
  1559. //  B.showmove();
  1560. //  A.reset(2, 3);
  1561. //  A.showmove();
  1562. //  Move C = B.add(A);
  1563. //  C.showmove();
  1564. //
  1565. //  return 0;
  1566. //}
  1567.  
  1568. //#include <iostream>
  1569. //#include <string>
  1570. //using namespace std;
  1571. //class Plorg
  1572. //{
  1573. //  string name;
  1574. //  int CI;
  1575. //public:
  1576. //  Plorg(const string& n = "Plorga", int ci = 50);
  1577. //  void show() const;
  1578. //  void changeCI(int ci);
  1579. //};
  1580. //
  1581. //Plorg::Plorg(const string& n, int ci)
  1582. //{
  1583. //  name = n;
  1584. //  CI = ci;
  1585. //}
  1586. //
  1587. //void Plorg::show() const
  1588. //{
  1589. //  cout << endl << "Name: " << name << "\t" << "CI = " << CI;
  1590. //}
  1591. //
  1592. //void Plorg::changeCI(int ci)
  1593. //{
  1594. //  CI = ci;
  1595. //}
  1596. //
  1597. //int main()
  1598. //{
  1599. //  Plorg A;
  1600. //  A.show();
  1601. //  A.changeCI(5);
  1602. //  A.show();
  1603. //  Plorg B("Q", 2);
  1604. //  B.show();
  1605. //  return 0;
  1606. //}
  1607. //
  1608.  
  1609. //#include <iostream>
  1610. //#include <fstream>
  1611. //#include <cmath>
  1612. //#include <cstdlib>
  1613. //#include <ctime>
  1614. //using namespace std;
  1615. //
  1616. //namespace VECTOR
  1617. //{
  1618. //  class Vector
  1619. //  {
  1620. //  public:
  1621. //      enum Mode {RECT, POL};
  1622. //  private:
  1623. //      double x;
  1624. //      double y;
  1625. //      Mode mode;
  1626. //     
  1627. //      void set_x(double n1, double n2);
  1628. //      void set_y(double n1, double n2);
  1629. //  public:
  1630. //      Vector();
  1631. //      Vector(double n1, double n2, Mode form = RECT);
  1632. //      void reset(double n1, double n2, Mode form = RECT);
  1633. //      ~Vector();
  1634. //      double xval() const { return x; }
  1635. //      double yval() const { return y; }
  1636. //      double magval() const { return sqrt(x * x + y * y); }
  1637. //      double angval() const { return (x == 0 && y == 0) ? 0.0 : atan2(y, x); }
  1638. //      void polar_mode();
  1639. //      void rect_mode();
  1640. //
  1641. //      Vector operator+(const Vector& b) const;
  1642. //      Vector operator-(const Vector& b) const;
  1643. //      Vector operator-() const;
  1644. //      Vector operator*(double n) const;
  1645. //
  1646. //      friend Vector operator*(double n, const Vector& a);
  1647. //      friend ostream& operator << (ostream& os, const Vector& v);
  1648. //  };
  1649. //}
  1650. //
  1651. //namespace VECTOR
  1652. //{
  1653. //  const double Rad_to_deg = 45.0 / atan(1.0);
  1654. //
  1655. //  void Vector::set_x(double n1, double n2)
  1656. //  {
  1657. //      x = n1 * cos(n2);
  1658. //  }
  1659. //  void Vector::set_y(double n1, double n2)
  1660. //  {
  1661. //      y = n1 * sin(n2);
  1662. //  }
  1663. //  Vector::Vector()
  1664. //  {
  1665. //      x = y = 0.0;
  1666. //      mode = RECT;
  1667. //  }
  1668. //  Vector::Vector(double n1, double n2, Mode form)
  1669. //  {
  1670. //      mode = form;
  1671. //      if (form == RECT)
  1672. //      {
  1673. //          x = n1;
  1674. //          y = n2;
  1675. //      }
  1676. //      else if (form == POL)
  1677. //      {
  1678. //          set_x(n1, n2);
  1679. //          set_y(n1, n2);
  1680. //      }
  1681. //      else
  1682. //      {
  1683. //          cout << "Incorrect 3rd argument to Vector() -- ";
  1684. //          cout << "vector set to 0\n";
  1685. //          x = y = 0.0;
  1686. //          mode = RECT;
  1687. //      }
  1688. //  }
  1689. //  void Vector::reset(double n1, double n2, Mode form)
  1690. //  {
  1691. //      mode = form;
  1692. //      if (form == RECT)
  1693. //      {
  1694. //          x = n1;
  1695. //          y = n2;
  1696. //      }
  1697. //      else if (form == POL)
  1698. //      {
  1699. //          set_x(n1, n2);
  1700. //          set_y(n1, n2);
  1701. //      }
  1702. //      else
  1703. //      {
  1704. //          cout << "Incorrect 3rd argument to Vector() -- ";
  1705. //          cout << "vector set to 0\n";
  1706. //          x = y = 0.0;
  1707. //          mode = RECT;
  1708. //      }
  1709. //  }
  1710. //
  1711. //  Vector::~Vector()
  1712. //  {
  1713. //  }
  1714. //  void Vector::polar_mode()
  1715. //  {
  1716. //      mode = POL;
  1717. //  }
  1718. //  void Vector::rect_mode()
  1719. //  {
  1720. //      mode = RECT;
  1721. //  }
  1722. //  Vector Vector::operator+(const Vector& b) const
  1723. //  {
  1724. //      return Vector(x + b.x, y + b.y);
  1725. //  }
  1726. //  Vector Vector::operator-(const Vector& b) const
  1727. //  {
  1728. //      return Vector(x - b.x, y - b.y);
  1729. //  }
  1730. //  Vector Vector::operator-() const
  1731. //  {
  1732. //      return Vector(-x, -y);
  1733. //  }
  1734. //  Vector Vector::operator*(double n) const
  1735. //  {
  1736. //      return Vector(n * x, n * y);
  1737. //  }
  1738. //  Vector operator*(double n, const Vector& a)
  1739. //  {
  1740. //      return a * n;
  1741. //  }
  1742. //  ostream& operator<<(ostream& os, const Vector& v)
  1743. //  {
  1744. //      if (v.mode == Vector::RECT)
  1745. //          os << "(x, y) = (" << v.x << ", " << v.y << ")";
  1746. //      else if (v.mode == Vector::POL)
  1747. //          os << "(m, a) = (" << v.magval() << ", " << v.angval() * Rad_to_deg << ")";
  1748. //      return os;
  1749. //  }
  1750. //}
  1751. //
  1752. //int main()
  1753. //{
  1754. //  using VECTOR::Vector;
  1755. //
  1756. //  srand(time(0));
  1757. //  double direction;
  1758. //  Vector step;
  1759. //  Vector result(0.0, 0.0);
  1760. //  unsigned long steps = 0;
  1761. //  double target;
  1762. //  double dstep;
  1763. //  int N;
  1764. //
  1765. //  cout << "Enter target distance (q to quit): ";
  1766. //  while (cin >> target)
  1767. //  {
  1768. //      cout << "Enter step length: ";
  1769. //      if (!(cin >> dstep))
  1770. //          break;
  1771. //      cout << "Enter N: ";
  1772. //      if (!(cin >> N))
  1773. //          break;
  1774. //      cout << "Target Distance: " << target << ", Step Size: " << dstep << ", N = "<< N << endl;
  1775. //      int count = 0;
  1776. //      while (count < N)
  1777. //      {
  1778. //          while (result.magval() < target)
  1779. //          {
  1780. //              direction = rand() % 10;
  1781. //              step.reset(dstep, direction, Vector::POL);
  1782. //              result = result + step;
  1783. //              ++steps;
  1784. //          }
  1785. //          result.rect_mode();
  1786. //          cout << count + 1 << ") After " << steps << " steps, the subject "
  1787. //              "has the following location:\n";
  1788. //          cout << result << endl;
  1789. //          result.polar_mode();
  1790. //          cout << " or\n" << result << endl;
  1791. //
  1792. //          cout << "Average outward distance per step = "
  1793. //              << result.magval() / steps << endl << endl;
  1794. //          ++count;
  1795. //      }
  1796. //
  1797. //      steps = 0;
  1798. //      result.reset(0.0, 0.0);
  1799. //      cout << "Enter target distance (q to quit): ";
  1800. //  }
  1801. //  cout << "Bye!\n";
  1802. //  cin.clear();
  1803. //  while (cin.get() != '\n')
  1804. //      continue;
  1805. //  return 0;
  1806. //}
  1807.  
  1808. //#include <iostream>
  1809. //
  1810. //class Time
  1811. //{
  1812. //private:
  1813. //  int hours;
  1814. //  int minutes;
  1815. //public:
  1816. //  Time();
  1817. //  Time(int h, int m = 0);
  1818. //  void AddMin(int m);
  1819. //  void AddHr(int h);
  1820. //  void Reset(int h = 0, int m = 0);
  1821. //  friend Time operator+(const Time& t1, const Time& t2);
  1822. //  friend Time operator-(const Time& t1, const Time& t2);
  1823. //  friend Time operator*(const Time& t, double mult);
  1824. //  friend Time operator*(double m, const Time& t) { return t * m; }
  1825. //  friend std::ostream& operator << (std::ostream& os, const Time& t);
  1826. //};
  1827. //
  1828. //Time::Time()
  1829. //{
  1830. //  hours = minutes = 0;
  1831. //}
  1832. //
  1833. //Time::Time(int h, int m)
  1834. //{
  1835. //  hours = h;
  1836. //  minutes = m;
  1837. //}
  1838. //
  1839. //void Time::AddMin(int m)
  1840. //{
  1841. //  minutes += m;
  1842. //  hours += minutes / 60;
  1843. //  minutes %= 60;
  1844. //}
  1845. //
  1846. //void Time::AddHr(int h)
  1847. //{
  1848. //  hours += h;
  1849. //}
  1850. //
  1851. //Time operator+(const Time& t1, const Time& t2)
  1852. //{
  1853. //  Time sum;
  1854. //  sum.minutes = t1.minutes + t2.minutes;
  1855. //  sum.hours = t1.hours + t2.hours + sum.minutes / 60;
  1856. //  sum.minutes %= 60;
  1857. //  return sum;
  1858. //}
  1859. //
  1860. //Time operator-(const Time& t1, const Time& t2)
  1861. //{
  1862. //  Time diff;
  1863. //  int tot1, tot2;
  1864. //  tot1 = t2.minutes + 60 * t2.hours;
  1865. //  tot2 = t1.minutes + 60 * t1.hours;
  1866. //  diff.minutes = (tot2 - tot1) % 60;
  1867. //  diff.hours = (tot2 - tot1) / 60;
  1868. //  return diff;
  1869. //}
  1870. //
  1871. //Time operator*(const Time& t, double mult)
  1872. //{
  1873. //  Time result;
  1874. //  long totalminutes = t.hours * mult * 60 + t.minutes * mult;
  1875. //  result.hours = totalminutes / 60;
  1876. //  result.minutes = totalminutes % 60;
  1877. //  return result;
  1878. //}
  1879. //
  1880. //std::ostream& operator<<(std::ostream& os, const Time& t)
  1881. //{
  1882. //  os << t.hours << " hours, " << t.minutes << " minutes";
  1883. //  return os;
  1884. //}
  1885. //
  1886. //int main()
  1887. //{
  1888. //  using std::cout;
  1889. //  using std::endl;
  1890. //
  1891. //  Time aida(3, 35);
  1892. //  Time tosca(2, 48);
  1893. //  Time temp;
  1894. //  cout << "Aida and Tosca:\n ";
  1895. //  cout << aida << "; " << tosca << endl;
  1896. //  temp = aida + tosca;
  1897. //  cout << "Aida + Tosca: " << temp << endl;
  1898. //  temp = aida * 1.17;
  1899. //  cout << "Aida * 1.17: " << temp << endl;
  1900. //  cout << "10.0 * Tosca: " << 10.0 * tosca << endl;
  1901. //  return 0;
  1902. //}
  1903.  
  1904. //#include <iostream>
  1905. //using namespace std;
  1906. //class Stonewt
  1907. //{
  1908. //private:
  1909. //  int dollars;
  1910. //  int cents;
  1911. //public:
  1912. //  enum Mode {D, C};
  1913. //  Mode mode;
  1914. //  Stonewt();
  1915. //  Stonewt(int cent);
  1916. //  Stonewt(int dollar, int cent);
  1917. //  ~Stonewt();
  1918. //  Stonewt operator+(const Stonewt& s) const;
  1919. //  Stonewt operator-(const Stonewt& s) const;
  1920. //  Stonewt operator*(int mult) const;
  1921. //  bool operator>(const Stonewt& s) const;
  1922. //  bool operator<(const Stonewt& s) const;
  1923. //  bool operator>=(const Stonewt& s) const;
  1924. //  bool operator<=(const Stonewt& s) const;
  1925. //  bool operator==(const Stonewt& s) const;
  1926. //  bool operator!=(const Stonewt& s) const;
  1927. //  friend ostream& operator<<(ostream& os, const Stonewt& s);
  1928. //};
  1929. //
  1930. //bool Stonewt::operator!=(const Stonewt& s) const
  1931. //{
  1932. //  return !(*this == s);
  1933. //}
  1934. //
  1935. //bool Stonewt::operator==(const Stonewt& s) const
  1936. //{
  1937. //  return dollars * 100 + cents == s.dollars * 100 + cents;
  1938. //}
  1939. //
  1940. //bool Stonewt::operator<=(const Stonewt& s) const
  1941. //{
  1942. //  return s >= *this;
  1943. //}
  1944. //
  1945. //bool Stonewt::operator>=(const Stonewt& s) const
  1946. //{
  1947. //  return dollars * 100 + cents >= s.dollars * 100 + cents;
  1948. //}
  1949. //
  1950. //bool Stonewt::operator<(const Stonewt& s) const
  1951. //{
  1952. //  return s > *this;
  1953. //}
  1954. //
  1955. //bool Stonewt::operator>(const Stonewt& s) const
  1956. //{
  1957. //  return dollars * 100 + cents > s.dollars * 100 + cents;
  1958. //}
  1959. //
  1960. //Stonewt Stonewt::operator*(int mult) const
  1961. //{
  1962. //  return Stonewt(dollars * mult, cents * mult);
  1963. //}
  1964. //
  1965. //Stonewt Stonewt::operator-(const Stonewt& s) const
  1966. //{
  1967. //  return Stonewt(dollars - s.dollars, cents - s.cents);
  1968. //}
  1969. //
  1970. //Stonewt Stonewt::operator+(const Stonewt& s) const
  1971. //{
  1972. //  return Stonewt(dollars + s.dollars, cents + s.cents);
  1973. //}
  1974. //
  1975. //ostream& operator<<(ostream& os, const Stonewt& s)
  1976. //{
  1977. //  if (s.mode == s.D)
  1978. //      os << s.dollars << " dollars, " << s.cents << " cents\n";
  1979. //  else if (s.mode == s.C)
  1980. //      os << s.dollars * 100 + s.cents << " cents\n";
  1981. //  return os;
  1982. //}
  1983. //
  1984. //Stonewt::Stonewt(int cent)
  1985. //{
  1986. //  mode = D;
  1987. //  dollars = cent / 100;
  1988. //  cents = cent % 100;
  1989. //}
  1990. //
  1991. //Stonewt::Stonewt(int dol, int cent)
  1992. //{
  1993. //  mode = D;
  1994. //  dollars = dol;
  1995. //  cents = cent;
  1996. //}
  1997. //
  1998. //Stonewt::Stonewt()
  1999. //{
  2000. //  mode = D;
  2001. //  dollars = cents = 0;
  2002. //}
  2003. //
  2004. //Stonewt::~Stonewt()
  2005. //{
  2006. //}
  2007. //
  2008. //int main()
  2009. //{
  2010. //  Stonewt st[6]{ {1, 10}, {3, 30}, {5, 50,}, {2, 20}, {6, 60}, {4, 40} };
  2011. //  Stonewt min = st[0], max = st[5];
  2012. //  Stonewt temp = st[1];
  2013. //  for (int i = 0; i < 6; ++i)
  2014. //  {
  2015. //      if (st[i] < min)
  2016. //          min = st[i];
  2017. //      if (st[i] > max)
  2018. //          max = st[i];
  2019. //      if (st[i] >= temp)
  2020. //          cout << st[i];
  2021. //  }
  2022. //
  2023. //  cout << "min = " << min;
  2024. //  cout << "max = " << max;
  2025. //  return 0;
  2026. //}
  2027.  
  2028. //#include <iostream>
  2029. //using namespace std;
  2030. //class Complex
  2031. //{
  2032. //  float real;
  2033. //  float imag;
  2034. //
  2035. //public:
  2036. //  Complex(float r = 0, float i = 0);
  2037. //
  2038. //  Complex operator+(const Complex& C) const;
  2039. //  Complex operator-(const Complex& C) const;
  2040. //  Complex operator*(const Complex& C) const;
  2041. //  Complex operator*(const float mult) const;
  2042. //  Complex operator-() const;
  2043. //  friend Complex operator*(const float mult, const Complex& C);
  2044. //
  2045. //  friend istream& operator>>(istream& is, Complex& C);
  2046. //  friend ostream& operator<<(ostream& os, const Complex& C);
  2047. //};
  2048. //
  2049. //istream& operator>>(istream& is, Complex& C)
  2050. //{
  2051. //  cout << "Enter real: ";
  2052. //  is >> C.real;
  2053. //  cout << "Enter im: ";
  2054. //  is >> C.imag;
  2055. //  return is;
  2056. //}
  2057. //
  2058. //ostream& operator<<(ostream& os, const Complex& C)
  2059. //{
  2060. //  os << "Real = " << C.real << "\tImag = " << C.imag << endl;
  2061. //  return os;
  2062. //}
  2063. //
  2064. //Complex::Complex(float r, float i)
  2065. //{
  2066. //  real = r;
  2067. //  imag = i;
  2068. //}
  2069. //
  2070. //Complex Complex::operator+(const Complex& C) const
  2071. //{
  2072. //  return Complex(real + C.real, imag + C.imag);
  2073. //}
  2074. //
  2075. //Complex Complex::operator-(const Complex& C) const
  2076. //{
  2077. //  return Complex(real - C.real, imag - C.imag);
  2078. //}
  2079. //
  2080. //Complex Complex::operator*(const Complex& C) const
  2081. //{
  2082. //  return Complex(real * C.real - imag * C.imag, real * C.imag + imag * C.real);
  2083. //}
  2084. //
  2085. //Complex Complex::operator*(const float mult) const
  2086. //{
  2087. //  return Complex(real * mult, imag * mult);
  2088. //}
  2089. //
  2090. //Complex Complex::operator-() const
  2091. //{
  2092. //  return Complex(-real, -imag);
  2093. //}
  2094. //
  2095. //Complex operator*(const float mult, const Complex& C)
  2096. //{
  2097. //  return C * mult;
  2098. //}
  2099. //
  2100. //int main()
  2101. //{
  2102. //  Complex a(3.0, 4.0);
  2103. //  Complex c;//(0.0, 0.0);
  2104. //  cout << "a: " << a;
  2105. //  cin >> c;
  2106. //  cout << "c: " << c;
  2107. //  cout << "-c: " << -c;
  2108. //  cout << "a + c" << a + c;
  2109. //  cout << "a - c" << a - c;
  2110. //  cout << "a * c" << a * c;
  2111. //  cout << "2 * c" << 2 * c;
  2112. //  cout << "c * 2" << c * 2;
  2113. //  cout << c;
  2114. //
  2115. //  return 0;
  2116. //}
  2117.  
  2118. //#include  <iostream>
  2119. //#include <cstring>
  2120. //#include <string>
  2121. //#include <cstdlib>
  2122. //
  2123. //using namespace std;
  2124. //#define _crt_secure_no_warnings
  2125. //#pragma warning(disable:4996)
  2126. //class Cow
  2127. //{
  2128. //  char name[20];
  2129. //  char* hobby;
  2130. //  double weight;
  2131. //public:
  2132. //  Cow();
  2133. //  Cow(const char* nm, const char* ho, double wt);
  2134. //  Cow(const Cow& c);
  2135. //  ~Cow();
  2136. //  Cow& operator=(const Cow& c);
  2137. //  void ShowCow() const;
  2138. //};
  2139. //
  2140. //Cow::Cow()
  2141. //{
  2142. //  name[0] = '\0';
  2143. //  hobby = new char [1];
  2144. //  hobby[0] = '\0';
  2145. //  weight = 0.0;
  2146. //}
  2147. //
  2148. //Cow::Cow(const char* nm, const char* ho, double wt)
  2149. //{
  2150. //  strncpy(name, nm, 20);
  2151. //  size_t len = strlen(ho);
  2152. //  hobby = new char[len + 1];
  2153. //  strncpy(hobby, ho, len);
  2154. //  hobby[len] = '\0';
  2155. //  weight = wt;
  2156. //}
  2157. //
  2158. //Cow::Cow(const Cow& c)
  2159. //{
  2160. //  weight = c.weight;
  2161. //  strncpy(name, c.name, 20);
  2162. //  name[strlen(c.name)] = '\0';
  2163. //  delete [] hobby;
  2164. //  size_t len = strlen(c.hobby);
  2165. //  hobby = new char[len + 1];
  2166. //  strncpy(hobby, c.hobby, len);
  2167. //  hobby[len] = '\0';
  2168. //}
  2169. //
  2170. //Cow::~Cow()
  2171. //{
  2172. //  weight = 0.0;
  2173. //  name[0] = '\0';
  2174. //  delete[] hobby;
  2175. //  hobby = nullptr;
  2176. //}
  2177. //
  2178. //Cow& Cow::operator=(const Cow& c)
  2179. //{
  2180. //  if (this == &c)
  2181. //      return *this;
  2182. //  weight = c.weight;
  2183. //  strncpy(name, c.name, 20);
  2184. //  name[strlen(c.name)] = '\0';
  2185. //  delete[] hobby;
  2186. //  int len = strlen(c.hobby);
  2187. //  hobby = new char[len + 1];
  2188. //  strncpy(hobby, c.hobby, len);
  2189. //  hobby[len] = '\0';
  2190. //  return *this;
  2191. //}
  2192. //
  2193. //void Cow::ShowCow() const
  2194. //{
  2195. //  cout << "\nName = " << name << "\tweight = " << weight << "\thobby = " << hobby;
  2196. //}
  2197. //
  2198. //int main()
  2199. //{
  2200. //  Cow A;
  2201. //  A.ShowCow();
  2202. //  Cow B("Felicia", "Chess", 20.0);
  2203. //  B.ShowCow();
  2204. //  A = B;
  2205. //  A.ShowCow();
  2206. //
  2207. //  return 0;
  2208. //}
  2209.  
  2210. //#include <iostream>
  2211. //#include <cctype>
  2212. //#include <cstring>
  2213. //
  2214. //using namespace std;
  2215. //
  2216. //#define _crt_secure_no_warnings
  2217. //#pragma warning(disable:4996)
  2218. //
  2219. //class String
  2220. //{
  2221. //private:
  2222. //  char* str;
  2223. //  int len;
  2224. //  static int numOfStrings;
  2225. //public:
  2226. //  String();
  2227. //  String(const char* s);
  2228. //  String(const String&);
  2229. //  ~String();
  2230. //  int length() const { return len; }
  2231. //  static int HowMany();
  2232. //
  2233. //  void stringlow();
  2234. //  void stringup();
  2235. //  int howManyChars(char ch);
  2236. //
  2237. //  String& operator=(const String&);
  2238. //  String& operator=(const char*);
  2239. //  char& operator[](int i);
  2240. //  const char& operator[](int i) const;
  2241. //  String operator+(const String& st);
  2242. //  String operator+(const char* str);
  2243. //
  2244. //  friend String operator+(const char* str, const String& st);
  2245. //  friend bool operator<(const String& st, const String& st2);
  2246. //  friend bool operator>(const String& st, const String& st2);
  2247. //  friend bool operator==(const String& st, const String& st2);
  2248. //  friend ostream& operator<<(ostream& os, const String& st);
  2249. //  friend istream& operator>>(istream& is, String& st);   
  2250. //};
  2251. //
  2252. //int String::numOfStrings = 0;
  2253. //
  2254. //String operator+(const char* str, const String& st)
  2255. //{
  2256. //  String temp;
  2257. //  temp.len = st.len + strlen(str);
  2258. //  temp.str = new char[temp.len + 1];
  2259. //  strncpy(temp.str, str, strlen(str));
  2260. //  temp.str[strlen(str)] = '\0';
  2261. //  strncat(temp.str, st.str, st.len);
  2262. //  temp.str[temp.len] = '\0';
  2263. //  return temp;
  2264. //}
  2265. //
  2266. //String String::operator+(const char* st)
  2267. //{
  2268. //  String temp;
  2269. //  temp.len = len + strlen(st);
  2270. //  temp.str = new char[temp.len + 1];
  2271. //  strncpy(temp.str, str, len);
  2272. //  temp.str[len] = '\0';
  2273. //  strncat(temp.str, st, strlen(st));
  2274. //  temp.str[temp.len] = '\0';
  2275. //  return temp;
  2276. //}
  2277. //
  2278. //void String::stringlow()
  2279. //{
  2280. //  int i = 0;
  2281. //  while (str[i] != '\0')
  2282. //  {
  2283. //      if(isupper(str[i]))
  2284. //          str[i] = tolower(str[i]);
  2285. //      ++i;
  2286. //  }
  2287. //}
  2288. //
  2289. //void String::stringup()
  2290. //{
  2291. //  int i = 0;
  2292. //  while (str[i] != '\0')
  2293. //  {
  2294. //      if (islower(str[i]))
  2295. //          str[i] = toupper(str[i]);
  2296. //      ++i;
  2297. //  }
  2298. //}
  2299. //
  2300. //int String::howManyChars(char ch)
  2301. //{
  2302. //  int i = 0;
  2303. //  int count = 0;
  2304. //  while (str[i] != '\0')
  2305. //  {
  2306. //      if (str[i] == ch)
  2307. //          ++count;
  2308. //      ++i;
  2309. //  }
  2310. //  return count;
  2311. //}
  2312. //
  2313. //String String::operator+(const String& st)
  2314. //{
  2315. //  String temp;
  2316. //  temp.len = len + st.len;
  2317. //  temp.str = new char[temp.len + 1];
  2318. //  strncpy(temp.str, str, len);
  2319. //  temp.str[len] = '\0';
  2320. //  strncat(temp.str, st.str, st.len);
  2321. //  temp.str[temp.len] = '\0';
  2322. //  return temp;
  2323. //}
  2324. //
  2325. //int String::HowMany()
  2326. //{
  2327. //  return numOfStrings;
  2328. //}
  2329. //
  2330. //String::String(const char* s)
  2331. //{
  2332. //  len = strlen(s);
  2333. //  str = new char[len + 1];
  2334. //  strncpy(str, s, len);
  2335. //  str[len] = '\0';
  2336. //  ++numOfStrings;
  2337. //}
  2338. //
  2339. //String::String()
  2340. //{
  2341. //  len = 1;
  2342. //  str = new char[len + 1];
  2343. //  str[0] = str[1] = '\0';
  2344. //  ++numOfStrings;
  2345. //}
  2346. //
  2347. //String::String(const String& st)
  2348. //{
  2349. //  len = st.len;
  2350. //  str = new char[len + 1];
  2351. //  strncpy(str, st.str, len);
  2352. //  ++numOfStrings;
  2353. //}
  2354. //
  2355. //String::~String()
  2356. //{
  2357. //  --numOfStrings;
  2358. //  delete[] str;
  2359. //  len = 4;
  2360. //  str = nullptr;
  2361. //}
  2362. //
  2363. //String& String::operator=(const String& st)
  2364. //{
  2365. //  if (this == &st)
  2366. //      return *this;
  2367. //  delete[] str;
  2368. //  len = st.len;
  2369. //  str = new char[len + 1];
  2370. //  strncpy(str, st.str, len);
  2371. //  str[len] = '\0';
  2372. //  return *this;
  2373. //}
  2374. //
  2375. //String& String::operator=(const char* s)
  2376. //{
  2377. //  delete[] str;
  2378. //  len = strlen(s);
  2379. //  str = new char[len + 1];
  2380. //  strncpy(str, s, len);
  2381. //  str[len] = '\0';
  2382. //  return *this;
  2383. //}
  2384. //
  2385. //char& String::operator[](int i)
  2386. //{
  2387. //  return str[i];
  2388. //}
  2389. //
  2390. //const char& String::operator[](int i) const
  2391. //{
  2392. //  return str[i];
  2393. //}
  2394. //
  2395. //bool operator<(const String& st1, const String& st2)
  2396. //{
  2397. //  return (strcmp(st1.str, st2.str) < 0);
  2398. //}
  2399. //
  2400. //bool operator>(const String& st1, const String& st2)
  2401. //{
  2402. //  return st2.str < st1.str;
  2403. //}
  2404. //
  2405. //bool operator==(const String& st1, const String& st2)
  2406. //{
  2407. //  return (strcmp(st1.str, st2.str) == 0);
  2408. //}
  2409. //
  2410. //ostream& operator<<(ostream& os, const String& st)
  2411. //{
  2412. //  os << st.str;
  2413. //  return os;
  2414. //}
  2415. //
  2416. //istream& operator>>(istream& is, String& st)
  2417. //{
  2418. //  char temp[100];
  2419. //  is.get(temp, 100);
  2420. //  while (is.get() != '\n')
  2421. //      continue;
  2422. //  st = temp;
  2423. //  return is;
  2424. //}
  2425. //
  2426. //int main()
  2427. //{
  2428. //
  2429. //  String s1(" and I am a C++ student.");
  2430. //  String s2 = "Please enter your name: ";
  2431. //  String s3;
  2432. //  cout << s2;
  2433. //  cin >> s3;
  2434. //  s2 = "My name is " + s3;
  2435. //  cout << s2 << ".\n";
  2436. //  s2 = s2 + s1;
  2437. //  s2.stringup();
  2438. //  cout << "The string\n" << s2 << "\ncontains " << s2.howManyChars('A') << " 'A' characters in it.\n";
  2439. //  s1 = "red";
  2440. //  String rgb[3] = { String(s1), String("green"), String("blue") };
  2441. //  cout << "Enter the name of a primaty color for mixing light: ";
  2442. //  String ans;
  2443. //  bool success = false;
  2444. //  while (cin >> ans)
  2445. //  {
  2446. //      ans.stringlow();
  2447. //      for (int i = 0; i < 3; ++i)
  2448. //      {
  2449. //          if (ans == rgb[i])
  2450. //          {
  2451. //              cout << "That's right!\n";
  2452. //              success = true;
  2453. //              break;
  2454. //          }
  2455. //      }
  2456. //      if (success)
  2457. //          break;
  2458. //      else
  2459. //          cout << "Try agein!\n";
  2460. //  }
  2461. //  cout << "Bye\n";
  2462. //  return 0;
  2463. //}
  2464.  
  2465. //#include <iostream>
  2466. //#include <string>
  2467. //using namespace std;
  2468. //#define _crt_secure_no_warnings
  2469. //#pragma warning(disable:4996)
  2470. //class Stock
  2471. //{
  2472. //  char *company;
  2473. //  int shares;
  2474. //  double share_val;
  2475. //  double total_val;
  2476. //  void set_tot() { total_val = shares * share_val; }
  2477. //public:
  2478. //  Stock();
  2479. //  Stock(const char* co, long n = 0, double pr = 0.0);
  2480. //  ~Stock();
  2481. //  void buy(long num, double price);
  2482. //  void sell(long num, double price);
  2483. //  void update(double price);
  2484. //  void show() const;
  2485. //  friend ostream& operator<<(ostream& os, const Stock& s);
  2486. //  const Stock& topval(const Stock& s) const;
  2487. //};
  2488. //
  2489. //ostream& operator<<(ostream& os, const Stock& s)
  2490. //{
  2491. //  os << "Company: " << s.company;
  2492. //  os << " Shares: " << s.shares << endl;
  2493. //  os << " Share price: $" << s.share_val;
  2494. //  os << " Total worth: $" << s.total_val << endl;
  2495. //  return os;
  2496. //}
  2497. //
  2498. //Stock::Stock()
  2499. //{
  2500. //  company = new char[8];
  2501. //  strcpy(company, "no name");
  2502. //  shares = 0;
  2503. //  share_val = 0.0;
  2504. //  total_val = 0.0;
  2505. //}
  2506. //
  2507. //Stock::Stock(const char* co, long n, double pr)
  2508. //{
  2509. //  int len = strlen(co);
  2510. //  company = new char[len + 1];
  2511. //  strncpy(company, co, len);
  2512. //  company[len] = '\0';
  2513. //  if (n < 0)
  2514. //  {
  2515. //      cout << "Number of shares can't be negative; " << company << " shares set to 0.\n";
  2516. //      shares = 0;
  2517. //  }
  2518. //  else
  2519. //      shares = n;
  2520. //  share_val = pr;
  2521. //  set_tot();
  2522. //}
  2523. //
  2524. //Stock::~Stock()
  2525. //{
  2526. //  delete[] company;
  2527. //  company = nullptr;
  2528. //}
  2529. //
  2530. //void Stock::buy(long num, double price)
  2531. //{
  2532. //  if (num < 0)
  2533. //      cout << "Number of shares purchased can't be negative. Transaction is aborted.\n";
  2534. //  else
  2535. //  {
  2536. //      shares += num;
  2537. //      share_val = price;
  2538. //      set_tot();
  2539. //  }
  2540. //}
  2541. //
  2542. //void Stock::sell(long num, double price)
  2543. //{
  2544. //  if (num < 0)
  2545. //      cout << "Number can't be negative. Abort\n";
  2546. //  else if (num > shares)
  2547. //      cout << "Too much. Abort\n";
  2548. //  else
  2549. //  {
  2550. //      shares -= num;
  2551. //      share_val = price;
  2552. //      set_tot();
  2553. //  }
  2554. //}
  2555. //
  2556. //void Stock::update(double price)
  2557. //{
  2558. //  share_val = price;
  2559. //  set_tot();
  2560. //}
  2561. //
  2562. //void Stock::show() const
  2563. //{
  2564. //  cout << "Company: " << company;
  2565. //  cout << " Shares: " << shares << endl;
  2566. //  cout << " Share price: $" << share_val;
  2567. //  cout << " Total worth: $" << total_val << endl;
  2568. //}
  2569. //
  2570. //const Stock& Stock::topval(const Stock& s) const
  2571. //{
  2572. //  if (s.total_val > total_val)
  2573. //      return s;
  2574. //  else
  2575. //      return *this;
  2576. //}
  2577. //
  2578. //const int STKS = 4;
  2579. //
  2580. //int main()
  2581. //{
  2582. //  Stock stocks[STKS] = {
  2583. //      Stock("NanoSmart", 12, 20.0),
  2584. //      Stock("Boffo Objects", 200, 2.0),
  2585. //      Stock("Monolithic Obelisks", 130, 3.25),
  2586. //      Stock("Fleep Enterprises", 60, 6.5)
  2587. //  };
  2588. //  cout << "Stock holdings:\n";
  2589. //  for (int st = 0; st < STKS; ++st)
  2590. //      cout << stocks[st];
  2591. //
  2592. //  const Stock* top = &stocks[0];
  2593. //  for (int st = 1; st < STKS; ++st)
  2594. //      top = &top->topval(stocks[st]);
  2595. //
  2596. //  cout << "Most valuable holding: \n";
  2597. //  cout << *top;
  2598. //}
  2599.  
  2600. //#include <iostream>
  2601. //using namespace std;
  2602. //typedef unsigned long Item;
  2603. //
  2604. //class Stack
  2605. //{
  2606. //  enum {MAX = 10};
  2607. //  Item* pitems;
  2608. //  int size;
  2609. //  int top;
  2610. //public:
  2611. //  Stack(int n = 10);
  2612. //  Stack(const Stack& st);
  2613. //  ~Stack();
  2614. //  bool isempty() const;
  2615. //  bool isfull() const;
  2616. //  bool push(const Item& item);
  2617. //  bool pop(Item& item);
  2618. //  Stack& operator=(const Stack& st);
  2619. //};
  2620. //
  2621. //Stack::Stack(int n)
  2622. //{
  2623. //  pitems = new Item[n];
  2624. //  size = 0;
  2625. //}
  2626. //
  2627. //Stack::Stack(const Stack& st)
  2628. //{
  2629. //  size = st.size;
  2630. //  delete[] pitems;
  2631. //  pitems = new Item[size];
  2632. //  for (int i = 0; i < size; ++i)
  2633. //      pitems[i] = st.pitems[i];
  2634. //  top = pitems[size - 1];
  2635. //}
  2636. //
  2637. //Stack::~Stack()
  2638. //{
  2639. //  delete[] pitems;
  2640. //  pitems = nullptr;
  2641. //}
  2642. //
  2643. //bool Stack::isempty() const
  2644. //{
  2645. //  return size == 0;
  2646. //}
  2647. //
  2648. //bool Stack::isfull() const
  2649. //{
  2650. //  return size == Stack::MAX;
  2651. //}
  2652. //
  2653. //bool Stack::push(const Item& item)
  2654. //{
  2655. //  if (size == Stack::MAX)
  2656. //      return false;
  2657. //  Stack temp(*this);
  2658. //  delete[] pitems;
  2659. //  size = temp.size + 1;
  2660. //  pitems = new Item[size];
  2661. //  for (int i = 0; i < size - 1; ++i)
  2662. //      pitems[i] = temp.pitems[i];
  2663. //  pitems[size - 1] = item;
  2664. //  top = size;
  2665. //  return true;
  2666. //}
  2667. //
  2668. //bool Stack::pop(Item& item)
  2669. //{
  2670. //  if (size == 0)
  2671. //      return false;
  2672. //  Stack temp(*this);
  2673. //  item = pitems[size - 1];
  2674. //  delete[] pitems;
  2675. //  size -= 1;
  2676. //  pitems = new Item[size];
  2677. //  for (int i = 0; i < size; ++i)
  2678. //      pitems[i] = temp.pitems[i];
  2679. //  return true;
  2680. //}
  2681. //
  2682. //Stack& Stack::operator=(const Stack& st)
  2683. //{
  2684. //  if (this == &st)
  2685. //      return *this;
  2686. //  size = st.size;
  2687. //  delete[] pitems;
  2688. //  pitems = new Item[size];
  2689. //  for (int i = 0; i < size; ++i)
  2690. //      pitems[i] = st.pitems[i];
  2691. //  top = pitems[size - 1];
  2692. //  return *this;
  2693. //}
  2694. //
  2695. //int main()
  2696. //{
  2697. //  Stack st;
  2698. //  char ch;
  2699. //  unsigned long po;
  2700. //  cout << "A, p, q\n";
  2701. //  while (cin >> ch && toupper(ch) != 'Q')
  2702. //  {
  2703. //      while (cin.get() != '\n')
  2704. //          continue;
  2705. //      if (!isalpha(ch))
  2706. //      {
  2707. //          cout << '\a';
  2708. //          continue;
  2709. //      }
  2710. //      switch (ch)
  2711. //      {
  2712. //      case'A':
  2713. //      case'a':
  2714. //          cout << "Enter a PO: ";
  2715. //          cin >> po;
  2716. //          if (st.isfull())
  2717. //              cout << "stack already full\n";
  2718. //          else
  2719. //              st.push(po);
  2720. //          break;
  2721. //      case'P':
  2722. //      case'p':
  2723. //          if (st.isempty())
  2724. //              cout << "stack already empty\n";
  2725. //          else
  2726. //          {
  2727. //              st.pop(po);
  2728. //              cout << "PO #" << po << " popped\n";
  2729. //          }
  2730. //          break;
  2731. //      }
  2732. //      cout << "Pjkg";
  2733. //  }
  2734. //  cout << "Bye\n";
  2735. //  return 0;
  2736. //}
  2737.  
  2738. //#include <iostream>
  2739. //using namespace std;
  2740. //#define _crt_secure_no_warnings
  2741. //#pragma warning(disable:4996)
  2742. //
  2743. //class Cd
  2744. //{
  2745. //  char* performers;
  2746. //  char*  label;
  2747. //  int selections;
  2748. //  double playtime;
  2749. //public:
  2750. //  Cd(const char* s1, const char* s2, int n, double x);
  2751. //  Cd(const Cd& d);
  2752. //  Cd();
  2753. //  virtual ~Cd();
  2754. //  virtual void Report() const;
  2755. //  Cd& operator=(const Cd& d);
  2756. //};
  2757. //
  2758. //class Classic : public Cd
  2759. //{
  2760. //  char* name;
  2761. //public:
  2762. //  Classic();
  2763. //  Classic(const Classic& d);
  2764. //  Classic(const char* s1, const char* s2, const char* s3, int n, double x);
  2765. //  Classic& operator=(const Classic& d);
  2766. //  void Report() const final;
  2767. //  ~Classic();
  2768. //};
  2769. //
  2770. //Classic::Classic() : Cd()
  2771. //{
  2772. //  const char* name_ = "none";
  2773. //  name = new char[strlen(name_) + 1];
  2774. //  strncpy(name, name_, strlen(name_));
  2775. //  name[strlen(name_)] = '\0';
  2776. //}
  2777. //
  2778. //Classic::~Classic()
  2779. //{
  2780. //  delete[] name;
  2781. //  name = nullptr;
  2782. //}
  2783. //
  2784. //Classic::Classic(const char* s1, const char* s2, const char* s3, int n, double x) :
  2785. //  Cd(s1, s2, n, x)
  2786. //{
  2787. //  name = new char[strlen(s3) + 1];
  2788. //  strncpy(name, s3, strlen(s3));
  2789. //  name[strlen(s3)] = '\0';
  2790. //}
  2791. //
  2792. //Cd::Cd(const char* s1, const char* s2, int n, double x)
  2793. //{
  2794. //  performers = new char[strlen(s1) + 1];
  2795. //  strncpy(performers, s1, strlen(s1));
  2796. //  performers[strlen(s1)] = '\0';
  2797. //  label = new char[strlen(s2) + 1];
  2798. //  strncpy(label , s2, strlen(s2));
  2799. //  label[strlen(s2)] = '\0';
  2800. //  selections = n;
  2801. //  playtime = x;
  2802. //}
  2803. //
  2804. //Cd::Cd(const Cd& d)
  2805. //{
  2806. //  performers = new char[strlen(d.performers) + 1];
  2807. //  strncpy(performers, d.performers, strlen(d.performers));
  2808. //  performers[strlen(d.performers)] = '\0';
  2809. //  label = new char[strlen(d.label) + 1];
  2810. //  strncpy(label, d.label, strlen(d.label));
  2811. //  label[strlen(d.label)] = '\0';
  2812. //  selections = d.selections;
  2813. //  playtime = d.playtime;
  2814. //}
  2815. //
  2816. //Cd::Cd()
  2817. //{
  2818. //  const char* name_ = "none";
  2819. //  performers = new char[strlen(name_) + 1];
  2820. //  strncpy(performers, name_, strlen(name_));
  2821. //  performers[strlen(name_)] = '\0';
  2822. //  label = new char[strlen(name_) + 1];
  2823. //  strncpy(label, name_, strlen(name_));
  2824. //  label[strlen(name_)] = '\0';
  2825. //  selections = 0;
  2826. //  playtime = 0.0;
  2827. //}
  2828. //
  2829. //void Cd::Report() const
  2830. //{
  2831. //  cout << "Performers = " << performers << "\nLabel = " << label
  2832. //      << "\nSelections = " << selections << "\nPlaytime = " << playtime;
  2833. //}
  2834. //
  2835. //void Classic::Report() const
  2836. //{
  2837. //  Cd::Report();
  2838. //  cout << "\nName = " << name << endl;
  2839. //}
  2840. //
  2841. //Cd& Cd::operator=(const Cd& d)
  2842. //{
  2843. //  if (this == &d)
  2844. //      return *this;
  2845. //  delete[] performers;
  2846. //  performers = new char[strlen(d.performers) + 1];
  2847. //  strncpy(performers, d.performers, strlen(d.performers));
  2848. //  performers[strlen(d.performers)] = '\0';
  2849. //  delete[] label;
  2850. //  label = new char[strlen(d.label) + 1];
  2851. //  strncpy(label, d.label, strlen(d.label));
  2852. //  label[strlen(d.label)] = '\0';
  2853. //  selections = d.selections;
  2854. //  playtime = d.playtime;
  2855. //  return *this;
  2856. //}
  2857. //
  2858. //Classic& Classic::operator=(const Classic& d)
  2859. //{
  2860. //  if (this == &d)
  2861. //      return *this;
  2862. //  Cd::operator=(d);
  2863. //  delete[] name;
  2864. //  name = new char[strlen(d.name) + 1];
  2865. //  strncpy(name, d.name, strlen(d.name));
  2866. //  name[strlen(d.name)] = '\0';
  2867. //  return *this;
  2868. //}
  2869. //
  2870. //Classic::Classic(const Classic& d) : Cd(d)
  2871. //{
  2872. //  name = new char[strlen(d.name) + 1];
  2873. //  strncpy(name, d.name, strlen(d.name));
  2874. //  name[strlen(d.name)] = '\0';
  2875. //}
  2876. //
  2877. //Cd::~Cd()
  2878. //{
  2879. //  delete[] performers;
  2880. //  performers = nullptr;
  2881. //  delete[] label;
  2882. //  label = nullptr;
  2883. //}
  2884. //
  2885. //void Bravo(const Cd& disk)
  2886. //{
  2887. //  disk.Report();
  2888. //}
  2889. //
  2890. //int main()
  2891. //{
  2892. //  Cd c1("Beatles", "Capitol", 14, 35.5 );
  2893. //  Classic c2 = Classic("Piano Sonata in B flat, Fantasia in C",
  2894. //      "Alfred Brendel", "Phillips", 2, 57.17);
  2895. //  Cd* pcd = &c1;
  2896. //  cout << "\nUsing object directly: \n";
  2897. //  c1.Report();
  2898. //  cout << endl;
  2899. //  c2.Report();
  2900. //  cout << "\nUsing pointer: \n";
  2901. //  pcd->Report();
  2902. //  cout << endl;
  2903. //  pcd = &c2;
  2904. //  pcd->Report();
  2905. //  cout << "\nCalling a function with a Cd reference: \n";
  2906. //  Bravo(c1);
  2907. //  cout << endl;
  2908. //  Bravo(c2);
  2909. //  cout << "\nTesting assignment: \n";
  2910. //  Classic copy;
  2911. //  copy = c2;
  2912. //  cout << endl;
  2913. //  copy.Report();
  2914. //  return 0;
  2915. //}
  2916.  
  2917. //#include <iostream>
  2918. //using namespace std;
  2919. //#define _crt_secure_no_warnings
  2920. //#pragma warning(disable:4996)
  2921. //
  2922. //class AbsDma
  2923. //{
  2924. //protected:
  2925. //  char* label;
  2926. //  int rating;
  2927. //public:
  2928. //  AbsDma(const char* l = "none", int r = 0);
  2929. //  AbsDma(const AbsDma& ra);
  2930. //  virtual ~AbsDma();
  2931. //  AbsDma& operator=(const AbsDma& ra);
  2932. //  virtual void View() const = 0;
  2933. //};
  2934. //
  2935. //class baseDma : public AbsDma
  2936. //{
  2937. //public:
  2938. //  baseDma(const char* l = "none", int r = 0);
  2939. //  baseDma(const baseDma& rb);
  2940. //  ~baseDma();
  2941. //  baseDma& operator=(const baseDma& ra);
  2942. //  void View() const;
  2943. //};
  2944. //
  2945. //class hasDma : public AbsDma
  2946. //{
  2947. //  char* style;
  2948. //public:
  2949. //  hasDma(const char* s = "none", const char* l = "none", int r = 0);
  2950. //  hasDma(const hasDma& rh, const char* s);
  2951. //  ~hasDma();
  2952. //  hasDma& operator=(const hasDma& rs);
  2953. //  void View() const;
  2954. //};
  2955. //
  2956. //class lacksDma : public AbsDma
  2957. //{
  2958. //private:
  2959. //  static const int COL_LEN = 40;
  2960. //  char color[COL_LEN];
  2961. //public:
  2962. //  lacksDma(const char* col = "none", const char* lab = "none", int r = 0);
  2963. //  lacksDma(const lacksDma& ra, const char* col = "none");
  2964. //  ~lacksDma();
  2965. //  lacksDma& operator=(const lacksDma& rs);
  2966. //  void View() const;
  2967. //};
  2968. //
  2969. //AbsDma::AbsDma(const char* l, int r)
  2970. //{
  2971. //  int size = strlen(l);
  2972. //  label = new char[size + 1];
  2973. //  strncpy(label, l, size);
  2974. //  label[size] = '\0';
  2975. //  rating = r;
  2976. //}
  2977. //
  2978. //AbsDma::~AbsDma()
  2979. //{
  2980. //  delete[]label;
  2981. //  label = nullptr;
  2982. //}
  2983. //
  2984. //AbsDma::AbsDma(const AbsDma& ra)
  2985. //{
  2986. //  int size = strlen(ra.label);
  2987. //  label = new char[size + 1];
  2988. //  strncpy(label, ra.label, size);
  2989. //  label[size] = '\0';
  2990. //  rating = ra.rating;
  2991. //}
  2992. //
  2993. //AbsDma& AbsDma::operator=(const AbsDma& ra)
  2994. //{
  2995. //  if (this == &ra)
  2996. //      return *this;
  2997. //  delete[] label;
  2998. //  int size = strlen(ra.label);
  2999. //  label = new char[size + 1];
  3000. //  strncpy(label, ra.label, size);
  3001. //  label[size] = '\0';
  3002. //  rating = ra.rating;
  3003. //  return *this;
  3004. //}
  3005. //
  3006. //baseDma::baseDma(const char *l, int r) : AbsDma(l, r)
  3007. //{}
  3008. //
  3009. //baseDma::baseDma(const baseDma& rb) : AbsDma(rb)
  3010. //{}
  3011. //
  3012. //baseDma::~baseDma()
  3013. //{}
  3014. //
  3015. //baseDma& baseDma::operator=(const baseDma& ra)
  3016. //{
  3017. //  if (this == &ra)
  3018. //      return *this;
  3019. //  AbsDma::operator=(ra);
  3020. //  return *this;
  3021. //}
  3022. //
  3023. //void baseDma::View() const
  3024. //{
  3025. //  cout << "Label = " << label << endl << "   Rating = " << rating << endl;
  3026. //}
  3027. //
  3028. //lacksDma::lacksDma(const char* col, const char* lab, int r) : AbsDma(lab, r)
  3029. //{
  3030. //  strncpy(color, col, COL_LEN);
  3031. //  color[strlen(col)] = '\0';
  3032. //}
  3033. //
  3034. //lacksDma::lacksDma(const lacksDma& ra, const char* col) : AbsDma(ra)
  3035. //{
  3036. //  strncpy(color, col, COL_LEN);
  3037. //  color[strlen(col)] = '\0';
  3038. //}
  3039. //
  3040. //lacksDma::~lacksDma()
  3041. //{
  3042. //  color[0] = '\0';
  3043. //}
  3044. //
  3045. //lacksDma& lacksDma::operator=(const lacksDma& rs)
  3046. //{
  3047. //  if (this == &rs)
  3048. //      return *this;
  3049. //  AbsDma::operator=(rs);
  3050. //  strncpy(color, rs.color, COL_LEN);
  3051. //  color[strlen(rs.color)] = '\0';
  3052. //  return *this;
  3053. //}
  3054. //
  3055. //void lacksDma::View() const
  3056. //{
  3057. //  cout << "Label = " << label << endl << "   Rating = " << rating << "      Color = " << color << endl;
  3058. //}
  3059. //
  3060. //hasDma::hasDma(const char* s, const char* l, int r) : AbsDma(l, r)
  3061. //{
  3062. //  int size = strlen(s);
  3063. //  style = new char[size + 1];
  3064. //  strncpy(style, s, size);
  3065. //  style[size] = '\0';
  3066. //}
  3067. //
  3068. //hasDma::hasDma(const hasDma& rh, const char* s) : AbsDma(rh)
  3069. //{
  3070. //  int size = strlen(s);
  3071. //  style = new char[size + 1];
  3072. //  strncpy(style, s, size);
  3073. //  style[size] = '\0';
  3074. //}
  3075. //
  3076. //hasDma::~hasDma()
  3077. //{
  3078. //  delete[] style;
  3079. //  style = nullptr;
  3080. //}
  3081. //
  3082. //hasDma& hasDma::operator=(const hasDma& rh)
  3083. //{
  3084. //  if (this == &rh)
  3085. //      return *this;
  3086. //  AbsDma::operator=(rh);
  3087. //  delete[] style;;
  3088. //  int size = strlen(rh.style);
  3089. //  style = new char[size + 1];
  3090. //  strncpy(style, rh.style, size);
  3091. //  style[size] = '\0';
  3092. //  return *this;
  3093. //}
  3094. //
  3095. //void hasDma::View() const
  3096. //{
  3097. //  cout << "Label = " << label << endl << "   Rating = " << rating << "      Style = " << style << endl;
  3098. //}
  3099. //
  3100. //void Show(const AbsDma *r)
  3101. //{
  3102. //  r->View();
  3103. //}
  3104. //
  3105. //int main()
  3106. //{
  3107. //  baseDma shirt("Portabelly", 8), shirt2;
  3108. //  lacksDma balloon("red", "Blimpo", 4), balloon2;
  3109. //  hasDma map("Mercerator", "Buffalo Keys", 5), map2;
  3110. // 
  3111. //  cout << "\n-----------------------------Basic--------------------------------------\n";
  3112. // 
  3113. //  shirt.View();
  3114. //  balloon.View();
  3115. //  map.View();
  3116. // 
  3117. //  cout << "\n---------------------------------Second----------------------------------\n";
  3118. // 
  3119. //  shirt2.View();
  3120. //  balloon2.View();
  3121. //  map2.View();
  3122. //
  3123. //  cout << "\n-------------------------------Dorivnie-----------------------------------\n";
  3124. //
  3125. //  shirt2 = shirt;
  3126. //  balloon2 = balloon;
  3127. //  map2 = map;
  3128. //
  3129. //  shirt2.View();
  3130. //  balloon2.View();
  3131. //  map2.View();
  3132. //
  3133. //  cout << "\n-------------------------------Pointer--------------------------------\n";
  3134. //
  3135. //  AbsDma * PA[3] = { &shirt, &balloon, &map };
  3136. //  for (int i = 0; i < 3; ++i)
  3137. //      PA[i]->View();
  3138. //
  3139. //  cout << "\n-------------------------------Function-------------------------------\n";
  3140. //
  3141. //  for (int i = 0; i < 3; ++i)
  3142. //      Show(PA[i]);
  3143. //
  3144. //  cout << "\n----------------------------------Pointer 2---------------------------\n";
  3145. //
  3146. //  AbsDma* pAbs[3];
  3147. //
  3148. //  pAbs[0] = new baseDma("Portabelly", 8);
  3149. //  pAbs[1] = new lacksDma("red", "Blimpo", 4);
  3150. //  pAbs[2] = new hasDma("Mercerator", "Buffalo Keys", 5);
  3151. //
  3152. //  for (int i = 0; i < 3; ++i)
  3153. //      pAbs[i]->View();
  3154. //
  3155. //  cout << "\n-------------------------------------End------------------------------\n";
  3156. //
  3157. //  return 0;
  3158. //}
  3159.  
  3160. //#include <iostream>
  3161. //
  3162. //using namespace std;
  3163. //
  3164. //#define _crt_secure_no_warnings
  3165. //#pragma warning(disable:4996)
  3166. //
  3167. //class Port
  3168. //{
  3169. //  char* brand;
  3170. //  char style[20];
  3171. //  int bottles;
  3172. //public:
  3173. //  Port(const char* br = "none", const char* st = "none", int bot = 0);
  3174. //  Port(const Port& p);
  3175. //  virtual ~Port();
  3176. //  Port& operator=(const Port& p);
  3177. //  Port& operator+=(int b);
  3178. //  Port& operator-=(int b);
  3179. //  int BottleCount() const;
  3180. //  virtual void Show() const;
  3181. //  friend ostream& operator<<(ostream& os, const Port& p);
  3182. //};
  3183. //
  3184. //class VintagePort : public Port
  3185. //{
  3186. //  char* nickname;
  3187. //  int year;
  3188. //public:
  3189. //  VintagePort();
  3190. //  VintagePort(const char* br, int b, const char* nn = "none", int y = 0);
  3191. //  VintagePort(const VintagePort& vp);
  3192. //  ~VintagePort();
  3193. //  VintagePort& operator=(const VintagePort& vp);
  3194. //  void Show() const;
  3195. //  friend ostream& operator<<(ostream& os, const VintagePort& vp);
  3196. //};
  3197. //
  3198. //Port::Port(const char* br, const char* st, int bot)
  3199. //{
  3200. //  int size = strlen(br);
  3201. //  brand = new char[size + 1];
  3202. //  strncpy(brand, br, size);
  3203. //  brand[size] = '\0';
  3204. //  strncpy(style, st, 20);
  3205. //  style[strlen(st)] = '\0';
  3206. //  bottles = bot;
  3207. //}
  3208. //
  3209. //Port::Port(const Port& p)
  3210. //{
  3211. //  int size = strlen(p.brand);
  3212. //  brand = new char[size + 1];
  3213. //  strncpy(brand, p.brand, size);
  3214. //  brand[size] = '\0';
  3215. //  strncpy(style, p.style, 20);
  3216. //  style[strlen(p.style)] = '\0';
  3217. //  bottles = p.bottles;
  3218. //}
  3219. //
  3220. //Port::~Port()
  3221. //{
  3222. //  delete[] brand;
  3223. //  brand = nullptr;
  3224. //  style[0] = '\0';
  3225. //  bottles = 0;
  3226. //}
  3227. //
  3228. //Port& Port::operator=(const Port& p)
  3229. //{
  3230. //  if (this == &p)
  3231. //      return *this;
  3232. //  delete[] brand;
  3233. //  int size = strlen(p.brand);
  3234. //  brand = new char[size + 1];
  3235. //  strncpy(brand, p.brand, size);
  3236. //  brand[size] = '\0';
  3237. //  strncpy(style, p.style, 20);
  3238. //  style[strlen(p.style)] = '\0';
  3239. //  bottles = p.bottles;
  3240. //  return *this;
  3241. //}
  3242. //
  3243. //int Port::BottleCount() const
  3244. //{
  3245. //  return bottles;
  3246. //}
  3247. //
  3248. //void Port::Show() const
  3249. //{
  3250. //  cout << endl;
  3251. //  cout << "Brand    : " << brand << endl;
  3252. //  cout << "Kind     : " << style << endl;
  3253. //  cout << "Bottles  : " << bottles << endl;
  3254. //}
  3255. //
  3256. //ostream& operator<<(ostream& os, const Port& p)
  3257. //{
  3258. //  os << endl << p.brand << ", " << p.style << ", " << p.bottles;
  3259. //  return os;
  3260. //}
  3261. //
  3262. //Port& Port::operator+=(int b)
  3263. //{
  3264. //  bottles += b;
  3265. //  return *this;
  3266. //}
  3267. //
  3268. //Port& Port::operator-=(int b)
  3269. //{
  3270. //  bottles -= b;
  3271. //  return *this;
  3272. //}
  3273. //
  3274. //VintagePort::VintagePort() : Port()
  3275. //{
  3276. //  nickname = new char[1];
  3277. //  nickname[0] = '\0';
  3278. //  year = 0;
  3279. //}
  3280. //
  3281. //VintagePort::VintagePort(const char* br, int b, const char* nn, int y) : Port(br, "vintage", b)
  3282. //{
  3283. //  int size = strlen(nn);
  3284. //  nickname = new char[size + 1];
  3285. //  strncpy(nickname, nn, size);
  3286. //  nickname[size] = '\0';
  3287. //  year = y;
  3288. //}
  3289. //
  3290. //VintagePort::VintagePort(const VintagePort& vp) : Port(vp)
  3291. //{
  3292. //  int size = strlen(vp.nickname);
  3293. //  nickname = new char[size + 1];
  3294. //  strncpy(nickname, vp.nickname, size);
  3295. //  nickname[size] = '\0';
  3296. //  year = vp.year;
  3297. //}
  3298. //
  3299. //VintagePort::~VintagePort()
  3300. //{
  3301. //  delete[] nickname;
  3302. //  nickname = nullptr;
  3303. //}
  3304. //
  3305. //VintagePort& VintagePort::operator=(const VintagePort& vp)
  3306. //{
  3307. //  if (this == &vp)
  3308. //      return *this;
  3309. //  Port::operator=(vp);
  3310. //  delete[] nickname;
  3311. //  int size = strlen(vp.nickname);
  3312. //  nickname = new char[size + 1];
  3313. //  strncpy(nickname, vp.nickname, size);
  3314. //  nickname[size] = '\0';
  3315. //  year = vp.year;
  3316. //  return *this;
  3317. //}
  3318. //
  3319. //void VintagePort::Show() const
  3320. //{
  3321. //  Port::Show();
  3322. //  cout << "Nickname : " << nickname << endl;
  3323. //  cout << "Year     : " << year << endl;
  3324. //}
  3325. //
  3326. //ostream& operator<<(ostream& os, const VintagePort& vp)
  3327. //{
  3328. //  os << dynamic_cast<const Port&>(vp);
  3329. //  os << ", " << vp.nickname << ", " << vp.year;
  3330. //  return os;
  3331. //}
  3332. //
  3333. //int main()
  3334. //{
  3335. //  Port A("Alfa", "tawny", 5);
  3336. //  cout << A << endl;
  3337. //  A.Show();
  3338. //  Port B;
  3339. //  cout << B;
  3340. //  B.Show();
  3341. //  B = A;
  3342. //  cout << B;
  3343. //  B.Show();
  3344. //  VintagePort C("Bravo", 7, "The noble", 1934);
  3345. //  cout << C << endl;
  3346. //  C.Show();
  3347. //  VintagePort D;
  3348. //  cout << D;
  3349. //  D.Show();
  3350. //  D = C;
  3351. //  cout << D;
  3352. //  D.Show();
  3353. //
  3354. //  cout << endl << endl << endl << endl << endl;
  3355. //
  3356. //  A = C;
  3357. //  cout << A;
  3358. //
  3359. //  cout << endl << endl << endl << endl << endl;
  3360. //
  3361. //
  3362. //  B += 5;
  3363. //  cout << B;
  3364. //  B -= 3;
  3365. //  cout << B;
  3366. //
  3367. //  C += 4;
  3368. //  cout << C;
  3369. //  C -= 2;
  3370. //  cout << C;
  3371. //
  3372. //
  3373. //  return 0;
  3374. //}
  3375.  
  3376. //#include <iostream>
  3377. //using std::cout;
  3378. //struct Triangle
  3379. //{
  3380. //  double length = 2.0; // нестатическая инициализация членов
  3381. //  double width = 2.0;
  3382. //};
  3383. //
  3384. //int main()
  3385. //{
  3386. //  Triangle z{ 3.0, 3.0 }; // uniform-инициализация
  3387. //  Triangle p;
  3388. //  cout << z.length << "\t" << z.width << std::endl;
  3389. //  cout << p.length << "\t" << p.width << std::endl;
  3390. //  return 0;
  3391. //
  3392. //  struct Employee
  3393. //  {
  3394. //      short id;
  3395. //      int age;
  3396. //      double salary;
  3397. //  };
  3398. //
  3399. //  Employee john;
  3400. //  john = { 5, 27, 45000.0 }; // только C++11
  3401. //}
  3402.  
  3403. //#include <iostream>
  3404. //
  3405. //using std::cin;
  3406. //using std::cout;
  3407. //using std::endl;
  3408. //
  3409. //int getNum()
  3410. //{
  3411. //  int x;
  3412. //  while (true)
  3413. //  {
  3414. //      cin >> x;
  3415. //      cin.ignore(32767, '\n');
  3416. //      if (cin.fail())
  3417. //      {
  3418. //          cin.clear();
  3419. //          cin.ignore(32767, '\n');
  3420. //          cout << "Bad input. Enter another num: ";
  3421. //      }
  3422. //      else if (x < 0)
  3423. //      {
  3424. //          cout << "Bad input. Enter another num: ";
  3425. //      }
  3426. //      else
  3427. //          return x;
  3428. //  }
  3429. //}
  3430. //
  3431. //char getChoice()
  3432. //{
  3433. //  char ch;
  3434. //  while (true)
  3435. //  {
  3436. //      cin >> ch;
  3437. //      cin.ignore(32767, '\n');
  3438. //      if (cin.fail())
  3439. //      {
  3440. //          cin.clear();
  3441. //          cin.ignore(32767, '\n');
  3442. //          cout << "Enter another char: ";
  3443. //      }
  3444. //      else if (ch != 'q' && ch != 'c')
  3445. //          cout << "Enter another char: ";
  3446. //      else
  3447. //          return ch;
  3448. //  }
  3449. //}
  3450. //
  3451. //void beatNum(int num)
  3452. //{
  3453. //  int x = num;
  3454. //  int count = 1;
  3455. //  while (x > 10)
  3456. //  {
  3457. //      x /= 10;
  3458. //      ++count;
  3459. //  }
  3460. //  int* arr = new int[count];
  3461. //  for (int i = count - 1; i >= 0; --i)
  3462. //  {
  3463. //      arr[i] = num % 10;
  3464. //      num /= 10;
  3465. //  }
  3466. //  for (int i = 0; i < count; ++i)
  3467. //      cout << i + 1 << " num = " << arr[i] << endl;
  3468. //}
  3469. //
  3470. //int main()
  3471. //{
  3472. //  char choice = 'c';
  3473. //  while (choice == 'c')
  3474. //  {
  3475. //      cout << "Enter the num: ";
  3476. //      int num = getNum();
  3477. //      cout << "Your num = " << num << endl;
  3478. //      beatNum(num);
  3479. //      cout << "Enter 'q' to quit or 'c' to continue: ";
  3480. //      choice = getChoice();
  3481. //      cout << "Your ch = " << choice << endl;
  3482. //  }
  3483. //
  3484. //  return 0;
  3485. //}
  3486. //
  3487.  
  3488. //#include <iostream>
  3489. //using namespace std;
  3490. //
  3491. //void getValues(int& a, int& b, int& f)
  3492. //{
  3493. //  while (true)
  3494. //  {
  3495. //      cout << "Enter a, b and f";
  3496. //      cin >> a >> b >> f;
  3497. //      cin.ignore(32767, '\n');
  3498. //      if (cin.fail())
  3499. //      {
  3500. //          cin.clear();
  3501. //          cin.ignore(32767, '\n');
  3502. //          cout << "Re-enter the numbers: ";
  3503. //      }
  3504. //      else
  3505. //          break;
  3506. //  }
  3507. //}
  3508. //
  3509. //int formula(const int& a, const int& b, const int& f)
  3510. //{
  3511. //  return (a + b - f / a) + f * a * a - (a + b);
  3512. //}
  3513. //
  3514. //int main()
  3515. //{
  3516. //  int a, b, f;
  3517. //  getValues(a, b, f);
  3518. //  cout << "x = (a + b - f / a) + f * a * a - (a + b) = ";
  3519. //  cout << formula(a, b, f);
  3520. //}
  3521.  
  3522. //#include <iostream>
  3523. //#include <cctype>
  3524. //using namespace std;
  3525. //char getChar()
  3526. //{
  3527. //  char ch;
  3528. //  cout << "Enter char: ";
  3529. //  while (true)
  3530. //  {
  3531. //      cin >> ch;
  3532. //      cin.ignore(32767, '\n');
  3533. //      if (!isalpha(ch))
  3534. //          cout << "Bad input. ";
  3535. //      else
  3536. //          return ch;
  3537. //  }
  3538. //}
  3539. //int main()
  3540. //{
  3541. //  char ch = getChar();
  3542. //  cout << static_cast<char>(toupper(ch));
  3543. //  return 0;
  3544. //}
  3545.  
  3546. //#include <iostream>
  3547. //using namespace std;
  3548. //float getMetres()
  3549. //{
  3550. //  float val;
  3551. //  cout << "Enter m: ";
  3552. //  while (true)
  3553. //  {
  3554. //      cin >> val;
  3555. //      cin.ignore(32767, '\n');
  3556. //      if (cin.fail())
  3557. //      {
  3558. //          cin.clear();
  3559. //          cin.ignore(32767, '\n');
  3560. //          cout << "Bad input. Enter again: ";
  3561. //      }
  3562. //      else if (val < 0)
  3563. //          cout << "Bad input. Only > 0 : ";
  3564. //      else
  3565. //          return val;
  3566. //  }
  3567. //}
  3568. //float mToK(float m)
  3569. //{
  3570. //  return m / 1000;
  3571. //}
  3572. //int main()
  3573. //{
  3574. //  float m = getMetres();
  3575. //  float k = mToK(m);
  3576. //  cout << m << " = " << k;
  3577. //  return 0;
  3578. //}
  3579.  
  3580. //#include <iostream>
  3581. //#include <string>
  3582. //using namespace std;
  3583. //
  3584. //int main()
  3585. //{
  3586. //  string name, surname, fathername;
  3587. //  cout << "Enter name = ";
  3588. //  cin >> name;
  3589. //  cout << "Enter surname = ";
  3590. //  cin >> surname;
  3591. //  cout << "Enter fathername = ";
  3592. //  cin >> fathername;
  3593. //  int size = name.size() + surname.size() + fathername.size();
  3594. //  for (int i = 0; i < size + 6; ++i)
  3595. //      cout << "*";
  3596. //  cout << endl << "* " << name << " " << surname << " " << fathername << " *" << endl;
  3597. //  for (int i = 0; i < size + 6; ++i)
  3598. //      cout << "*";
  3599. //  return 0;
  3600. //}
  3601.  
  3602. //#include <iostream>
  3603. //using namespace std;
  3604. //
  3605. //int getNum()
  3606. //{
  3607. //  int val = 0;
  3608. //  cout << "Enter num: ";
  3609. //  while (true)
  3610. //  {
  3611. //      cin >> val;
  3612. //      cin.ignore(32767, '\n');
  3613. //      if (cin.fail())
  3614. //      {
  3615. //          cin.clear();
  3616. //          cin.ignore(32767, '\n');
  3617. //          cout << "Bad input. ";
  3618. //      }
  3619. //      else
  3620. //          return val;
  3621. //  }
  3622. //}
  3623. //
  3624. //void compareNums(const int x, const int y)
  3625. //{
  3626. //  if (x > y)
  3627. //      cout << " X > Y ";
  3628. //  else if (x < y)
  3629. //      cout << " X < Y ";
  3630. //  else
  3631. //      cout << " X == Y ";
  3632. //}
  3633. //
  3634. //int main()
  3635. //{
  3636. //  int x = getNum();
  3637. //  int y = getNum();
  3638. //  compareNums(x, y);
  3639. //  return 0;
  3640. //}
  3641.  
  3642. //#include <iostream>
  3643. //using namespace std;
  3644. //
  3645. //int getnum()
  3646. //{
  3647. //  int val = 0;
  3648. //  cout << "enter num: ";
  3649. //  while (true)
  3650. //  {
  3651. //      cin >> val;
  3652. //      cin.ignore(32767, '\n');
  3653. //      if (cin.fail())
  3654. //      {
  3655. //          cin.clear();
  3656. //          cin.ignore(32767, '\n');
  3657. //          cout << "bad input. ";
  3658. //      }
  3659. //      else
  3660. //          return val;
  3661. //  }
  3662. //}
  3663. //
  3664. //void changeNums(int& x, int& y, int& z, const int n)
  3665. //{
  3666. //  x += n;
  3667. //  y += n;
  3668. //  z += n;
  3669. //}
  3670. //
  3671. //int main()
  3672. //{
  3673. //  int x = getnum();
  3674. //  int y = getnum();
  3675. //  int z = getnum();
  3676. //  int n = getnum();
  3677. //
  3678. //  if (x == y || y == z || x == z)
  3679. //  {
  3680. //      changeNums(x, y, z, n);
  3681. //      cout << x << " " << y << " " << z << " " << endl;
  3682. //  }
  3683. //  else
  3684. //      cout << "no equal";
  3685. //
  3686. //  return 0;
  3687. //}
  3688.  
  3689. //#include <iostream>
  3690. //using namespace std;
  3691. //
  3692. //int getNumOfX()
  3693. //{
  3694. //  int val = -1;
  3695. //  while (true)
  3696. //  {
  3697. //      cout << "Enter the num of X: ";
  3698. //      cin >> val;
  3699. //      cin.ignore(32767, '\n');
  3700. //      if (cin.fail())
  3701. //      {
  3702. //          cin.clear();
  3703. //          cin.ignore(32767, '\n');
  3704. //          cout << "Bad input. ";
  3705. //      }
  3706. //      else if (val < 1)
  3707. //          cout << "Only > 0";
  3708. //      else
  3709. //          return val;
  3710. //  }
  3711. //}
  3712. //
  3713. //double getNums()
  3714. //{
  3715. //  double val = 0.0;
  3716. //  while (true)
  3717. //  {
  3718. //      cout << "Enter the nums: ";
  3719. //      cin >> val;
  3720. //      cin.ignore(32767, '\n');
  3721. //      if (cin.fail())
  3722. //      {
  3723. //          cin.clear();
  3724. //          cin.ignore(32767, '\n');
  3725. //          cout << "Bad input. ";
  3726. //      }
  3727. //      else
  3728. //          return val;
  3729. //  }
  3730. //}
  3731. //
  3732. //void calcX(double* x, double* Z, double* B, double* A, double* betta, int size)
  3733. //{
  3734. //  for (int i = 0; i < size; ++i)
  3735. //      x[i] = Z[i] * Z[i] * Z[i] - B[i] + (A[i] * A[i]) / (tan(betta[i]) * tan(betta[i]));
  3736. //}
  3737. //
  3738. //double calcY(double* x, int size)
  3739. //{
  3740. //  double sum = 0.0;
  3741. //  for (int i = 0; i < size; ++i)
  3742. //      sum += x[i];
  3743. //  return sum;
  3744. //}
  3745. //
  3746. //void getArr(double* arr, int size)
  3747. //{
  3748. //  for (int i = 0; i < size; ++i)
  3749. //      arr[i] = getNums();
  3750. //}
  3751. //
  3752. //int main()
  3753. //{
  3754. //  int size = getNumOfX();
  3755. //  double* x = new double[size];
  3756. //  double* Z = new double[size];
  3757. //  getArr(Z, size);
  3758. //  double* B = new double[size];
  3759. //  getArr(B, size);
  3760. //  double* A = new double[size];
  3761. //  getArr(A, size);
  3762. //  double* betta = new double[size];
  3763. //  getArr(betta, size);
  3764. //  calcX(x, Z, B, A, betta, size);
  3765. //  double y = calcY(x, size);
  3766. //  cout << endl << " Y = " << y;
  3767. //  return 0;
  3768. //}
  3769.  
  3770. //#include <iostream>
  3771. //using namespace std;
  3772. //
  3773. //int getNum()
  3774. //{
  3775. //  int val = -1;
  3776. //  while (true)
  3777. //  {
  3778. //      cout << "Enter the num: ";
  3779. //      cin >> val;
  3780. //      cin.ignore(32767, '\n');
  3781. //      if (cin.fail())
  3782. //      {
  3783. //          cin.clear();
  3784. //          cin.ignore(32767, '\n');
  3785. //          cout << "Bad input. ";
  3786. //      }
  3787. //      else if (val < 1)
  3788. //          cout << "Only > 0";
  3789. //      else
  3790. //          return val;
  3791. //  }
  3792. //}
  3793. //
  3794. //float calc(int k, int N)
  3795. //{
  3796. //  float sum = 0.0;
  3797. //  float sum2 = 1.0;
  3798. //  for (int i = 1; i <= N; ++i)
  3799. //  {
  3800. //      sum2 = 1.0;
  3801. //      for (int j = 1; j <= k; ++j)
  3802. //          sum2 *= i;
  3803. //      sum += sum2;
  3804. //  }
  3805. //  return sum;
  3806. //}
  3807. //
  3808. //int main()
  3809. //{
  3810. //  int k = getNum();
  3811. //  int N = getNum();
  3812. //  float result = calc(k, N);
  3813. //  cout << result;
  3814. //  return 0;
  3815. //}
  3816. //
  3817. //#include <iostream>
  3818. //using namespace std;
  3819. //
  3820. //int getNum()
  3821. //{
  3822. //  int val = 0;
  3823. //  while (true)
  3824. //  {
  3825. //      cout << "Enter the nums: ";
  3826. //      cin >> val;
  3827. //      cin.ignore(32767, '\n');
  3828. //      if (cin.fail())
  3829. //      {
  3830. //          cin.clear();
  3831. //          cin.ignore(32767, '\n');
  3832. //          cout << "Bad input. ";
  3833. //      }
  3834. //      else
  3835. //          return val;
  3836. //  }
  3837. //}
  3838. //
  3839. //void find(int& max, int& min, int num)
  3840. //{
  3841. //  int x = max = min = num % 10;
  3842. //  while (num > 10)
  3843. //  {
  3844. //      num /= 10;
  3845. //      x = num % 10;
  3846. //      if (min > x)
  3847. //          min = x;
  3848. //      else if (max < x)
  3849. //          max = x;
  3850. //  }
  3851. //}
  3852. //
  3853. //int main()
  3854. //{
  3855. //  int num = getNum();
  3856. //  int min, max;
  3857. //  find(max, min, num);
  3858. //  cout << "Max = " << max << " min = " << min;
  3859. //  return 0;
  3860. //}
  3861. //
  3862. //#include <iostream>
  3863. //using namespace std;
  3864. //
  3865. //int getNum()
  3866. //{
  3867. //  int num;
  3868. //  while (true)
  3869. //  {
  3870. //      cout << "Enter num: ";
  3871. //      cin >> num;
  3872. //      cin.ignore(32767, '\n');
  3873. //      if (cin.fail())
  3874. //      {
  3875. //          cin.clear();
  3876. //          cin.ignore(32767, '\n');
  3877. //          cout << "Bad input. ";
  3878. //      }
  3879. //      else if (num < 0)
  3880. //          cout << "Only > 0";
  3881. //      else
  3882. //          return num;
  3883. //  }
  3884. //}
  3885. //
  3886. //bool palindrom(int num)
  3887. //{
  3888. //  int x = num, count = 1;
  3889. //  while (x > 9)
  3890. //  {
  3891. //      x /= 10;
  3892. //      ++count;
  3893. //  }
  3894. //  cout << endl << count;
  3895. //  int* arr = new int[count] {0};
  3896. //  x = num;
  3897. //  for (int i = 0; x > 0; ++i)
  3898. //  {
  3899. //      arr[i] = x % 10;
  3900. //      x /= 10;
  3901. //  }
  3902. //
  3903. //  for (int i = 0; i < count / 2; ++i)
  3904. //      if (arr[i] != arr[count - i - 1])
  3905. //          return false;
  3906. //  return true;
  3907. //}
  3908. //
  3909. //int main()
  3910. //{
  3911. //  int num = getNum();
  3912. //  if (palindrom(num))
  3913. //      cout << endl << "yes";
  3914. //  else
  3915. //      cout << endl << "no";
  3916. // 
  3917. //  return 0;
  3918. //}
  3919.  
  3920. //#include <iostream>
  3921. //using namespace std;
  3922. //
  3923. //int getSize()
  3924. //{
  3925. //  int size = 0;
  3926. //  while (true)
  3927. //  {
  3928. //      cin >> size;
  3929. //      cin.ignore(32767, '\n');
  3930. //      if (cin.fail())
  3931. //      {
  3932. //          cin.clear();
  3933. //          cin.ignore(32767, '\n');
  3934. //          cout << "Bad input. Re-enter: ";
  3935. //      }
  3936. //      else if (size < 1)
  3937. //          cout << "Bad input. Re-enter: ";
  3938. //      else
  3939. //          return size;
  3940. //  }
  3941. //
  3942. //  return size;
  3943. //}
  3944. //
  3945. //float getNumForArr()
  3946. //{
  3947. //  float val = 0.0f;
  3948. //  while (true)
  3949. //  {
  3950. //      cin >> val;
  3951. //      cin.ignore(32767, '\n');
  3952. //      if (cin.fail())
  3953. //      {
  3954. //          cin.clear();
  3955. //          cin.ignore(32767, '\n');
  3956. //          cout << "Bad input. Re-enter: ";
  3957. //      }
  3958. //      else
  3959. //          return val;
  3960. //  }
  3961. //}
  3962. //
  3963. //void fillArray(float* arr, int size)
  3964. //{
  3965. //  for (int i = 0; i < size; ++i)
  3966. //  {
  3967. //      cout << "Enter " << i + 1 << " element: ";
  3968. //      arr[i] = getNumForArr();
  3969. //  }
  3970. //}
  3971. //
  3972. //float ser(float* arr, int size)
  3973. //{
  3974. //  float sum = 0.0f;
  3975. //  for (int i = 0; i < size; ++i)
  3976. //      sum += arr[i];
  3977. //  return sum / size;
  3978. //}
  3979. //
  3980. //int main()
  3981. //{
  3982. //  cout << "Enter the size of array: ";
  3983. //  int sizeOfArray = getSize();
  3984. //  float* arr = new float[sizeOfArray];
  3985. //  fillArray(arr, sizeOfArray);
  3986. //  cout << ser(arr, sizeOfArray);
  3987. //  return 0;
  3988. //}
  3989. //
  3990. //#include <iostream>
  3991. //using namespace std;
  3992. //int main()
  3993. //{
  3994. //  int num = 0;
  3995. //  cin >> num;
  3996. //  for (int i = 1; i <= 10; ++i)
  3997. //      cout << i << " * " << num << " = " << i * num << endl;
  3998. //}
  3999.  
  4000. //#include <iostream>
  4001. //using namespace std;
  4002. //
  4003. //int getNum()
  4004. //{
  4005. //  int num;
  4006. //  cout << "Enter a num: ";
  4007. //  while (true)
  4008. //  {
  4009. //      cin >> num;
  4010. //      cin.ignore(32767, '\n');
  4011. //      if (cin.fail())
  4012. //      {
  4013. //          cin.clear();
  4014. //          cin.ignore(32767, '\n');
  4015. //          cout << "Bad input. Try again. ";
  4016. //      }
  4017. //      else
  4018. //          return num;
  4019. //  }
  4020. //}
  4021. //
  4022. //char getChoice()
  4023. //{
  4024. //  char choice;
  4025. //  cout << "Enter your choice (q - quit, c - continue): ";
  4026. //  while (true)
  4027. //  {
  4028. //      cin >> choice;
  4029. //      cin.ignore(32767, '\n');
  4030. //      if (cin.fail())
  4031. //      {
  4032. //          cin.clear();
  4033. //          cin.ignore(32767, '\n');
  4034. //          cout << "Bad input. Try again. ";
  4035. //      }
  4036. //      else if(choice != 'q' && choice != 'c')
  4037. //          cout << "Bad input. Try again. ";
  4038. //      else
  4039. //          return choice;
  4040. //  }
  4041. //}
  4042. //
  4043. //char getOperation()
  4044. //{
  4045. //  char operation;
  4046. //  cout << "Enter your operation (+, -, /, *): ";
  4047. //  while (true)
  4048. //  {
  4049. //      cin >> operation;
  4050. //      cin.ignore(32767, '\n');
  4051. //      if (cin.fail())
  4052. //      {
  4053. //          cin.clear();
  4054. //          cin.ignore(32767, '\n');
  4055. //          cout << "Bad input. Try again. ";
  4056. //      }
  4057. //      else if (operation != '+' && operation != '-' && operation != '*' && operation != '/')
  4058. //          cout << "Bad input. Try again. ";
  4059. //      else
  4060. //          return operation;
  4061. //  }
  4062. //}
  4063. //
  4064. //int add(int x, int y)
  4065. //{
  4066. //  return x + y;
  4067. //}
  4068. //
  4069. //int subtract(int x, int y)
  4070. //{
  4071. //  return x - y;
  4072. //}
  4073. //
  4074. //int multiply(int x, int y)
  4075. //{
  4076. //  return x * y;
  4077. //}
  4078. //
  4079. //int divide(int x, int y)
  4080. //{
  4081. //  return x / y;
  4082. //}
  4083. //
  4084. //typedef int (*arithmeticFcn)(int x, int y);
  4085. //
  4086. //arithmeticFcn getArithmeticFcn(char operation)
  4087. //{
  4088. //  switch (operation)
  4089. //  {
  4090. //  case '+': return add;
  4091. //  case '-': return subtract;
  4092. //  case '*': return multiply;
  4093. //  case '/': return divide;
  4094. //  }
  4095. //}
  4096. //
  4097. //int main()
  4098. //{
  4099. //  char choice = 'c', operation;
  4100. //  int x, y;
  4101. //  choice = getChoice();
  4102. //
  4103. //  while (choice != 'q')
  4104. //  {
  4105. //      x = getNum();
  4106. //      y = getNum();
  4107. //      operation = getOperation();
  4108. //      arithmeticFcn fptr = getArithmeticFcn(operation);
  4109. //      cout << fptr(x, y) << endl;
  4110. //      choice = getChoice();
  4111. //  }
  4112. //
  4113. //  return 0;
  4114. //}
  4115.  
  4116. //#include <iostream>
  4117. //using namespace std;
  4118. //
  4119. //int getNum()
  4120. //{
  4121. //  int num;
  4122. //  cout << "Enter a num: ";
  4123. //  while (true)
  4124. //  {
  4125. //      cin >> num;
  4126. //      cin.ignore(32767, '\n');
  4127. //      if (cin.fail())
  4128. //      {
  4129. //          cin.clear();
  4130. //          cin.ignore(32767, '\n');
  4131. //          cout << "Bad input. Try again. ";
  4132. //      }
  4133. //      else
  4134. //          return num;
  4135. //  }
  4136. //}
  4137. //
  4138. //char getChoice()
  4139. //{
  4140. //  char choice;
  4141. //  cout << "Enter your choice (q - quit, c - continue): ";
  4142. //  while (true)
  4143. //  {
  4144. //      cin >> choice;
  4145. //      cin.ignore(32767, '\n');
  4146. //      if (cin.fail())
  4147. //      {
  4148. //          cin.clear();
  4149. //          cin.ignore(32767, '\n');
  4150. //          cout << "Bad input. Try again. ";
  4151. //      }
  4152. //      else if(choice != 'q' && choice != 'c')
  4153. //          cout << "Bad input. Try again. ";
  4154. //      else
  4155. //          return choice;
  4156. //  }
  4157. //}
  4158. //
  4159. //char getOperation()
  4160. //{
  4161. //  char operation;
  4162. //  cout << "Enter your operation (+, -, /, *): ";
  4163. //  while (true)
  4164. //  {
  4165. //      cin >> operation;
  4166. //      cin.ignore(32767, '\n');
  4167. //      if (cin.fail())
  4168. //      {
  4169. //          cin.clear();
  4170. //          cin.ignore(32767, '\n');
  4171. //          cout << "Bad input. Try again. ";
  4172. //      }
  4173. //      else if (operation != '+' && operation != '-' && operation != '*' && operation != '/')
  4174. //          cout << "Bad input. Try again. ";
  4175. //      else
  4176. //          return operation;
  4177. //  }
  4178. //}
  4179. //
  4180. //int add(int x, int y)
  4181. //{
  4182. //  return x + y;
  4183. //}
  4184. //
  4185. //int subtract(int x, int y)
  4186. //{
  4187. //  return x - y;
  4188. //}
  4189. //
  4190. //int multiply(int x, int y)
  4191. //{
  4192. //  return x * y;
  4193. //}
  4194. //
  4195. //int divide(int x, int y)
  4196. //{
  4197. //  return x / y;
  4198. //}
  4199. //
  4200. //typedef int (*arithmeticFcn)(int x, int y);
  4201. //
  4202. //struct arithmeticStruct
  4203. //{
  4204. //  char oper;
  4205. //  arithmeticFcn fptr;
  4206. //};
  4207. //
  4208. //const arithmeticStruct arithmeticArr[4] { {'+', add}, {'-', subtract}, {'*', multiply}, {'/', divide} };
  4209. //
  4210. //arithmeticFcn getArithmeticFcn(char operation)
  4211. //{
  4212. //  for (auto &x : arithmeticArr)
  4213. //      if (x.oper == operation)
  4214. //          return x.fptr;
  4215. //}
  4216. //
  4217. //int main()
  4218. //{
  4219. //  char choice = 'c', operation;
  4220. //  int x, y;
  4221. //  choice = getChoice();
  4222. //
  4223. //  while (choice != 'q')
  4224. //  {
  4225. //      x = getNum();
  4226. //      y = getNum();
  4227. //      operation = getOperation();
  4228. //      arithmeticFcn fptr = getArithmeticFcn(operation);
  4229. //      cout << fptr(x, y) << endl;
  4230. //      choice = getChoice();
  4231. //  }
  4232. //
  4233. //  return 0;
  4234. //}
  4235.  
  4236. //#include <iostream>
  4237. //#include <fstream>
  4238. //using namespace std;
  4239. //
  4240. //int main()
  4241. //{
  4242. //  ifstream fin;
  4243. //  fin.open("in.txt");
  4244. //  if (!fin.is_open())
  4245. //      exit(1);
  4246. //  char ch;
  4247. //  int c1{ 0 }, c2{ 0 };
  4248. //  while (!fin.eof())
  4249. //  {
  4250. //      ch = fin.get();
  4251. //      if (ch == '{')
  4252. //          ++c1;
  4253. //      else if (ch == '}')
  4254. //          ++c2;
  4255. //  }
  4256. //  if (c1 == c2)
  4257. //      cout << "YES";
  4258. //  else
  4259. //      cout << "NO";
  4260. //  return 0;
  4261. //}
  4262.  
  4263. //#include <iostream>
  4264. //using namespace std;
  4265. //
  4266. //int getSize()
  4267. //{
  4268. //  int num;
  4269. //  while (true)
  4270. //  {
  4271. //      cin >> num;
  4272. //      cin.ignore(32767, '\n');
  4273. //      if (cin.fail())
  4274. //      {
  4275. //          cin.clear();
  4276. //          cin.ignore(32767, '\n');
  4277. //          cout << "Bad input. Try again: ";
  4278. //      }
  4279. //      else if (num < 1 || num > 10)
  4280. //          cout << "Only > 0 && < 10, try again: ";
  4281. //      else
  4282. //          return num;
  4283. //  }
  4284. //}
  4285. //
  4286. //int getNum()
  4287. //{
  4288. //  int num;
  4289. //  while (true)
  4290. //  {
  4291. //      cin >> num;
  4292. //      cin.ignore(32767, '\n');
  4293. //      if (cin.fail())
  4294. //      {
  4295. //          cin.clear();
  4296. //          cin.ignore(32767, '\n');
  4297. //          cout << "Bad input. Try again: ";
  4298. //      }
  4299. //      else
  4300. //          return num;
  4301. //  }
  4302. //}
  4303. //
  4304. //int** creatreMatrix(int rows, int cols)
  4305. //{
  4306. //  int** matrix = new int* [rows];
  4307. //  for (int i = 0; i < rows; ++i)
  4308. //      *(matrix + i) = new int[cols];
  4309. //  return matrix;
  4310. //}
  4311. //
  4312. //int* createVector(int size)
  4313. //{
  4314. //  int* vec = new int[size];
  4315. //  return vec;
  4316. //}
  4317. //
  4318. //void fillMatrix(int** matrix, int rows, int cols)
  4319. //{
  4320. //  for(int i = 0; i < rows; ++i)
  4321. //      for (int j = 0; j < cols; ++j)
  4322. //      {
  4323. //          cout << "Enter [" << i << "][" << j << "] = ";
  4324. //          *(*(matrix + i) + j) = getNum();
  4325. //      }
  4326. //}
  4327. //
  4328. //void fillVector(int* vec, int size)
  4329. //{
  4330. //  for (int i = 0; i < size; ++i)
  4331. //  {
  4332. //      cout << "Enter [" << i << "] = ";
  4333. //      *(vec + i) = getNum();
  4334. //  }
  4335. //}
  4336. //
  4337. //void printMatrix(int** matrix, int rows, int cols)
  4338. //{
  4339. //  for (int i = 0; i < rows; ++i)
  4340. //  {
  4341. //      for (int j = 0; j < cols; ++j)
  4342. //          cout << *(*(matrix + i) + j) << " ";
  4343. //      cout << endl;
  4344. //  }
  4345. //  cout << endl;
  4346. //}
  4347. //
  4348. //void printVector(const int* vec, int size)
  4349. //{
  4350. //  for (int i = 0; i < size; ++i)
  4351. //      cout << *(vec + i) << " ";
  4352. //  cout << endl << endl;
  4353. //}
  4354. //
  4355. //int* calcResultVector(int** matrix, int* vec, int rows, int cols)
  4356. //{
  4357. //  int* res = createVector(rows);
  4358. //  for (int i = 0; i < rows; ++i)
  4359. //  {
  4360. //      int sum = 0;
  4361. //      for (int j = 0; j < cols; ++j)
  4362. //          sum += *(*(matrix + i) + j) * *(vec + j);
  4363. //      *(res + i) = sum;
  4364. //  }
  4365. //  return res;
  4366. //}
  4367. //
  4368. //int findMax(int* vec, int rows)
  4369. //{
  4370. //  int max = vec[0];
  4371. //  for (int i = 0; i < rows; ++i)
  4372. //      if (*(vec + i) > max)
  4373. //          max = *(vec + i);
  4374. //  return max;
  4375. //}
  4376. //
  4377. //void freeVec(int* vec)
  4378. //{
  4379. //  delete[] vec;
  4380. //  vec = nullptr;
  4381. //}
  4382. //
  4383. //void freeMatrix(int** matrix, int rows)
  4384. //{
  4385. //  for (int i = 0; i < rows; ++i)
  4386. //      delete[]matrix[i];
  4387. //  delete[] matrix;
  4388. //  matrix = nullptr;
  4389. //}
  4390. //
  4391. //int main()
  4392. //{
  4393. //  cout << "Enter the number of rows: ";
  4394. //  int rows = getSize();
  4395. // 
  4396. //  cout << "Enter the number of columns: ";
  4397. //  int cols = getSize();
  4398. // 
  4399. //  int** matrix = creatreMatrix(rows, cols);
  4400. //  cout << "Now enter these elements: " << endl;
  4401. //  fillMatrix(matrix, rows, cols);
  4402. // 
  4403. //  int* vec = createVector(cols);
  4404. //  cout << "Now enter the elements of vector: " << endl;
  4405. //  fillVector(vec, cols);
  4406. //
  4407. //  printMatrix(matrix, rows, cols);
  4408. //  printVector(vec, cols);
  4409. // 
  4410. //  int* resultVec = createVector(rows);
  4411. //  resultVec = calcResultVector(matrix, vec, rows, cols);
  4412. //
  4413. //  printVector(resultVec, rows);
  4414. //
  4415. //  int max = findMax(resultVec, rows);
  4416. //  cout << "Max = " << max;
  4417. //
  4418. //  freeVec(vec);
  4419. //  freeVec(resultVec);
  4420. //  freeMatrix(matrix, rows);
  4421. //
  4422. //  return 0;
  4423. //}
  4424.  
  4425. //#include <iostream>
  4426. //using namespace std;
  4427. //
  4428. //int getNum()
  4429. //{
  4430. //  int num;
  4431. //  cout << "Enter a num: ";
  4432. //  while (true)
  4433. //  {
  4434. //      cin >> num;
  4435. //      cin.ignore(32767, '\n');
  4436. //      if (cin.fail())
  4437. //      {
  4438. //          cin.clear();
  4439. //          cin.ignore(32767, '\n');
  4440. //          cout << "Bad input. Try again: ";
  4441. //      }
  4442. //      else
  4443. //          return num;
  4444. //  }
  4445. //}
  4446. //
  4447. //void copyArr(int* source, int* target, int size)
  4448. //{
  4449. //  for (int i = 0; i < size; ++i)
  4450. //      target[i] = source[i];
  4451. //}
  4452. //
  4453. //void print(const int* arr, int size)
  4454. //{
  4455. //  for (int i = 0; i < size; ++i)
  4456. //      cout << arr[i] << " ";
  4457. //  cout << endl;
  4458. //}
  4459. //
  4460. //int main()
  4461. //{
  4462. //  size_t size = 1;
  4463. //  int* arr = new int[size];
  4464. //  int temp;
  4465. //  temp = getNum();
  4466. //  arr[0] = temp;
  4467. //  print(arr, size);
  4468. //
  4469. //
  4470. //  while ((temp = getNum()) >= 0)
  4471. //  {
  4472. //      int* tempArr = new int[size];
  4473. //      copyArr(arr, tempArr, size);
  4474. //      delete[] arr;
  4475. //      arr = new int[size + 1];
  4476. //      copyArr(tempArr, arr, size);
  4477. //      delete[] tempArr;
  4478. //      arr[size] = temp;
  4479. //      ++size;
  4480. //      print(arr, size);
  4481. //  }
  4482. //
  4483. //  delete [] arr;
  4484. //  return 0;
  4485. //}
  4486. //
  4487. //
  4488. //
  4489. //
  4490. //#include <iostream>
  4491. //#include <string>
  4492. //using namespace std;
  4493. //
  4494. //struct human
  4495. //{
  4496. //  int age;
  4497. //  string name;
  4498. //};
  4499. //
  4500. //int getAge()
  4501. //{
  4502. //  int num { 0 };
  4503. //  while (true)
  4504. //  {
  4505. //      cin >> num;
  4506. //      cin.ignore(32767, '\n');
  4507. //      if (cin.fail())
  4508. //      {
  4509. //          cin.clear();
  4510. //          cin.ignore();
  4511. //          cout << "Bad input. Try again: ";
  4512. //      }
  4513. //      else if (num < 0)
  4514. //          cout << "Only n>=0. Try again: ";
  4515. //      else
  4516. //          return num;
  4517. //  }
  4518. //}
  4519. //
  4520. //int getChoice()
  4521. //{
  4522. //  int num{ 0 };
  4523. //  while (true)
  4524. //  {
  4525. //      cin >> num;
  4526. //      cin.ignore(32767, '\n');
  4527. //      if (cin.fail())
  4528. //      {
  4529. //          cin.clear();
  4530. //          cin.ignore();
  4531. //          cout << "Bad input. Try again: ";
  4532. //      }
  4533. //      else if (num != 1 && num != 0)
  4534. //          cout << "Only 0or1. Try again: ";
  4535. //      else
  4536. //          return num;
  4537. //  }
  4538. //}
  4539. //
  4540. //human getInfo()
  4541. //{
  4542. //  human temp;
  4543. //  cout << "Enter the age: ";
  4544. //  temp.age = getAge();
  4545. //  cout << "Enter the name: ";
  4546. //  cin >> temp.name;
  4547. //  return temp;
  4548. //}
  4549. //
  4550. //void copyHuman(human* source, human* target, int size)
  4551. //{
  4552. //  for (int i = 0; i < size; ++i)
  4553. //      target[i] = source[i];
  4554. //}
  4555. //
  4556. //void showInfo(human* arr, int size)
  4557. //{
  4558. //  for (int i = 0; i < size; ++i)
  4559. //      cout << i << " element : " << arr[i].name << " " << arr[i].age << endl;
  4560. //}
  4561. //
  4562. //int main()
  4563. //{
  4564. //  int size = 1;
  4565. //  human* humanArr = new human[size];
  4566. //  humanArr[0] = getInfo();
  4567. //  int choice = 1;
  4568. //  cout << "Enter another info - 1, exit - 0";
  4569. //
  4570. //  while ((choice = getChoice()) == 1)
  4571. //  {
  4572. //      human* tempHuman = new human[size];
  4573. //      copyHuman(humanArr, tempHuman, size);
  4574. //      delete[] humanArr;
  4575. //      humanArr = new human[size + 1];
  4576. //      copyHuman(tempHuman, humanArr, size);
  4577. //      humanArr[size] = getInfo();
  4578. //      ++size;
  4579. //      delete[] tempHuman;
  4580. //      showInfo(humanArr, size);
  4581. //      cout << "Enter another info - 1, exit - 0";
  4582. //  }
  4583. //  return 0;
  4584. //}
  4585.  
  4586. //#include <iostream>
  4587. //using namespace std;
  4588. //
  4589. //double getNum()
  4590. //{
  4591. //  double num;
  4592. //  while (true)
  4593. //  {
  4594. //      cin >> num;
  4595. //      cin.ignore(32767, '\n');
  4596. //      if (cin.fail())
  4597. //      {
  4598. //          cin.clear();
  4599. //          cin.ignore(32767, '\n');
  4600. //          cout << "Bad input. Try again: ";
  4601. //      }
  4602. //      else if (num < 0.0)
  4603. //          cout << "Only > 0";
  4604. //      else
  4605. //          return num;
  4606. //  }
  4607. //}
  4608. //
  4609. //const double eps = 0.0001;
  4610. //
  4611. //double squareRoot(double x)
  4612. //{
  4613. //  double Y1 = x;
  4614. //  double Y2 = 0.5 * (Y1 + (3.0 * x) / (2.0 * Y1 * Y1 + x / Y1));
  4615. //  while (abs(Y2 - Y1) > eps)
  4616. //  {
  4617. //      Y1 = Y2;
  4618. //      Y2 = 0.5 * (Y1 + (3.0 * x) / (2.0 * Y1 * Y1 + x / Y1));
  4619. //  }
  4620. //  return Y2;
  4621. //}
  4622. //
  4623. //int main()
  4624. //{
  4625. //  cout << "Enter x : ";
  4626. //  double x = getNum();
  4627. //  cout << "Square root " << squareRoot(x);
  4628. //  return 0;
  4629. //}
  4630.  
  4631. //#include <iostream>
  4632. //#include <cctype>
  4633. //using namespace std;
  4634. //
  4635. //char getChoice()
  4636. //{
  4637. //  char choice;
  4638. //  cout << "Enter your choice: ";
  4639. //  while (true)
  4640. //  {
  4641. //      cin >> choice;
  4642. //      cin.ignore(32767, '\n');
  4643. //      if (cin.fail())
  4644. //      {
  4645. //          cin.clear();
  4646. //          cin.ignore(32767, '\n');
  4647. //          cout << "Bad input. Try again : ";
  4648. //      }
  4649. //      else if (choice != '1' && choice != '2' && choice != '3' && choice != '4'
  4650. //                              && choice != '5' && choice != 'f')
  4651. //          cout << "Only 1, 2, 3, 4, 5 or f. Try again : ";
  4652. //      else
  4653. //          return choice;
  4654. //  }
  4655. //}
  4656. //
  4657. //void showMenu()
  4658. //{
  4659. //  cout << "To convert a string to capital letters press: 1"                   << endl <<
  4660. //          "To convert a string to lowercase nf press : 2"                     << endl <<
  4661. //          "To convert a string with a Capital Letter press : 3"               << endl <<
  4662. //          "To convert the string to the first lowercase character press : 4"  << endl <<
  4663. //          "To convert a string as in a normal sentence, press : 5"            << endl <<
  4664. //          "To exit press : f"                                                 << endl;
  4665. //}
  4666. //
  4667. //void toUp(const char* str, int size)
  4668. //{
  4669. //  cout << endl << endl;
  4670. //  for (int i = 0; i < size; ++i)
  4671. //      cout.put(toupper(str[i]));
  4672. //  cout << endl << endl;
  4673. //}
  4674. //
  4675. //void toDown(const char* str, int size)
  4676. //{
  4677. //  cout << endl << endl;
  4678. //  for (int i = 0; i < size; ++i)
  4679. //      cout.put(tolower(str[i]));
  4680. //  cout << endl << endl;
  4681. //}
  4682. //
  4683. //void toFirstUp(const char* str, int size)
  4684. //{
  4685. //  cout << endl << endl;
  4686. //  cout.put(toupper(str[0]));
  4687. //  for (int i = 1; i < size; ++i)
  4688. //  {
  4689. //      if (str[i - 1] == ' ' && str[i] != ' ')
  4690. //          cout.put(toupper(str[i]));
  4691. //      else
  4692. //          cout.put(tolower(str[i]));
  4693. //  }
  4694. //  cout << endl << endl;
  4695. //}
  4696. //
  4697. //void toFirstLower(const char* str, int size)
  4698. //{
  4699. //  cout << endl << endl;
  4700. //  cout.put(tolower(str[0]));
  4701. //  for (int i = 1; i < size; ++i)
  4702. //  {
  4703. //      if (str[i - 1] == ' ' && str[i] != ' ')
  4704. //          cout.put(tolower(str[i]));
  4705. //      else
  4706. //          cout.put(toupper(str[i]));
  4707. //  }
  4708. //  cout << endl << endl;
  4709. //}
  4710. //
  4711. //void toNormal(const char* str, int size)
  4712. //{
  4713. //  cout << endl << endl;
  4714. //  for (int i = 0; i < size; ++i)
  4715. //      cout.put(str[i]);
  4716. //  cout << endl << endl;
  4717. //}
  4718. //
  4719. //int main()
  4720. //{
  4721. //  const int size{ 255 };
  4722. //  char str[size]{};
  4723. //  int sizeOfStr = 0;
  4724. //  cout << "Enter the string: ";
  4725. //  while ((str[sizeOfStr] = cin.get()) != '\n' && sizeOfStr < size)
  4726. //      ++sizeOfStr;
  4727. //  str[sizeOfStr] = '\0';
  4728. //  char choice = '1';
  4729. //  while (choice != 'f')
  4730. //  {
  4731. //      showMenu();
  4732. //      choice = getChoice();
  4733. //      switch (choice)
  4734. //      {
  4735. //      case '1': toUp(str, sizeOfStr);         break;
  4736. //      case '2': toDown(str, sizeOfStr);       break;
  4737. //      case '3': toFirstUp(str, sizeOfStr);    break;
  4738. //      case '4': toFirstLower(str, sizeOfStr); break;
  4739. //      case '5': toNormal(str, sizeOfStr);     break;
  4740. //      case 'f': break;
  4741. //      }
  4742. //  }
  4743. //  return 0;
  4744. //}
  4745.  
  4746. //#include <iostream>
  4747. //#include <ctime>
  4748. //#include <cstdlib>
  4749. //using namespace std;
  4750. //
  4751. //int getNum()
  4752. //{
  4753. //  int num;
  4754. //  while (true)
  4755. //  {
  4756. //      cin >> num;
  4757. //      cin.ignore(32767, '\n');
  4758. //      if (cin.fail())
  4759. //      {
  4760. //          cin.clear();
  4761. //          cin.ignore(32767, '\n');
  4762. //          cout << "Bad input. Try again: ";
  4763. //      }
  4764. //      else if (num < 0)
  4765. //          cout << "Only > 0";
  4766. //      else
  4767. //          return num;
  4768. //  }
  4769. //}
  4770. //
  4771. //double** allocMemory(const int size)
  4772. //{
  4773. //  double** arr = new double* [size];
  4774. //  for (int i = 0; i < size; ++i)
  4775. //      arr[i] = new double[size];
  4776. //  return arr;
  4777. //}
  4778. //
  4779. //void fillArray(double** arr, const int size, const int left, const int right)
  4780. //{
  4781. //  srand(static_cast<unsigned int>(time(0)));
  4782. //  for (int i = 0; i < size; ++i)
  4783. //  {
  4784. //      for (int j = 0; j < size; ++j)
  4785. //          arr[i][j] = ((left * 1000) + (rand() % ((right - left) * 1000))) / 1000.0;
  4786. //  }
  4787. //}
  4788. //
  4789. //void showArray(double** arr, const int size)
  4790. //{
  4791. //  for (int i = 0; i < size; ++i)
  4792. //  {
  4793. //      for (int j = 0; j < size; ++j)
  4794. //          cout << arr[i][j] << "\t";
  4795. //      cout << endl;
  4796. //  }
  4797. //}
  4798. //
  4799. //int findMax(double** arr, int size, double &min)
  4800. //{
  4801. //  min = arr[0][0];
  4802. //  int index = 0;
  4803. //  for (int i = 0; i < size; ++i)
  4804. //      for (int j = 0; j < size; ++j)
  4805. //          if (arr[i][j] < min)
  4806. //          {
  4807. //              min = arr[i][j];
  4808. //              index = i;
  4809. //          }
  4810. //  return index;
  4811. //}
  4812. //
  4813. //void showMin(double min, int minIndex)
  4814. //{
  4815. //  cout << endl << "Number of row with min num = " << minIndex;
  4816. //  cout << endl << "Min element = " << min << endl << endl;
  4817. //}
  4818. //
  4819. //void swapRows(double** arr, int first, int second)
  4820. //{
  4821. //  double* temp = arr[first];
  4822. //  arr[first] = arr[second];
  4823. //  arr[second] = temp;
  4824. //}
  4825. //
  4826. //int main()
  4827. //{
  4828. //  cout << "Enter a : ";
  4829. //  int a = getNum();
  4830. //  cout << "Enter b : ";
  4831. //  int b = getNum();
  4832. //  if (a > b)
  4833. //      swap(a, b);
  4834. //  const int size = 10;
  4835. //  double** arr = allocMemory(size);
  4836. //  fillArray(arr, size, a, b);
  4837. //  showArray(arr, size);
  4838. //  double min;
  4839. //  int minIndex = findMax(arr, size, min);
  4840. //  showMin(min, minIndex);
  4841. //  swapRows(arr, 0, minIndex);
  4842. //  showArray(arr, size);
  4843. //  return 0;
  4844. //}
  4845.  
  4846.  
  4847. //#include <iostream>
  4848. //using namespace std;
  4849. //int getSize()
  4850. //{
  4851. //  int num;
  4852. //  while (true)
  4853. //  {
  4854. //      cin >> num;
  4855. //      cin.ignore(32767, '\n');
  4856. //      if (cin.fail())
  4857. //      {
  4858. //          cin.clear();
  4859. //          cin.ignore(32767, '\n');
  4860. //          cout << "Bad input. Try again. ";
  4861. //      }
  4862. //      else if (num < 1)
  4863. //          cout << "Bad input. Try again. ";
  4864. //      else
  4865. //          return num;
  4866. //  }
  4867. //}
  4868. //
  4869. //int getNum()
  4870. //{
  4871. //  int num;
  4872. //  while (true)
  4873. //  {
  4874. //      cin >> num;
  4875. //      cin.ignore(32767, '\n');
  4876. //      if (cin.fail())
  4877. //      {
  4878. //          cin.clear();
  4879. //          cin.ignore(32767, '\n');
  4880. //          cout << "Bad input. Try again. ";
  4881. //      }
  4882. //      else
  4883. //          return num;
  4884. //  }
  4885. //}
  4886. //
  4887. //int** createMatrix(int rows, int cols)
  4888. //{
  4889. //  int** arr = new int* [rows];
  4890. //  for (int i = 0; i < rows; ++i)
  4891. //      arr[i] = new int[cols];
  4892. //  return arr;
  4893. //}
  4894. //
  4895. //void fillMatrix(int** arr, int rows, int cols)
  4896. //{
  4897. //  for (int i = 0; i < rows; ++i)
  4898. //      for (int j = 0; j < cols; ++j)
  4899. //      {
  4900. //          cout << "Enter [" << i << "][" << j << "] = ";
  4901. //          arr[i][j] = getNum();
  4902. //      }
  4903. //}
  4904. //
  4905. //void copyArr(int** source, int* target, int rows, int cols)
  4906. //{
  4907. //  for (int i = 0; i < rows; ++i)
  4908. //      for (int j = 0; j < cols; ++j)
  4909. //          target[i * cols + j] = source[i][j];
  4910. //}
  4911. //
  4912. //void showArr(int** arr, int rows, int cols)
  4913. //{
  4914. //  for (int i = 0; i < rows; ++i)
  4915. //  {
  4916. //      for (int j = 0; j < cols; ++j)
  4917. //          cout << arr[i][j] << " ";
  4918. //      cout << endl;
  4919. //  }
  4920. //}
  4921. //
  4922. //void showArr(int* arr, int size)
  4923. //{
  4924. //  for (int i = 0; i < size; ++i)
  4925. //      cout << arr[i] << " ";
  4926. //  cout << endl;
  4927. //}
  4928. //
  4929. //void deleteArr(int** arr, int rows)
  4930. //{
  4931. //  for (int i = 0; i < rows; ++i)
  4932. //  {
  4933. //      delete[]arr[i];
  4934. //      arr[i] = nullptr;
  4935. //  }
  4936. //  delete[]arr;
  4937. //  arr = nullptr;
  4938. //}
  4939. //
  4940. //void deleteArr(int* arr)
  4941. //{
  4942. //  delete[]arr;
  4943. //  arr = nullptr;
  4944. //}
  4945. //
  4946. //int main()
  4947. //{
  4948. //  cout << "Enter the num of rows: ";
  4949. //  int rows = getSize();
  4950. //  cout << "Enter the num of cols: ";
  4951. //  int cols = getSize();
  4952. //  cout << "Now fill the matrix: ";
  4953. //  int ** arr = createMatrix(rows, cols);
  4954. //  fillMatrix(arr, rows, cols);
  4955. //  int* newArr = new int[rows * cols];
  4956. //  copyArr(arr, newArr, rows, cols);
  4957. //  showArr(arr, rows, cols);
  4958. //  showArr(newArr, rows * cols);
  4959. //  deleteArr(arr, rows);
  4960. //  deleteArr(newArr);
  4961. //  return 0;
  4962. //}
  4963.  
  4964. //#include <iostream>
  4965. //using namespace std;
  4966. //
  4967. //int getHours()
  4968. //{
  4969. //  int h;
  4970. //  while (true)
  4971. //  {
  4972. //      cin >> h;
  4973. //      cin.ignore(32767, '\n');
  4974. //      if (cin.fail())
  4975. //      {
  4976. //          cin.clear();
  4977. //          cin.ignore(32767, '\n');
  4978. //          cout << "Bad input. Try again : ";
  4979. //      }
  4980. //      else if (h > 23|| h < 0)
  4981. //          cout << "Bad input. Try again : ";
  4982. //      else
  4983. //          return h;
  4984. //  }
  4985. //}
  4986. //
  4987. //int getMinutesOrSeconds()
  4988. //{
  4989. //  int h;
  4990. //  while (true)
  4991. //  {
  4992. //      cin >> h;
  4993. //      cin.ignore(32767, '\n');
  4994. //      if (cin.fail())
  4995. //      {
  4996. //          cin.clear();
  4997. //          cin.ignore(32767, '\n');
  4998. //          cout << "Bad input. Try again : ";
  4999. //      }
  5000. //      else if (h > 59 || h < 0)
  5001. //          cout << "Bad input. Try again : ";
  5002. //      else
  5003. //          return h;
  5004. //  }
  5005. //}
  5006. //
  5007. //int getSecondsForMinus()
  5008. //{
  5009. //  int h;
  5010. //  while (true)
  5011. //  {
  5012. //      cin >> h;
  5013. //      cin.ignore(32767, '\n');
  5014. //      if (cin.fail())
  5015. //      {
  5016. //          cin.clear();
  5017. //          cin.ignore(32767, '\n');
  5018. //          cout << "Bad input. Try again : ";
  5019. //      }
  5020. //      else if (h < 0)
  5021. //          cout << "Bad input. Try again : ";
  5022. //      else
  5023. //          return h;
  5024. //  }
  5025. //}
  5026. //
  5027. //struct time
  5028. //{
  5029. //  int hours;
  5030. //  int minutes;
  5031. //  int seconds;
  5032. //};
  5033. //
  5034. //void calculateRestOfTime(time &T, int secondsToMinus)
  5035. //{
  5036. //  if (secondsToMinus < T.seconds)
  5037. //      T.seconds -= secondsToMinus;
  5038. //  else if ((T.seconds + T.minutes * 60) > secondsToMinus)
  5039. //  {
  5040. //      T.minutes -= secondsToMinus / 60;
  5041. //      T.seconds -= secondsToMinus % 60;
  5042. //  }
  5043. //  else
  5044. //  {
  5045. //      int total = T.hours * 3600 + T.minutes * 60 + T.seconds;
  5046. //      total -= secondsToMinus;
  5047. //      T.seconds = total % 60;
  5048. //      T.minutes = total / 60;
  5049. //      T.hours = T.minutes / 60;
  5050. //      T.minutes = T.minutes % 60;
  5051. //  }
  5052. //}
  5053. //
  5054. //void showTime(time T)
  5055. //{
  5056. //  cout << T.hours << ":" << T.minutes << ":" << T.seconds << endl;
  5057. //}
  5058. //
  5059. //int minusTimeBetweenPeriods(time T1, time T2)
  5060. //{
  5061. //  int t1 = T1.hours * 3600 + T1.minutes * 60 + T1.seconds;
  5062. //  int t2 = T2.hours * 3600 + T2.minutes * 60 + T2.seconds;
  5063. //  return abs(t2 - t1);
  5064. //}
  5065. //
  5066. //int main()
  5067. //{
  5068. //  time T;
  5069. //  cout << "Enter the time\n>>Enter hours: ";
  5070. //  T.hours = getHours();
  5071. //  cout << "Enter minutes: ";
  5072. //  T.minutes = getMinutesOrSeconds();
  5073. //  cout << "Enter seconds: ";
  5074. //  T.seconds = getMinutesOrSeconds();
  5075. //  cout << "Your time: ";
  5076. //  showTime(T);
  5077. //  cout << "Enter seconds to minus: ";
  5078. //  int secondsToMinus = getSecondsForMinus();
  5079. //  calculateRestOfTime(T, secondsToMinus);
  5080. //  cout << "Your new time: ";
  5081. //  showTime(T);
  5082. // 
  5083. //
  5084. //  time T1;
  5085. //  cout << "Enter the time\n>>Enter hours: ";
  5086. //  T1.hours = getHours();
  5087. //  cout << "Enter minutes: ";
  5088. //  T1.minutes = getMinutesOrSeconds();
  5089. //  cout << "Enter seconds: ";
  5090. //  T1.seconds = getMinutesOrSeconds();
  5091. //  cout << "Your time: ";
  5092. //  showTime(T1);
  5093. //
  5094. //  time T2;
  5095. //  cout << "Enter the time\n>>Enter hours: ";
  5096. //  T2.hours = getHours();
  5097. //  cout << "Enter minutes: ";
  5098. //  T2.minutes = getMinutesOrSeconds();
  5099. //  cout << "Enter seconds: ";
  5100. //  T2.seconds = getMinutesOrSeconds();
  5101. //  cout << "Your time: ";
  5102. //  showTime(T2);
  5103. //
  5104. //  int res = minusTimeBetweenPeriods(T1, T2);
  5105. //  cout << "Num of seconds between this periods: " << res;
  5106. // 
  5107. //  return 0;
  5108. //}
  5109.  
  5110. //#include <iostream>
  5111. //#include <fstream>
  5112. //#include <string>
  5113. //using namespace std;
  5114. //
  5115. //class Worker
  5116. //{
  5117. //  string name;
  5118. //  int experience;
  5119. //  int salaryPerHour;
  5120. //  int workHours;
  5121. //public:
  5122. //  Worker();
  5123. //  Worker(string name_, int experience_, int salaryPerHour_, int workHours_);
  5124. //  ~Worker();
  5125. //  friend istream& operator>>(istream& is, Worker &Man);
  5126. //  friend ostream& operator<<(ostream& os, const Worker &Man);
  5127. //  friend ofstream& operator<<(ofstream& ofs, const Worker &Man);
  5128. //  float calcPremium() const;
  5129. //  float calcSalary() const;
  5130. //};
  5131. //
  5132. //Worker::Worker()
  5133. //{
  5134. //  name = "none";
  5135. //  experience = salaryPerHour = workHours = 0;
  5136. //}
  5137. //
  5138. //Worker::Worker(string name_, int experience_, int salaryPerHour_, int workHours_)
  5139. //{
  5140. //  name = name_;
  5141. //  experience = experience_;
  5142. //  salaryPerHour = salaryPerHour_;
  5143. //  workHours = workHours_;
  5144. //}
  5145. //
  5146. //Worker::~Worker()
  5147. //{
  5148. //  name = "none";
  5149. //  experience = salaryPerHour = workHours = 0;
  5150. //}
  5151. //
  5152. //int getNum()
  5153. //{
  5154. //  int num;
  5155. //  while (true)
  5156. //  {
  5157. //      cin >> num;
  5158. //      cin.ignore(32767, '\n');
  5159. //      if (cin.fail())
  5160. //      {
  5161. //          cin.clear();
  5162. //          cin.ignore(32767, '\n');
  5163. //          cout << "Bad input. Try again. ";
  5164. //      }
  5165. //      else if (num < 0)
  5166. //          cout << "Only > 0 . Try again. ";
  5167. //      else
  5168. //          return num;
  5169. //  }
  5170. //}
  5171. //
  5172. //float Worker::calcSalary() const
  5173. //{
  5174. //  return salaryPerHour * workHours;
  5175. //}
  5176. //
  5177. //float Worker::calcPremium() const
  5178. //{
  5179. //  float res = 0;
  5180. //  if (experience < 1)
  5181. //      res = 0.0f;
  5182. //  else if (experience < 3)
  5183. //      res = 0.05f;
  5184. //  else if (experience < 5)
  5185. //      res = 0.08f;
  5186. //  else
  5187. //      res = 0.15f;
  5188. //  return res * calcSalary();
  5189. //}
  5190. //
  5191. //istream& operator>>(istream& is, Worker &Man)
  5192. //{
  5193. //  cout << "Enter worker's name: ";
  5194. //  is >> Man.name;
  5195. //  cout << "Enter worker's experience: ";
  5196. //  Man.experience = getNum();
  5197. //  cout << "Enter worker's hourly wag: ";
  5198. //  Man.salaryPerHour = getNum();
  5199. //  cout << "Entre how much hours " << Man.name << " has worked: ";
  5200. //  Man.workHours = getNum();
  5201. //  return is;
  5202. //}
  5203. //
  5204. //ostream& operator<<(ostream& os, const Worker &Man)
  5205. //{
  5206. //  os << "Name " << Man.name << endl;
  5207. //  os << "Experience is " << Man.experience << endl;
  5208. //  os << "Hourly wage is " << Man.salaryPerHour << endl;
  5209. //  os << Man.experience << " has worked " << Man.workHours << " hours" << endl;
  5210. //  os << "Salary is " << Man.calcSalary() << endl;
  5211. //  os << "Premy is " << Man.calcPremium() << endl;
  5212. //  return os;
  5213. //}
  5214. //
  5215. //ofstream& operator<<(ofstream& ofs, const Worker& Man)
  5216. //{
  5217. //  ofs << "Name " << Man.name << endl;
  5218. //  ofs << "Experience is " << Man.experience << endl;
  5219. //  ofs << "Hourly wage is " << Man.salaryPerHour << endl;
  5220. //  ofs << Man.experience << " has worked " << Man.workHours << " hours" << endl;
  5221. //  ofs << "Salary is " << Man.calcSalary() << endl;
  5222. //  ofs << "Premy is " << Man.calcPremium() << endl;
  5223. //  return ofs;
  5224. //}
  5225. //
  5226. //int main()
  5227. //{
  5228. //  ofstream ofs;
  5229. //  ofs.open("out.txt");
  5230. //  if (ofs.fail())
  5231. //      return 1;
  5232. //  Worker Man1("Danila", 5, 100, 3000);
  5233. //  Worker Man2;
  5234. //
  5235. //  cout << endl << Man1 << endl << endl;
  5236. //
  5237. //  cin >> Man2;
  5238. //  cout << endl << endl << Man2 << endl;
  5239. //
  5240. //  ofs << Man1 << endl << endl << Man2;
  5241. //
  5242. //  return 0;
  5243. //}
  5244.  
  5245. //#include <iostream>
  5246. //using namespace std;
  5247. //
  5248. //int getSize()
  5249. //{
  5250. //  cout << "Enter the size of matrix: ";
  5251. //  int size;
  5252. //  while (true)
  5253. //  {
  5254. //      cin >> size;
  5255. //      cin.ignore(32767, '\n');
  5256. //      if (cin.fail())
  5257. //      {
  5258. //          cin.clear();
  5259. //          cin.ignore(32767, '\n');
  5260. //          cout << "Bad input. Try again. ";
  5261. //      }
  5262. //      else if (size < 2)
  5263. //          cout << "Only n> 1. Try again. ";
  5264. //      else
  5265. //          return size;
  5266. //  }
  5267. //}
  5268. //
  5269. //int getNum()
  5270. //{
  5271. //  int size;
  5272. //  while (true)
  5273. //  {
  5274. //      cin >> size;
  5275. //      cin.ignore(32767, '\n');
  5276. //      if (cin.fail())
  5277. //      {
  5278. //          cin.clear();
  5279. //          cin.ignore(32767, '\n');
  5280. //          cout << "Bad input. Try again. ";
  5281. //      }
  5282. //      else
  5283. //          return size;
  5284. //  }
  5285. //}
  5286. //
  5287. //int** createArray(int size)
  5288. //{
  5289. //  int** arr = new int* [size];
  5290. //  for (int i = 0; i < size; ++i)
  5291. //      arr[i] = new int[size];
  5292. //  return arr;
  5293. //}
  5294. //
  5295. //void findMax(int &col, int &row, int** arr, int size)
  5296. //{
  5297. //  int max = abs(arr[0][0]);
  5298. //  for (int i = 0; i < size; ++i)
  5299. //      for (int j = 0; j < size; ++j)
  5300. //          if (abs(arr[i][j]) > max)
  5301. //          {
  5302. //              max = abs(arr[i][j]);
  5303. //              row = i;
  5304. //              col = j;
  5305. //          }
  5306. //}
  5307. //
  5308. //void fillMatrix(int** arr, int size)
  5309. //{
  5310. //  for(int i = 0; i < size; ++i)
  5311. //      for (int j = 0; j < size; ++j)
  5312. //      {
  5313. //          cout << "Enter [" << i << "][" << j << "] = ";
  5314. //          arr[i][j] = getNum();
  5315. //      }
  5316. //}
  5317. //
  5318. //void showMatrix(int** arr, int size)
  5319. //{
  5320. //  cout << endl << endl;
  5321. //  for (int i = 0; i < size; ++i)
  5322. //  {
  5323. //      for (int j = 0; j < size; ++j)
  5324. //          cout << arr[i][j] << " ";
  5325. //      cout << endl;
  5326. //  }
  5327. //}
  5328. //
  5329. //void swapRowsAndCols(int** arr, int col, int row, int size)
  5330. //{
  5331. //  if (row != (size - 1))
  5332. //  {
  5333. //      int* temp = arr[size - 1];
  5334. //      arr[size - 1] = arr[row];
  5335. //      arr[row] = temp;
  5336. //      temp = nullptr;
  5337. //  }
  5338. //
  5339. //  showMatrix(arr, size);
  5340. //
  5341. //  if (col != (size - 1))
  5342. //      for (int i = 0; i < size; ++i)
  5343. //      {
  5344. //          int temp = arr[i][size - 1];
  5345. //          arr[i][size - 1] = arr[i][col];
  5346. //          arr[i][col] = temp;
  5347. //      }
  5348. //}
  5349. //
  5350. //void deleteMatrix(int** arr, int size)
  5351. //{
  5352. //  for (int i = 0; i < size; ++i)
  5353. //  {
  5354. //      delete[] arr[i];
  5355. //      arr[i] = nullptr;
  5356. //  }
  5357. //  delete [] arr;
  5358. //  arr = nullptr;
  5359. //}
  5360. //
  5361. //int main()
  5362. //{
  5363. //  int size = getSize();
  5364. //  int row = 0, col = 0;
  5365. //  int** arr = createArray(size);
  5366. //  fillMatrix(arr, size);
  5367. //  showMatrix(arr, size);
  5368. //  findMax(col, row, arr, size);
  5369. //  swapRowsAndCols(arr, col, row, size);
  5370. //  showMatrix(arr, size);
  5371. //  deleteMatrix(arr, size);
  5372. //  return 0;
  5373. //}
  5374.  
  5375. //#include <iostream>
  5376. //#include <cstdlib>
  5377. //#include <ctime>
  5378. //
  5379. //using namespace std;
  5380. //
  5381. //int getStr(char *str)
  5382. //{
  5383. //  int count = 0;
  5384. //  char ch;
  5385. //  while ((ch = cin.get()) != '\n')
  5386. //      str[count++] = ch;
  5387. //  str[count] = '\0';
  5388. //  return count;
  5389. //}
  5390. //
  5391. //bool isConsonant(char ch)
  5392. //{
  5393. //  char consonants[] = "bcdfghjklmnpqrstvwxz";
  5394. //  return strchr(consonants, ch) ? true : false;
  5395. //}
  5396. //
  5397. //bool isVowel(char ch)
  5398. //{
  5399. //  char vowels[] = "aeyuio";
  5400. //  return strchr(vowels, ch) ? true : false;
  5401. //}
  5402. //
  5403. //char consonantOnVowel()
  5404. //{
  5405. //  char vowels[13] = "AEYUIOaeyuio";
  5406. //  srand(time(0));
  5407. //  int n = 1 + rand() % 12;
  5408. //  return vowels[n];
  5409. //}
  5410. //
  5411. //void changeString(char* str, int size)
  5412. //{
  5413. //  for (int i = 0; i < size; ++i)
  5414. //  {
  5415. //      if (isConsonant(tolower(str[i])))
  5416. //          cout << consonantOnVowel();
  5417. //      else if (isVowel(tolower(str[i])))
  5418. //          cout << static_cast<int> (str[i]);
  5419. //      else
  5420. //          cout << str[i];
  5421. //      cout << " ";
  5422. //  }
  5423. //}
  5424. //
  5425. //int main()
  5426. //{
  5427. //  char str[256];
  5428. //  cout << "Enter the string of characters: ";
  5429. //  int size = getStr(str);
  5430. //  changeString(str, size);
  5431. //  return 0;
  5432. //}
  5433.  
  5434. //#include <iostream>
  5435. //
  5436. //using namespace std;
  5437. //
  5438. //void showMenu()
  5439. //{
  5440. //  cout << "Menu:\n"
  5441. //      "1 - To enter the string\n"
  5442. //      "2 - To process the data\n"
  5443. //      "3 - To see result\n"
  5444. //      "0 - Exit\n";
  5445. //}
  5446. //
  5447. //int getStr(char *str)
  5448. //{
  5449. //  int count = 0;
  5450. //  char ch;
  5451. //  cout << "Enter your string: ";
  5452. //  while ((ch = cin.get()) != '\n')
  5453. //      str[count++] = ch;
  5454. //  str[count] = '\n';
  5455. //  return count;
  5456. //}
  5457. //int getChoice()
  5458. //{
  5459. //  int choice;
  5460. //  cout << "Enter your choice: ";
  5461. //  while (true)
  5462. //  {
  5463. //      cin >> choice;
  5464. //      cin.ignore(32767, '\n');
  5465. //      if (cin.fail())
  5466. //      {
  5467. //          cin.clear();
  5468. //          cin.ignore(32767, '\n');
  5469. //          cout << "Bad input. Try again. ";
  5470. //      }
  5471. //      else if (choice != 1 && choice != 2 && choice != 3 && choice != 0)
  5472. //          cout << "Bad input. Try again. ";
  5473. //      else
  5474. //          return choice;
  5475. //  }
  5476. //}
  5477. //
  5478. //int countRepeats(char* str, int size)
  5479. //{
  5480. //  cout << "\nProcessing the data...\n";
  5481. //  int count = 0;
  5482. //  for (int i = 0; i < size - 1; ++i)
  5483. //      if (str[i] == str[i + 1])
  5484. //          ++count;
  5485. //  return count;
  5486. //}
  5487. //
  5488. //int main()
  5489. //{
  5490. //  char str[256]{ "none" };
  5491. //  int choice = getChoice();
  5492. //  showMenu();
  5493. //
  5494. //  int count = 0;
  5495. //  int size = 0;
  5496. //  while (choice != 0)
  5497. //  {
  5498. //      switch (choice)
  5499. //      {
  5500. //      case 1: size = getStr(str); break;
  5501. //      case 2: count = countRepeats(str, size); break;
  5502. //      case 3: cout << "There are " << count << " repeats\n";
  5503. //      }
  5504. //      showMenu();
  5505. //      choice = getChoice();
  5506. //  }
  5507. //
  5508. //  return 0;
  5509. //}
  5510.  
  5511. //#include <iostream>
  5512. //#include <ctime>
  5513. //using namespace std;
  5514. //
  5515. //int getNum()
  5516. //{
  5517. //  int choice;
  5518. //  while (true)
  5519. //  {
  5520. //      cin >> choice;
  5521. //      cin.ignore(32767, '\n');
  5522. //      if (cin.fail())
  5523. //      {
  5524. //          cin.clear();
  5525. //          cin.ignore(32767, '\n');
  5526. //          cout << "Bad input. Try again : ";
  5527. //      }
  5528. //      else if (choice != 1 && choice != 0)
  5529. //          cout << "Only 1 or 0.";
  5530. //      else
  5531. //          return choice;
  5532. //  }
  5533. //}
  5534. //
  5535. //void hint()
  5536. //{
  5537. //  srand(time(0));
  5538. //  int choice = rand() % 3;
  5539. //  switch (choice)
  5540. //  {
  5541. //  case 0: cout << "lox"; break;
  5542. //  case 1: cout << "Lox"; break;
  5543. //  case 2: cout << "LoxLox"; break;
  5544. //  }
  5545. //}
  5546. //
  5547. //int main()
  5548. //{
  5549. //  cout << "Enter the year of birth of Hohol is 1809(yes- 1, no - 0): ";
  5550. //  int choice = getNum();
  5551. //  while (choice != 1)
  5552. //  {
  5553. //      cout << "Think better: ";
  5554. //      hint();
  5555. //      cout << "Enter the year of birth of Hohol is 1809(yes- 1, no - 0): ";
  5556. //      choice = getNum();
  5557. //  }
  5558. //
  5559. //  string cel = "You are right!", name;
  5560. //  cout << cel << "\nEnter your name: ";
  5561. //  cin >> name;
  5562. //  string cel2 = ", pozdr, whe csvety y vas ";
  5563. //  cel = name + cel2;
  5564. //  cel = cel + name;
  5565. //  string m = "This music  for ua";
  5566. //  cel += m;
  5567. //  cout << cel;
  5568. //  return 0;
  5569. //}
  5570.  
  5571. //#include <iostream>
  5572. //using namespace std;
  5573. //
  5574. //void addRightDigit(int d, int& k)
  5575. //{
  5576. //  k = k * 10 + d;
  5577. //}
  5578. //
  5579. //int main()
  5580. //{
  5581. //  int k = 4, d = 5;  
  5582. //  cout << k << endl << d;
  5583. //  addRightDigit(d, k);
  5584. //  d = 2;
  5585. //  cout << endl << k << endl << d;
  5586. //  addRightDigit(d, k);
  5587. //  cout << endl << k;
  5588. //  return 0;
  5589. //}
  5590.  
  5591. //#include <iostream>
  5592. //using namespace std;
  5593. //
  5594. //#define _CRT_SECURE_NO_WARNINGS
  5595. //#pragma warning(disable:4996)
  5596. //
  5597. //float getNum()
  5598. //{
  5599. //  float num;
  5600. //  while (true)
  5601. //  {
  5602. //      cin >> num;
  5603. //      cin.ignore(32767, '\n');
  5604. //      if (cin.fail())
  5605. //      {
  5606. //          cin.clear();
  5607. //          cin.ignore(32767, '\n');
  5608. //          cout << "Bad input. Try again. ";
  5609. //      }
  5610. //      else if (num < 0.0)
  5611. //          cout << "Only positive nums: ";
  5612. //      else
  5613. //          return num;
  5614. //  }
  5615. //}
  5616. //
  5617. //void fillMatrix(float** matrix, int numOfSport, int tries)
  5618. //{
  5619. //  for (int i = 0; i < numOfSport; ++i)
  5620. //  {
  5621. //      cout << "for " << i + 1 << " sportsmen: ";
  5622. //      for (int j = 0; j < tries; ++j)
  5623. //          matrix[i][j] = getNum();
  5624. //  }
  5625. //}
  5626. //
  5627. //float** allocMemory(int numOfSp, int tries)
  5628. //{
  5629. //  float** matrix = new float* [numOfSp];
  5630. //  for (int i = 0; i < numOfSp; ++i)
  5631. //      matrix[i] = new float[tries];
  5632. //  return matrix;
  5633. //}
  5634. //
  5635. //void freeMemory(float** arr, int num)
  5636. //{
  5637. //  for (int i = 0; i < num; ++i)
  5638. //  {
  5639. //      delete[] arr[i];
  5640. //      arr[i] = nullptr;
  5641. //  }
  5642. //  delete[] arr;
  5643. //  arr = nullptr;
  5644. //}
  5645. //
  5646. //void findBest(float** arr, int numOfSp, int tries)
  5647. //{
  5648. //  cout << "\nBest result of sportsmens: \n";
  5649. //  for (int i = 0; i < numOfSp; ++i)
  5650. //  {
  5651. //      cout << "Num of sp - " << i + 1 << endl;
  5652. //      float best = arr[i][0];
  5653. //      int tr = 1;
  5654. //      for (int j = 0; j < tries; ++j)
  5655. //          if (arr[i][j] > best)
  5656. //          {
  5657. //              tr = j + 1;
  5658. //              best = arr[i][j];
  5659. //          }
  5660. //      cout << "Num of try - " << tr << endl;
  5661. //  }
  5662. //}
  5663. //
  5664. //int main()
  5665. //{
  5666. //  const int numOfSportsmens = 5;
  5667. //  const int tries = 3;
  5668. //  float **results = allocMemory(numOfSportsmens, tries);
  5669. //  cout << "Enter the results of competition: \n";
  5670. //  fillMatrix(results, numOfSportsmens, tries);
  5671. //  findBest(results, numOfSportsmens, tries);
  5672. //  freeMemory(results, numOfSportsmens);
  5673. //  return 0;
  5674. //}
  5675.  
  5676. //#include <iostream>
  5677. //using namespace std;
  5678. //
  5679. //int findChastnoe(int delimoe, int delitel)
  5680. //{
  5681. //  int n = delitel;
  5682. //  int count = 1;
  5683. //  while ((n += delitel) <= delimoe)
  5684. //      ++count;
  5685. //  return count;
  5686. //}
  5687. //
  5688. //int findOstatok(int delimoe, int delitel, int chastnoe)
  5689. //{
  5690. //  int temp = 0;
  5691. //  for (int i = 0; i < chastnoe; ++i)
  5692. //      temp += delitel;
  5693. //  return delimoe - temp;
  5694. //}
  5695. //
  5696. //int main()
  5697. //{
  5698. //  int delimoe, delitel;
  5699. //  cout << "Enter delimoe: ";
  5700. //  cin >> delimoe;
  5701. //  cout << "Enter delitel: ";
  5702. //  cin >> delitel;
  5703. //  if (delimoe > delitel)
  5704. //  {
  5705. //      int chastnoe = findChastnoe(delimoe, delitel);
  5706. //      int ostatok = findOstatok(delimoe, delitel, chastnoe);
  5707. //      cout << "Chastnoe = " << chastnoe << endl << "Ostatok = " << ostatok;
  5708. //  }
  5709. //  else
  5710. //      cout << "LOX";
  5711. //  return 0;
  5712. //}
  5713.  
  5714. //#include <iostream>
  5715. //#include <cstdlib>
  5716. //#include <ctime>
  5717. //
  5718. //using namespace std;
  5719. //
  5720. //int** createMatrix(int size)
  5721. //{
  5722. //  int** arr = new int* [size];
  5723. //  for (int i = 0; i < size; ++i)
  5724. //      arr[i] = new int[size];
  5725. //  return arr;
  5726. //}
  5727. //
  5728. //void fillMatrix(int** matrix, int size)
  5729. //{
  5730. //  srand(static_cast<unsigned>(time(0)));
  5731. //  for (int i = 0; i < size; ++i)
  5732. //      for (int j = 0; j < size; ++j)
  5733. //          matrix[i][j] = 1 + rand() % 100;
  5734. //}
  5735. //
  5736. //void showMatrix( int** matrix, int size)
  5737. //{
  5738. //  for (int i = 0; i < size; ++i)
  5739. //  {
  5740. //      for (int j = 0; j < size; ++j)
  5741. //          cout << matrix[i][j] << " ";
  5742. //      cout << endl;
  5743. //  }
  5744. //  cout << endl << endl << endl << endl << endl;
  5745. //}
  5746. //
  5747. //void nullColInMatrix(int** matrix, int size, int colToNull)
  5748. //{
  5749. //  for (int i = 0; i < size; ++i)
  5750. //      matrix[i][colToNull] = 0;
  5751. //}
  5752. //
  5753. //int main()
  5754. //{
  5755. //  const int size = 8;
  5756. //  int** matrix = createMatrix(size);
  5757. //  fillMatrix(matrix, size);
  5758. //
  5759. //  showMatrix(matrix, size);
  5760. //
  5761. //  int colToNull = 1;
  5762. //  nullColInMatrix(matrix, size, colToNull);
  5763. //  showMatrix(matrix, size);
  5764. //
  5765. //  colToNull = 3;
  5766. //  nullColInMatrix(matrix, size, colToNull);
  5767. //  showMatrix(matrix, size);
  5768. //
  5769. //  colToNull = 5;
  5770. //  nullColInMatrix(matrix, size, colToNull);
  5771. //  showMatrix(matrix, size);
  5772. //
  5773. //  return 0;
  5774. //}
  5775.  
  5776. //#include <iostream>
  5777. //using namespace std;
  5778. //
  5779. //int calc(int num, int razr)
  5780. //{
  5781. //  int countNumbers = 0;
  5782. //  int newNum = num;
  5783. //  while (newNum > 0)
  5784. //  {
  5785. //      ++countNumbers;
  5786. //      newNum /= 10;
  5787. //  }
  5788. //  if (countNumbers < razr)
  5789. //      return 0;
  5790. //  int i = 0;
  5791. //  --countNumbers;
  5792. //  newNum = 0;
  5793. //  while (i < razr)
  5794. //  {
  5795. //      int n = num / static_cast<int>(pow(10, countNumbers)) % 10;
  5796. //      newNum = newNum * 10 + n;
  5797. //      ++i; --countNumbers;
  5798. //  }
  5799. //  return newNum;
  5800. //}
  5801. //
  5802. //
  5803. //
  5804. //int main()
  5805. //{
  5806. //  cout << "Enter the num : ";
  5807. //  int num = 0;
  5808. //  cin >> num;
  5809. //  cout << "How many show : ";
  5810. //  int razr;
  5811. //  cin >> razr;
  5812. //  cout << calc(num, razr);
  5813. //  return 0;
  5814. //}
  5815.  
  5816. //#include <iostream>
  5817. //using namespace std;
  5818. //
  5819. //bool slon(int x1, int y1, int x2, int y2)
  5820. //{
  5821. //  bool res = false;
  5822. //  if (abs(x1 - x2) == 2 && abs(y1 - y2) == 1)
  5823. //      res = true;
  5824. //  else if (abs(y1 - y2) == 2 && abs(x1 - x2) == 1)
  5825. //      res = true;
  5826. //  return res;
  5827. //}
  5828. //
  5829. //int main()
  5830. //{
  5831. //  int x1, y1, x2, y2;
  5832. //  cout << "Enter x1: ";
  5833. //  cin >> x1;
  5834. //  cout << "Enter y1: ";
  5835. //  cin >> y1;
  5836. //  cout << "Enter x2: ";
  5837. //  cin >> x2;
  5838. //  cout << "Enter y2: ";
  5839. //  cin >> y2;
  5840. //  if (slon(x1, y1, x2, y2))
  5841. //      cout << "YES\n";
  5842. //  else
  5843. //      cout << "NO\n";
  5844. //  return 0;
  5845. //}
  5846.  
  5847. //#include <iostream>
  5848. //using namespace std;
  5849. //
  5850. //bool slon(int x1, int y1, int x2, int y2)
  5851. //{
  5852. //  bool res = false;
  5853. //  if (abs(x1 - x2) == abs(y1 - y2))
  5854. //      res = true;
  5855. //  return res;
  5856. //}
  5857. //
  5858. //int main()
  5859. //{
  5860. //  int x1, y1, x2, y2;
  5861. //  cout << "Enter x1: ";
  5862. //  cin >> x1;
  5863. //  cout << "Enter y1: ";
  5864. //  cin >> y1;
  5865. //  cout << "Enter x2: ";
  5866. //  cin >> x2;
  5867. //  cout << "Enter y2: ";
  5868. //  cin >> y2;
  5869. //  if (slon(x1, y1, x2, y2))
  5870. //      cout << "YES\n";
  5871. //  else
  5872. //      cout << "NO\n";
  5873. //  return 0;
  5874. //}
  5875.  
  5876. //#include <iostream>
  5877. //using namespace std;
  5878. //
  5879. //bool status(int num)
  5880. //{
  5881. //  if (num % 2 == 0 || num % 3 == 0)
  5882. //      return true;
  5883. //  else
  5884. //      return false;
  5885. //}
  5886. //
  5887. //int main()
  5888. //{
  5889. //  int num;
  5890. //  cin >> num;
  5891. //  if (status(num))
  5892. //      cout << "YES";
  5893. //  else
  5894. //      cout << "NO";
  5895. //  return 0;
  5896. //}
  5897.  
  5898. //#include <iostream>
  5899. //#include <cstdlib>
  5900. //#include <ctime>
  5901. //using namespace std;
  5902. //
  5903. //int getSize()
  5904. //{
  5905. //  int num;
  5906. //  while (true)
  5907. //  {
  5908. //      cin >> num;
  5909. //      cin.ignore(32767, '\n');
  5910. //      if (cin.fail())
  5911. //      {
  5912. //          cin.clear();
  5913. //          cin.ignore(32767, '\n');
  5914. //          cout << "Bad input. ";
  5915. //
  5916. //      }
  5917. //      else if (num <= 1)
  5918. //          cout << "Bad input. ";
  5919. //      else
  5920. //          return num;
  5921. //  }
  5922. //}
  5923. //
  5924. //int** allocMemory(int rows, int cols)
  5925. //{
  5926. //  int** arr = new int* [rows];
  5927. //  for (int i = 0; i < rows; ++i)
  5928. //      arr[i] = new int[cols];
  5929. //  return arr;
  5930. //}
  5931. //
  5932. //void fillMatrix(int** arr, int rows, int cols)
  5933. //{
  5934. //  srand(static_cast<unsigned>(time(0)));
  5935. //  for (int i = 0; i < rows; ++i)
  5936. //      for (int j = 0; j < cols; ++j)
  5937. //          arr[i][j] = -10 + rand() % 20;
  5938. //}
  5939. //
  5940. //void showMatrix(int** arr, int rows, int cols)
  5941. //{
  5942. //  for (int i = 0; i < rows; ++i)
  5943. //  {
  5944. //      for (int j = 0; j < cols; ++j)
  5945. //      {
  5946. //          cout.width(5);
  5947. //          cout << arr[i][j];
  5948. //      }
  5949. //      cout << endl;
  5950. //  }
  5951. //}
  5952. //
  5953. //void showRes(int* arr, int size)
  5954. //{
  5955. //  for (int i = 0; i < size; ++i)
  5956. //      cout << arr[i] << " ";
  5957. //  cout << endl;
  5958. //}
  5959. //
  5960. //
  5961. //int * copyRes(int* arr, int count)
  5962. //{
  5963. //  int* newArr = new int[count];
  5964. //  for (int i = 0; i < count; ++i)
  5965. //      newArr[i] = arr[i];
  5966. //  return newArr;
  5967. //}
  5968. //
  5969. //void deleteArr(int* arr)
  5970. //{
  5971. //  delete[] arr;
  5972. //  arr = nullptr;
  5973. //}
  5974. //
  5975. //int* findSumInPosCols(int** arr, int rows, int cols, int &resSize)
  5976. //{
  5977. //  int* res = new int[cols] {0};
  5978. //  int countOfSuccess = 0;
  5979. //  for (int j = 0; j < cols; ++j)
  5980. //  {
  5981. //      bool suc = true;
  5982. //      int sum = 0;
  5983. //      for (int i = 0; i < rows; ++i)
  5984. //      {
  5985. //          if (arr[i][j] < 0)
  5986. //          {
  5987. //              suc = false;
  5988. //              break;
  5989. //          }
  5990. //          else
  5991. //              sum += arr[i][j];
  5992. //      }
  5993. //      if(suc)
  5994. //          res[countOfSuccess++] = sum;
  5995. //  }
  5996. //  resSize = countOfSuccess;
  5997. //  int* newArr = copyRes(res, countOfSuccess);
  5998. //  deleteArr(res);
  5999. //  return newArr;
  6000. //}
  6001. //
  6002. //void deleteMatrix(int** arr, int size)
  6003. //{
  6004. //  for (int i = 0; i < size; ++i)
  6005. //  {
  6006. //      delete [] arr[i];
  6007. //      arr[i] = nullptr;
  6008. //  }
  6009. //  delete[] arr;
  6010. //  arr = nullptr;
  6011. //}
  6012. //
  6013. //int main()
  6014. //{
  6015. //  int rows, cols;
  6016. //  cout << "Enter the number of rows: ";
  6017. //  rows = getSize();
  6018. //  cout << "Enter the number of columns: ";
  6019. //  cols = getSize();
  6020. //  int** arr = allocMemory(rows, cols);
  6021. //  fillMatrix(arr, rows, cols);
  6022. //  showMatrix(arr, rows, cols);
  6023. //  int resSize = 0;
  6024. //  int* res = findSumInPosCols(arr, rows, cols, resSize);
  6025. //  showRes(res, resSize);
  6026. //  deleteMatrix(arr, rows);
  6027. //  deleteArr(res);
  6028. //  return 0;
  6029. //}
  6030.  
  6031. //#include <iostream>
  6032. //using namespace std;
  6033. //
  6034. //int getSize()
  6035. //{
  6036. //  int num;
  6037. //  while (true)
  6038. //  {
  6039. //      cin >> num;
  6040. //      cin.ignore(32767, '\n');
  6041. //      if (cin.fail())
  6042. //      {
  6043. //          cin.clear();
  6044. //          cin.ignore(32767, '\n');
  6045. //          cout << "Bad input. ";
  6046. //      }
  6047. //      else if (num < 1)
  6048. //          cout << "Bad input. ";
  6049. //      else
  6050. //          return num;
  6051. //  }
  6052. //}
  6053. //
  6054. //int getNum()
  6055. //{
  6056. //  int num;
  6057. //  while (true)
  6058. //  {
  6059. //      cin >> num;
  6060. //      cin.ignore(32767, '\n');
  6061. //      if (cin.fail())
  6062. //      {
  6063. //          cin.clear();
  6064. //          cin.ignore(32767, '\n');
  6065. //          cout << "Bad input. ";
  6066. //      }
  6067. //      else
  6068. //          return num;
  6069. //  }
  6070. //}
  6071. //
  6072. //void fillArray(int* arr, int size)
  6073. //{
  6074. //  for (int i = 0; i < size; ++i)
  6075. //      arr[i] = getNum();
  6076. //}
  6077. //
  6078. //void showArray(int* arr, int size)
  6079. //{
  6080. //  for (int i = 0; i < size; ++i)
  6081. //      cout << arr[i] << " ";
  6082. //}
  6083. //
  6084. //void copyArr(int* source, int* target, int size)
  6085. //{
  6086. //  for (int i = 0; i < size; ++i)
  6087. //      target[i] = source[i];
  6088. //}
  6089. //
  6090. //void deleteNum(int* arr, int &size, int numToDelete)
  6091. //{
  6092. //  int* newArr = new int[size - 1];
  6093. //  for (int i = 0, count = 0; i < size; ++i)
  6094. //      if (i != numToDelete)
  6095. //          newArr[count++] = arr[i];
  6096. //  --size;
  6097. //  delete arr;
  6098. //  arr = new int[size];
  6099. //  copyArr(newArr, arr, size);
  6100. //}
  6101. //
  6102. //int main()
  6103. //{
  6104. //  int size;
  6105. //  cout << "Enter the size - ";
  6106. //  size = getSize();
  6107. //  int* arr = new int[size];
  6108. //  fillArray(arr, size);
  6109. //  showArray(arr, size);
  6110. //  cout << "Enter the num of element to delete - ";
  6111. //  int numToDelete = getNum();
  6112. //  if (numToDelete < size)
  6113. //  {
  6114. //      deleteNum(arr, size, numToDelete);
  6115. //      showArray(arr, size);
  6116. //  }
  6117. //  return 0;
  6118. //}
  6119.  
  6120. //#include <iostream>
  6121. //#include <fstream>
  6122. //
  6123. //using namespace std;
  6124. //
  6125. //int main()
  6126. //{
  6127. //  cout << "Enter file path: ";
  6128. //  string filePath;
  6129. //  cin >> filePath;
  6130. //  ifstream ifs;
  6131. //  ifs.open(filePath);
  6132. //  if (ifs.fail() || !ifs.is_open())
  6133. //      return -1;
  6134. //  char ch;
  6135. //  int count = 0;
  6136. //  string temp = "";
  6137. //  while (!ifs.eof())
  6138. //  {
  6139. //      ch = ifs.get();
  6140. //      bool succ = true;
  6141. //      ++count;
  6142. //
  6143. //      for (int i = 0; i < count; ++i)
  6144. //          if (ch == temp[i])
  6145. //          {
  6146. //              succ = false;
  6147. //              break;
  6148. //          }
  6149. //      if (succ)
  6150. //          cout << ch;
  6151. //      temp += ch;
  6152. //
  6153. //  }
  6154. //  return 0;
  6155. //}
  6156.  
  6157. //#include <iostream>
  6158. //#include <cstring>
  6159. //using namespace std;
  6160. //#define _CRT_SECURE_NO_WARNINGS
  6161. //#pragma warning(disable:4996)
  6162. //
  6163. //int main()
  6164. //{
  6165. //  cout << "Enter the string of numbers: ";
  6166. //  char str[256];
  6167. //  cin.getline(str, 256);
  6168. //  cout << str;
  6169. //  char* pch = strtok(str, ",");
  6170. //  int sum = 0;
  6171. //  while (pch != NULL)
  6172. //  {
  6173. //      sum += atoi(pch);
  6174. //      pch = strtok(NULL, ",");
  6175. //  }
  6176. //  cout << endl << endl << sum << endl;
  6177. //
  6178. //  return 0;
  6179. //}
  6180.  
  6181. //#include <iostream>
  6182. //using namespace std;
  6183. //
  6184. //int getNum()
  6185. //{
  6186. //  int num;
  6187. //  while (true)
  6188. //  {
  6189. //      cin >> num;
  6190. //      cin.ignore(32767, '\n');
  6191. //      if (cin.fail())
  6192. //      {
  6193. //          cin.clear();
  6194. //          cin.ignore(32767, '\n');
  6195. //          cout << "Bad input. Try again - ";
  6196. //      }
  6197. //      else
  6198. //          return num;
  6199. //  }
  6200. //}
  6201. //
  6202. //int getSize()
  6203. //{
  6204. //  int num;
  6205. //  while (true)
  6206. //  {
  6207. //      cin >> num;
  6208. //      cin.ignore(32767, '\n');
  6209. //      if (cin.fail())
  6210. //      {
  6211. //          cin.clear();
  6212. //          cin.ignore(32767, '\n');
  6213. //          cout << "Bad input. Try again - ";
  6214. //      }
  6215. //      else if (num <= 1)
  6216. //          cout << "Bad input. Try again - ";
  6217. //      else
  6218. //          return num;
  6219. //  }
  6220. //}
  6221. //
  6222. //class Matrix
  6223. //{
  6224. //  int rows;
  6225. //  int cols;
  6226. //  int** arr;
  6227. //public:
  6228. //  Matrix();
  6229. //  Matrix(int r, int c);
  6230. //  Matrix(Matrix& matrix);
  6231. //  ~Matrix();
  6232. //  Matrix& operator=(Matrix& matrix);
  6233. //  Matrix operator+(Matrix& matrix);
  6234. //  //Matrix operator*(Matrix& matrix);
  6235. //  friend istream& operator>>(istream& is, const Matrix& matrix);
  6236. //  friend ostream& operator<<(ostream& os, const Matrix& matrix);
  6237. //
  6238. //};
  6239. //
  6240. //Matrix::Matrix() : rows(0), cols(0)
  6241. //{
  6242. //  arr = nullptr;
  6243. //}
  6244. //
  6245. //Matrix::Matrix(int r, int c) : rows(r), cols(c)
  6246. //{
  6247. //  arr = new int* [rows];
  6248. //  for (int i = 0; i < rows; ++i)
  6249. //      arr[i] = new int[cols];
  6250. //}
  6251. //
  6252. //Matrix::~Matrix()
  6253. //{
  6254. //  for (int i = 0; i < rows; ++i)
  6255. //  {
  6256. //      delete[] arr[i];
  6257. //      arr[i] = nullptr;
  6258. //  }
  6259. //  delete[] arr;
  6260. //  arr = nullptr;
  6261. //}
  6262. //
  6263. //Matrix::Matrix(Matrix& matrix)
  6264. //{
  6265. //  rows = matrix.rows;
  6266. //  cols = matrix.cols;
  6267. //  arr = new int* [rows];
  6268. //  for (int i = 0; i < rows; ++i)
  6269. //      arr[i] = new int[cols];
  6270. //  for (int i = 0; i < rows; ++i)
  6271. //      for (int j = 0; j < cols; ++j)
  6272. //          arr[i][j] = matrix.arr[i][j];
  6273. //}
  6274. //
  6275. //Matrix& Matrix::operator=(Matrix& matrix)
  6276. //{
  6277. //  if (&matrix == this)
  6278. //      return *this;
  6279. //  for (int i = 0; i < rows; ++i)
  6280. //  {
  6281. //      delete[] arr[i];
  6282. //      arr[i] = nullptr;
  6283. //  }
  6284. //  delete[] arr;
  6285. //  rows = matrix.rows;
  6286. //  cols = matrix.cols;
  6287. //  arr = new int* [rows];
  6288. //  for (int i = 0; i < rows; ++i)
  6289. //      arr[i] = new int[cols];
  6290. //  for (int i = 0; i < rows; ++i)
  6291. //      for (int j = 0; j < cols; ++j)
  6292. //          arr[i][j] = matrix.arr[i][j];
  6293. //  return *this;
  6294. //}
  6295. //
  6296. //Matrix Matrix::operator+(Matrix& matrix)
  6297. //{
  6298. //  if (rows != matrix.rows || cols != matrix.cols)
  6299. //  {
  6300. //      Matrix res;
  6301. //      return res;
  6302. //  }
  6303. //  Matrix res(rows, cols);
  6304. //  for (int i = 0; i < rows; ++i)
  6305. //      for (int j = 0; j < cols; ++j)
  6306. //          res.arr[i][j] = arr[i][j] + matrix.arr[i][j];
  6307. //  return res;
  6308. //}
  6309. //
  6310. ////Matrix Matrix::operator*(Matrix& matrix)
  6311. ////{
  6312. ////    if (cols != matrix.rows)
  6313. ////        return;
  6314. ////    Matrix res(rows, matrix.cols);
  6315. ////    for (int i = 0; i < res.rows; ++i)
  6316. ////    {
  6317. ////        for (int j = 0; j < res.cols; ++j)
  6318. ////            ;
  6319. ////    }
  6320. ////}
  6321. //
  6322. //istream& operator>>(istream& is, const Matrix& matrix)
  6323. //{
  6324. //  cout << "\nEnter the elements of matrix: \n";
  6325. //  for (int i = 0; i < matrix.rows; ++i)
  6326. //      for (int j = 0; j < matrix.cols; ++j)
  6327. //      {
  6328. //          cout << "Enter [" << i << "][" << j << "] - ";
  6329. //          matrix.arr[i][j] = getNum();
  6330. //      }
  6331. //  cout << endl;
  6332. //  return is;
  6333. //}
  6334. //
  6335. //ostream& operator<<(ostream& os, const Matrix& matrix)
  6336. //{
  6337. //  os << endl << "Your matrix : \n";
  6338. //  for (int i = 0; i < matrix.rows; ++i)
  6339. //  {
  6340. //      for (int j = 0; j < matrix.cols; ++j)
  6341. //          os << matrix.arr[i][j] << " ";
  6342. //      os << endl;
  6343. //  }
  6344. //  os << endl;
  6345. //  return os;
  6346. //}
  6347. //
  6348. //int main()
  6349. //{
  6350. //  Matrix M1(2, 3);
  6351. //  cin >> M1;
  6352. //  int M2rows, M2cols;
  6353. // 
  6354. //  cout << "Enter rows - ";
  6355. //  M2rows = getSize();
  6356. //  cout << "Enter cols - ";
  6357. //  M2cols = getSize();
  6358. //
  6359. //  Matrix M2(M2rows, M2cols);
  6360. //  cin >> M2;
  6361. //
  6362. //  cout << M1 << M2 << M1 + M2;
  6363. //
  6364. //
  6365. //
  6366. //  return 0;
  6367. //}
  6368.  
  6369. //#include <iostream>
  6370. //#include <cstring>
  6371. //#include <string>
  6372. //using namespace std;
  6373. //#define _CRT_SECURE_NO_WARNINGS
  6374. //#pragma warning(disable:4996)
  6375. //int main()
  6376. //{
  6377. //  char str[256];
  6378. //  cin.getline(str, 256);
  6379. //  int count = 0;
  6380. //  int max = 0;
  6381. //  string res = "";
  6382. //  char* pcd = strtok(str, " .");
  6383. // 
  6384. //  while (pcd != NULL)
  6385. //  {
  6386. //      ++count;
  6387. //      if (strlen(pcd) > res.size())
  6388. //      {
  6389. //          res = pcd;
  6390. //          max = count;
  6391. //      }
  6392. //      pcd = strtok(NULL, " .");
  6393. //  }
  6394. //  cout << endl << endl << res << endl << max;
  6395. //  return 0;
  6396. //}
  6397.  
  6398. //#include <iostream>
  6399. //#include <cstring>
  6400. //#include <string>
  6401. //using namespace std;
  6402. //#define _CRT_SECURE_NO_WARNINGS
  6403. //#pragma warning(disable:4996)
  6404. //
  6405. //int main()
  6406. //{
  6407. //  char str[256];
  6408. //  cin.getline(str, 256);
  6409. //  int count = 0;
  6410. //  int max = 1;
  6411. // 
  6412. //  char* pcd = strtok(str, " .");
  6413. //  string res = pcd;
  6414. //  while (pcd != NULL)
  6415. //  {
  6416. //      ++count;
  6417. //      if (strlen(pcd) < res.size())
  6418. //      {
  6419. //          res = pcd;
  6420. //          max = count;
  6421. //      }
  6422. //      pcd = strtok(NULL, " .");
  6423. //  }
  6424. //  cout << endl << endl << res << endl << max;
  6425. //  return 0;
  6426. //}
  6427.  
  6428. //#include <iostream>
  6429. //#include <cstring>
  6430. //#define _CRT_SECURE_NO_WARNINGS
  6431. //#pragma warning(disable:4996)
  6432. //using namespace std;
  6433. //int main()
  6434. //{
  6435. //  const int size = 256;
  6436. //  char str[size];
  6437. //  int i = 0;
  6438. //  while ((str[i++] = cin.get()) != '.' && i < size);
  6439. //  str[i] = '\0';
  6440. //  cout << endl << endl << str << endl << endl;
  6441. //  char* pcd = strtok(str, " ");
  6442. //  string res = "";
  6443. //  while (pcd != NULL)
  6444. //  {
  6445. //      if (strlen(pcd) > 1)
  6446. //      {
  6447. //          res += " ";
  6448. //          res += &pcd[1];
  6449. //      }
  6450. //      pcd = strtok(NULL, " ");
  6451. //  }
  6452. //  cout << res;
  6453. //
  6454. //  return 0;
  6455. //}
  6456.  
  6457. //#include <iostream>
  6458. //using namespace std;
  6459. //
  6460. //int lengthString(char* str)
  6461. //{
  6462. //  if (str == NULL)
  6463. //      return 0;
  6464. //  int count = 0;
  6465. //  while (str[count] != '\0')
  6466. //      ++count;
  6467. //  return count;
  6468. //}
  6469. //
  6470. //char* reverseString(char* source)
  6471. //{
  6472. //  if (source == NULL)
  6473. //      exit(1);
  6474. //  char* target = new char[lengthString(source)];
  6475. //  for (int i = lengthString(source) - 1, j = 0; i >= 0; --i, ++j)
  6476. //      target[j] = source[i];
  6477. //  target[lengthString(source)] = '\0';
  6478. //  return target;
  6479. //}
  6480. //
  6481. //int balanceBrackets(char* str)
  6482. //{
  6483. //  if (str == NULL)
  6484. //      return 0;
  6485. //  bool noBrackets = true;
  6486. //  bool balanced = true;
  6487. //  int countSquare = 0, countRound = 0, countFigure = 0;
  6488. //  int i = 0;
  6489. //  while (str[i] != '\0')
  6490. //  {
  6491. //      if (str[i] == '{')
  6492. //      {
  6493. //          ++countFigure;
  6494. //          noBrackets = false;
  6495. //      }
  6496. //      else if (str[i] == '}')
  6497. //      {
  6498. //          --countFigure;
  6499. //          noBrackets = false;
  6500. //      }
  6501. //      else if (str[i] == '(')
  6502. //      {
  6503. //          ++countRound;
  6504. //          noBrackets = false;
  6505. //      }
  6506. //      else if (str[i] == ')')
  6507. //      {
  6508. //          --countRound;
  6509. //          noBrackets = false;
  6510. //      }
  6511. //      else if (str[i] == '[')
  6512. //      {
  6513. //          ++countSquare;
  6514. //          noBrackets = false;
  6515. //      }
  6516. //      else if (str[i] == ']')
  6517. //      {
  6518. //          --countSquare;
  6519. //          noBrackets = false;
  6520. //      }
  6521. //      ++i;
  6522. //  }
  6523. //  if (noBrackets)
  6524. //      return -1;
  6525. //  if (countFigure != 0 || countRound != 0 || countSquare != 0)
  6526. //      return 0;
  6527. //  return 1;      
  6528. //}
  6529. //
  6530. //int occurenceSubstring(char* str, char* subStr)
  6531. //{
  6532. //  if (str == NULL || subStr == NULL)
  6533. //      return 0;
  6534. //  int i = 0, pos = 0;
  6535. //  bool found = true;
  6536. //  while (str[i] != '\0')
  6537. //  {
  6538. //      if (str[i] == subStr[0])
  6539. //      {
  6540. //          found = true;
  6541. //          for (int j = i, count = 0; count < lengthString(subStr); ++j, ++count)
  6542. //              if (str[j] != subStr[count])
  6543. //              {
  6544. //                  found = false;
  6545. //                  break;
  6546. //              }
  6547. //          if (found)
  6548. //          {
  6549. //              pos = i + 1;
  6550. //              break;
  6551. //          }
  6552. //      }
  6553. //      ++i;
  6554. //  }
  6555. //  return pos;
  6556. //}
  6557. //
  6558. //char* insertnString(char* str1, char* str2, int n)
  6559. //{
  6560. //  if (str1 == NULL || str2 == NULL)
  6561. //      exit(1);
  6562. //  int size = lengthString(str1) + lengthString(str2) + 1;
  6563. //  if (n > size)
  6564. //      exit(1);
  6565. //  char* newStr = new char[size];
  6566. //  for (int i = 0; i < n - 1; ++i)
  6567. //      newStr[i] = str1[i];
  6568. //  for (int i = n - 1, j = 0; j < lengthString(str2); ++j, ++i)
  6569. //      newStr[i] = str2[j];
  6570. //  for (int i = lengthString(str2) + n - 1, j = n - 1; i < size; ++i, ++j)
  6571. //      newStr[i] = str1[j];
  6572. //  newStr[size] = '\0';
  6573. //  return newStr;
  6574. //}
  6575. //
  6576. //char* cutString(char* str, int pos, int k)
  6577. //{
  6578. //  int size = lengthString(str);
  6579. //  if (pos + k > size)
  6580. //      exit(1);
  6581. //  char* newStr = new char[k + 1];
  6582. //  for (int i = pos - 1, j = 0; j < k; ++j, ++i)
  6583. //      newStr[j] = str[i];
  6584. //  newStr[k] = '\0';
  6585. //  return newStr;
  6586. //}
  6587. //
  6588. //int main()
  6589. //{
  6590. //  char str[] = "cppstudio.com";
  6591. //  cout << cutString(str, 4, 6);
  6592. //  return 0;
  6593. //}
  6594.  
  6595. //#include <iostream>
  6596. //#include <ctime>
  6597. //#include <cstdlib>
  6598. //
  6599. //using namespace std;
  6600. //
  6601. //int** createMatrix(int size)
  6602. //{
  6603. //  int** arr = new int* [size];
  6604. //  for (int i = 0; i < size; ++i)
  6605. //      arr[i] = new int[size];
  6606. //  return arr;
  6607. //}
  6608. //
  6609. //void fillMatrix(int** arr, int size)
  6610. //{
  6611. //  srand(static_cast<unsigned>(time(0)));
  6612. //  for (int i = 0; i < size; ++i)
  6613. //      for (int j = 0; j < size; ++j)
  6614. //          arr[i][j] = rand() % 100;
  6615. //}
  6616. //
  6617. //int findMin(int** arr, int size, int& minI, int& minJ)
  6618. //{
  6619. //  int min = arr[1][0];
  6620. //  for(int i = 0; i < size; ++i)
  6621. //      for(int j = 0; j < i; ++j)
  6622. //          if (arr[i][j] < min)
  6623. //          {
  6624. //              min = arr[i][j];
  6625. //              minI = i;
  6626. //              minJ = j;
  6627. //          }
  6628. //  return min;
  6629. //}
  6630. //
  6631. //int findMax(int** arr, int size, int& maxI, int& maxJ)
  6632. //{
  6633. //  int max = arr[0][1];
  6634. //  for (int i = 0; i < size; ++i)
  6635. //      for (int j = i + 1; j < size; ++j)
  6636. //          if (arr[i][j] > max)
  6637. //          {
  6638. //              max = arr[i][j];
  6639. //              maxI = i;
  6640. //              maxJ = j;
  6641. //          }
  6642. //  return max;
  6643. //}
  6644. //
  6645. //void showMatrix(int** arr, int size)
  6646. //{
  6647. //  for (int i = 0; i < size; ++i)
  6648. //  {
  6649. //      for (int j = 0; j < size; ++j)
  6650. //      {
  6651. //          cout.width(4);
  6652. //          cout << arr[i][j] << " ";
  6653. //      }
  6654. //      cout << endl;
  6655. //  }
  6656. //}
  6657. //
  6658. //void swapElements(int** matrix, int minI, int minJ, int maxI, int maxJ)
  6659. //{
  6660. //  int temp = matrix[minI][minJ];
  6661. //  matrix[minI][minJ] = matrix[maxI][maxJ];
  6662. //  matrix[maxI][maxJ] = temp;
  6663. //}
  6664. //
  6665. //int getSize()
  6666. //{
  6667. //  int num;
  6668. //  while (true)
  6669. //  {
  6670. //      cin >> num;
  6671. //      cin.ignore(32767, '\n');
  6672. //      if (cin.fail())
  6673. //      {
  6674. //          cin.clear();
  6675. //          cin.ignore(32767, '\n');
  6676. //          cout << "Bad input. ";
  6677. //      }
  6678. //      else if (num <= 1)
  6679. //          cout << "Bad input. ";
  6680. //      else
  6681. //          return num;
  6682. //  }
  6683. //}
  6684. //
  6685. //int main()
  6686. //{
  6687. //  cout << "Enter the size of square matrix: ";
  6688. //  int size = getSize();
  6689. //  int **matrix = createMatrix(size);
  6690. //  fillMatrix(matrix, size);
  6691. //  showMatrix(matrix, size);
  6692. //  int max = matrix[0][0], maxI = 0, maxJ = 1, min = matrix[0][0], minI = 1, minJ = 0;
  6693. //  min = findMin(matrix, size, minI, minJ);
  6694. //  max = findMax(matrix, size, maxI, maxJ);
  6695. //
  6696. //  cout << "\n\nMin[" << minI << "][" << minJ << "] = " << min << endl;
  6697. //  cout << "\nMax[" << maxI << "][" << maxJ << "] = " << max << endl << endl;
  6698. //
  6699. //  swapElements(matrix, minI, minJ, maxI, maxJ);
  6700. //  showMatrix(matrix, size);
  6701. //  return 0;
  6702. //}
  6703.  
  6704. //#include <iostream>
  6705. //
  6706. //using namespace std;
  6707. //
  6708. //class Array
  6709. //{
  6710. //  int* pArr;
  6711. //  int size;
  6712. //public:
  6713. //  Array();
  6714. //  Array(int size_);
  6715. //  Array(const Array& arr);
  6716. //  ~Array();
  6717. //  int findElementByKey(int key) const;
  6718. //  void sortByHigher();
  6719. //  void sortByLower();
  6720. //  int getSize() const;
  6721. //
  6722. //  friend istream& operator>>(istream& is, Array& arr);
  6723. //  friend ostream& operator<<(ostream& os, const Array& arr);
  6724. //
  6725. //  Array operator+(const Array& arr) const;
  6726. //  Array operator-(int num) const;
  6727. //  Array& operator=(const Array& arr);
  6728. //  void operator+=(int num);
  6729. //  int operator==(const Array& arr) const;
  6730. //  int& operator[](int position);
  6731. //  Array operator-(const Array& arr) const;
  6732. //};
  6733. //
  6734. //int Array::getSize() const
  6735. //{
  6736. //  return size;
  6737. //}
  6738. //
  6739. //Array::Array()
  6740. //{
  6741. //  pArr = nullptr;
  6742. //  size = 0;
  6743. //}
  6744. //
  6745. //Array::Array(int size_) : size(size_)
  6746. //{
  6747. //  pArr = new int[size];
  6748. //}
  6749. //
  6750. //Array::Array(const Array& arr)
  6751. //{
  6752. //  size = arr.size;
  6753. //  pArr = new int[size];
  6754. //  for (int i = 0; i < size; ++i)
  6755. //      pArr[i] = arr.pArr[i];
  6756. //}
  6757. //
  6758. //Array::~Array()
  6759. //{
  6760. //  size = 0;
  6761. //  delete[] pArr;
  6762. //  pArr = nullptr;
  6763. //}
  6764. //
  6765. //int Array::findElementByKey(int key) const
  6766. //{
  6767. //  for (int i = 0; i < size; ++i)
  6768. //      if (pArr[i] == key)
  6769. //          return i;
  6770. //  return -1;
  6771. //}
  6772. //
  6773. //void Array::sortByHigher()
  6774. //{
  6775. //  int temp;
  6776. //  for(int i = 0; i < size - 1; ++i)
  6777. //      for(int j = i + 1; j < size; ++j)
  6778. //          if (pArr[i] > pArr[j])
  6779. //          {
  6780. //              temp = pArr[i];
  6781. //              pArr[i] = pArr[j];
  6782. //              pArr[j] = temp;
  6783. //          }
  6784. //}
  6785. //
  6786. //void Array::sortByLower()
  6787. //{
  6788. //  int temp;
  6789. //  for (int i = 0; i < size - 1; ++i)
  6790. //      for (int j = i + 1; j < size; ++j)
  6791. //          if (pArr[i] < pArr[j])
  6792. //          {
  6793. //              temp = pArr[i];
  6794. //              pArr[i] = pArr[j];
  6795. //              pArr[j] = temp;
  6796. //          }
  6797. //}
  6798. //
  6799. //int getNum()
  6800. //{
  6801. //  int num;
  6802. //  while (true)
  6803. //  {
  6804. //      cin >> num;
  6805. //      cin.ignore(32767, '\n');
  6806. //      if (cin.fail())
  6807. //      {
  6808. //          cin.clear();
  6809. //          cin.ignore(32767, '\n');
  6810. //          cout << "Bad input. Try again - ";
  6811. //      }
  6812. //      else
  6813. //          return num;
  6814. //  }
  6815. //}
  6816. //
  6817. //istream& operator>>(istream& is, Array& arr)
  6818. //{
  6819. //  for (int i = 0; i < arr.size; ++i)
  6820. //  {
  6821. //      cout << "Enter [" << i << "] - ";
  6822. //      arr.pArr[i] = getNum();
  6823. //  }
  6824. //  return is;
  6825. //}
  6826. //
  6827. //ostream& operator<<(ostream& os, const Array& arr)
  6828. //{
  6829. //  for (int i = 0; i < arr.size; ++i)
  6830. //      os << arr.pArr[i] << " ";
  6831. //  os << endl;
  6832. //  return os;
  6833. //}
  6834. //
  6835. //Array Array::operator+(const Array& arr) const
  6836. //{
  6837. //  if (size != arr.size)
  6838. //      exit(1);
  6839. //  Array res(size);
  6840. //  for (int i = 0; i < size; ++i)
  6841. //      res.pArr[i] = pArr[i] + arr.pArr[i];
  6842. //  return res;
  6843. //}
  6844. //
  6845. //Array& Array::operator=(const Array& arr)
  6846. //{
  6847. //  if (this == &arr)
  6848. //      return *this;
  6849. //  delete[] pArr;
  6850. //  pArr = nullptr;
  6851. //  size = arr.size;
  6852. //  pArr = new int[size];
  6853. //  for (int i = 0; i < size; ++i)
  6854. //      pArr[i] = arr.pArr[i];
  6855. //  return *this;
  6856. //}
  6857. //
  6858. //int Array::operator==(const Array& arr) const
  6859. //{
  6860. //  if (size != arr.size)
  6861. //      return -1;
  6862. //  int equal = 1;
  6863. //  for(int i = 0; i < size; ++i)
  6864. //      if (pArr[i] != arr.pArr[i])
  6865. //      {
  6866. //          equal = 0;
  6867. //          break;
  6868. //      }
  6869. //  return equal;
  6870. //}
  6871. //
  6872. //void Array::operator+=(int num)
  6873. //{
  6874. //  int* temp = new int[static_cast<size_t>(size) + 1];
  6875. //  for (int i = 0; i < size; ++i)
  6876. //      temp[i] = pArr[i];
  6877. //  temp[size] = num;
  6878. //  delete[] pArr;
  6879. //  ++size;
  6880. //  pArr = new int[size];
  6881. //  for (int i = 0; i < size; ++i)
  6882. //      pArr[i] = temp[i];
  6883. //}
  6884. //
  6885. //Array Array::operator-(int num) const
  6886. //{
  6887. //  int key = this->findElementByKey(num);
  6888. //  if (key == -1)
  6889. //  {
  6890. //      Array res;
  6891. //      return res;
  6892. //  }
  6893. //  Array res(size - 1);
  6894. //  for (int i = 0, j = 0; i < size; ++i)
  6895. //      if (i != key)
  6896. //          res.pArr[j++] = pArr[i];
  6897. //  return res;
  6898. //}
  6899. //
  6900. //int& Array::operator[](int pos)
  6901. //{
  6902. //  if (pos >= size)
  6903. //      exit(1);
  6904. //  return pArr[pos];
  6905. //}
  6906. //
  6907. //Array Array::operator-(const Array& arr) const
  6908. //{
  6909. //  if (size != arr.size)
  6910. //      exit(1);
  6911. //  Array res(size);
  6912. //  for (int i = 0; i < size; ++i)
  6913. //      res.pArr[i] = pArr[i] - arr.pArr[i];
  6914. //  return res;
  6915. //}
  6916. //
  6917. //class Matrix
  6918. //{
  6919. //  Array* pMatr;
  6920. //  int size;
  6921. //public:
  6922. //  Matrix();
  6923. //  Matrix(int size_);
  6924. //  Matrix(const Matrix& matrix);
  6925. //  ~Matrix();
  6926. //  friend istream& operator>>(istream& is, Matrix& matrix);
  6927. //  friend ostream& operator<<(ostream& os, const Matrix& matrix);
  6928. //  void showMatrix() const;
  6929. //  void fillMatrix();
  6930. //  int findElementByKey(int key) const;
  6931. //  Matrix operator+(const Matrix& matrix) const;
  6932. //  Matrix& operator+=(const Matrix& matrix);
  6933. //  Matrix operator-(const Matrix& matrix) const;
  6934. //  Matrix& operator=(const Matrix& matrix);
  6935. //  int operator==(const Matrix& matrix) const;
  6936. //  Array& operator[](int num);
  6937. //};
  6938. //
  6939. //Matrix::Matrix()
  6940. //{
  6941. //  pMatr = nullptr;
  6942. //  size = 0;
  6943. //}
  6944. //
  6945. //Matrix::Matrix(int size_) : size(size_)
  6946. //{
  6947. //  pMatr = new Array[size];
  6948. //  for (int i = 0; i < size; ++i)
  6949. //      pMatr[i] = Array(size);
  6950. //}
  6951. //
  6952. //Matrix::Matrix(const Matrix& matrix)
  6953. //{
  6954. //  size = matrix.size;
  6955. //  pMatr = new Array[size];
  6956. //  for (int i = 0; i < size; ++i)
  6957. //      pMatr[i] = matrix.pMatr[i];
  6958. //}
  6959. //
  6960. //Matrix::~Matrix()
  6961. //{
  6962. //  delete[] pMatr;
  6963. //  pMatr = nullptr;
  6964. //}
  6965. //
  6966. //istream& operator>>(istream& is, Matrix& matrix)
  6967. //{
  6968. //  cout << endl;
  6969. //  for (int i = 0; i < matrix.size; ++i)
  6970. //  {
  6971. //      cout << "Enter the elements of row " << i << " - \n";
  6972. //      is >> matrix.pMatr[i];
  6973. //  }
  6974. //  return is;
  6975. //}
  6976. //
  6977. //ostream& operator<<(ostream& os, const Matrix& matrix)
  6978. //{
  6979. //  os << endl;
  6980. //  for (int i = 0; i < matrix.size; ++i)
  6981. //      os << matrix.pMatr[i];
  6982. //  os << endl;
  6983. //  return os;
  6984. //}
  6985. //
  6986. //int Matrix::findElementByKey(int key) const
  6987. //{
  6988. //  for (int i = 0; i < size; ++i)
  6989. //      if (pMatr[i].findElementByKey(key) != -1)
  6990. //          return i;
  6991. //  return -1;
  6992. //}
  6993. //
  6994. //void Matrix::showMatrix() const
  6995. //{
  6996. //  cout << endl;
  6997. //  for (int i = 0; i < size; ++i)
  6998. //      cout << pMatr[i] << endl;
  6999. //
  7000. //}
  7001. //
  7002. //void Matrix::fillMatrix()
  7003. //{
  7004. //  for (int i = 0; i < size; ++i)
  7005. //      cin >> pMatr[i];
  7006. //}
  7007. //
  7008. //Matrix Matrix::operator+(const Matrix& matrix) const
  7009. //{
  7010. //  if (size != matrix.size)
  7011. //      exit(1);
  7012. //  Matrix res(size);
  7013. //  for (int i = 0; i < size; ++i)
  7014. //      res.pMatr[i] = pMatr[i] + matrix.pMatr[i];
  7015. //  return res;
  7016. //}
  7017. //
  7018. //Matrix& Matrix::operator+=(const Matrix& matrix)
  7019. //{
  7020. //  if (size != matrix.size)
  7021. //      exit(1);
  7022. //  for (int i = 0; i < size; ++i)
  7023. //      pMatr[i] = pMatr[i] + matrix.pMatr[i];
  7024. //  return *this;
  7025. //}
  7026. //
  7027. //Matrix Matrix::operator-(const Matrix& matrix) const
  7028. //{
  7029. //  if (size != matrix.size)
  7030. //      exit(1);
  7031. //  Matrix res(size);
  7032. //  for (int i = 0; i < size; ++i)
  7033. //      res.pMatr[i] = pMatr[i] - matrix.pMatr[i];
  7034. //  return res;
  7035. //}
  7036. //
  7037. //Matrix& Matrix::operator=(const Matrix& matrix)
  7038. //{
  7039. //  if (this == &matrix)
  7040. //      return *this;
  7041. //  delete[] pMatr;
  7042. //  size = matrix.size;
  7043. //  pMatr = new Array[size];
  7044. //  for (int i = 0; i < size; ++i)
  7045. //      pMatr[i] = matrix.pMatr[i];
  7046. //  return *this;
  7047. //}
  7048. //
  7049. //int Matrix::operator==(const Matrix& matrix) const
  7050. //{
  7051. //  if (size != matrix.size)
  7052. //      return -1;
  7053. //  for (int i = 0; i < size; ++i)
  7054. //      if ((pMatr[i] == matrix.pMatr[i]) == 0)
  7055. //          return 0;
  7056. //  return 1;
  7057. //}
  7058. //
  7059. //Array& Matrix::operator[](int num)
  7060. //{
  7061. //  if (num >= size)
  7062. //      exit(1);
  7063. //  return pMatr[num];
  7064. //}
  7065. //
  7066. //int main()
  7067. //{
  7068. //  Matrix M1(2);
  7069. //  cin >> M1;
  7070. //  cout << M1;
  7071. //  Matrix M2(2);
  7072. //  cin >> M2;
  7073. //  cout << M2;
  7074. //  Matrix M3 = M1 + M2;
  7075. //  Matrix M4 = M1 - M2;
  7076. //  cout << M3 << endl << "M4: \n" << M4;
  7077. //  M3 += M4;
  7078. //  cout << M3;
  7079. //  if (M3 == M1)
  7080. //      cout << "\nEqual\n";
  7081. //  else
  7082. //      cout << "\nNot equal\n";
  7083. //  M3 = M1;
  7084. //  if (M3 == M1)
  7085. //      cout << "\nEqual\n";
  7086. //  else
  7087. //      cout << "\nNot equal\n";
  7088. //  cout << M3[0];
  7089. //
  7090. //  return 0;
  7091. //}
  7092.  
  7093. //#include <iostream>
  7094. //using namespace std;
  7095. //
  7096. //class Many
  7097. //{
  7098. //  int* arr;
  7099. //  int size;
  7100. //public:
  7101. //  Many();
  7102. //  Many(int size_);
  7103. //  Many(const Many& many);
  7104. // 
  7105. //  int getSize();
  7106. // 
  7107. //  friend istream& operator>>(istream& is, Many& many);
  7108. //  friend ostream& operator<<(ostream& os, const Many& many);
  7109. //
  7110. //  bool elementPresent(int num, int maxPos) const;
  7111. //  bool elementPresent(int num) const;
  7112. // 
  7113. //  Many operator+(int num) const;
  7114. //  Many& operator+=(int num);
  7115. // 
  7116. //  Many& operator=(const Many& many);
  7117. // 
  7118. //  Many operator+(const Many& many) const;
  7119. //  Many& operator+=(const Many& many);
  7120. //
  7121. //  Many operator-(int num) const;
  7122. //  Many operator-(const Many& many) const;
  7123. //
  7124. //  bool operator==(const Many& many) const;
  7125. //};
  7126. //
  7127. //Many::Many()
  7128. //{
  7129. //  arr = nullptr;
  7130. //  size = 0;
  7131. //}
  7132. //
  7133. //Many::Many(int size_)
  7134. //{
  7135. //  size = size_;
  7136. //  arr = new int[size];
  7137. //}
  7138. //
  7139. //Many::Many(const Many& many)
  7140. //{
  7141. //  size = many.size;
  7142. //  arr = new int[size];
  7143. //  for (int i = 0; i < size; ++i)
  7144. //      arr[i] = many.arr[i];
  7145. //}
  7146. //
  7147. //int Many::getSize()
  7148. //{
  7149. //  return size;
  7150. //}
  7151. //
  7152. //int getNum()
  7153. //{
  7154. //  int num;
  7155. //  while (true)
  7156. //  {
  7157. //      cin >> num;
  7158. //      cin.ignore(32767, '\n');
  7159. //      if (cin.fail())
  7160. //      {
  7161. //          cin.clear();
  7162. //          cin.ignore(32767, '\n');
  7163. //          cout << "Bad input. Try again - ";
  7164. //      }
  7165. //      else
  7166. //          return num;
  7167. //  }
  7168. //}
  7169. //
  7170. //bool Many::elementPresent(int num, int maxPos) const
  7171. //{
  7172. //  for (int i = 0; i < maxPos; ++i)
  7173. //      if (arr[i] == num)
  7174. //          return true;
  7175. //  return false;
  7176. //}
  7177. //
  7178. //bool Many::elementPresent(int num) const
  7179. //{
  7180. //  for (int i = 0; i < size; ++i)
  7181. //      if (arr[i] == num)
  7182. //          return true;
  7183. //  return false;
  7184. //}
  7185. //
  7186. //Many& Many::operator=(const Many& many)
  7187. //{
  7188. //  if (this == &many)
  7189. //      return *this;
  7190. //  delete[] arr;
  7191. //  size = many.size;
  7192. //  arr = new int[size];
  7193. //  for(int i = 0; i < size; ++i)
  7194. //      arr[i] = many.arr[i];
  7195. //  return *this;
  7196. //}
  7197. //
  7198. //Many Many::operator+(int num) const
  7199. //{
  7200. //  if (this->elementPresent(num))
  7201. //      return *this;
  7202. //  Many res(size + 1);
  7203. //  for (int i = 0; i < size; ++i)
  7204. //      res.arr[i] = arr[i];
  7205. //  res.arr[size] = num;
  7206. //  return res;
  7207. //}
  7208. //
  7209. //Many& Many::operator+=(int num)
  7210. //{
  7211. //  if (this->elementPresent(num, size))
  7212. //      return *this;
  7213. //  int* temp = new int[size + 1];
  7214. //  for (int i = 0; i < size; ++i)
  7215. //      temp[i] = arr[i];
  7216. //  temp[size] = num;
  7217. //  delete[] arr;
  7218. //  ++size;
  7219. //  for (int i = 0; i < size; ++i)
  7220. //      arr[i] = temp[i];
  7221. //  return *this;
  7222. //}
  7223. //
  7224. //Many Many::operator+(const Many& many) const
  7225. //{
  7226. //  int *temp = new int[size + many.size];
  7227. //  for (int i = 0; i < size; ++i)
  7228. //      temp[i] = arr[i];
  7229. //  int count = size;
  7230. //  for (int i = 0, j = size; i < many.size; ++i)
  7231. //      if (!elementPresent(many.arr[i]))
  7232. //      {
  7233. //          temp[j++] = many.arr[i];
  7234. //          ++count;
  7235. //      }
  7236. //  Many res(count);
  7237. //  for (int i = 0; i < count; ++i)
  7238. //      res.arr[i] = temp[i];
  7239. //  return res;
  7240. //}
  7241. //
  7242. //Many& Many::operator+=(const Many& many)
  7243. //{
  7244. //  if (this == &many)
  7245. //      return *this;
  7246. //  int* temp = new int[size + many.size];
  7247. //  for (int i = 0; i < size; ++i)
  7248. //      temp[i] = arr[i];
  7249. //  int count = size;
  7250. //  for (int i = 0, j = size; i < many.size; ++i)
  7251. //      if (!elementPresent(many.arr[i]))
  7252. //      {
  7253. //          temp[j++] = many.arr[i];
  7254. //          ++count;
  7255. //      }
  7256. //  delete[] arr;
  7257. //  size = count;
  7258. //  arr = new int[size];
  7259. //  for (int i = 0; i < size; ++i)
  7260. //      arr[i] = temp[i];
  7261. //  return *this;
  7262. //}
  7263. //
  7264. //istream& operator>>(istream& is, Many& many)
  7265. //{
  7266. //  cout << "Enter the elements of many: " << endl;
  7267. //  for (int i = 0; i < many.size; ++i)
  7268. //  {
  7269. //      cout << "Enter [" << i << "] - ";
  7270. //      int temp = getNum();
  7271. //      while (many.elementPresent(temp, i))
  7272. //      {
  7273. //          cout << "Element is already present in many. Enter another - ";
  7274. //          temp = getNum();
  7275. //      }
  7276. //      many.arr[i] = temp;
  7277. //  }
  7278. //  return is;
  7279. //}
  7280. //
  7281. //ostream& operator<<(ostream& os, const Many& many)
  7282. //{
  7283. //  os << endl << endl;
  7284. //  for (int i = 0; i < many.size; ++i)
  7285. //      os << many.arr[i] << " ";
  7286. //  os << endl << endl;
  7287. //  return os;
  7288. //}
  7289. //
  7290. //Many Many::operator-(int num) const
  7291. //{
  7292. //  if (!elementPresent(num, size))
  7293. //  {
  7294. //      Many res;
  7295. //      return res;
  7296. //  }
  7297. //  Many res(size - 1);
  7298. //  for (int i = 0, j = 0; i < size; ++i)
  7299. //      if (arr[i] != num)
  7300. //          res.arr[j++] = arr[i];
  7301. //  return res;
  7302. //}
  7303. //
  7304. //Many Many::operator-(const Many& many) const
  7305. //{
  7306. //  int* temp = new int[size];
  7307. //  int count = 0;
  7308. //  for(int i = 0; i < size; ++i)
  7309. //      if (!many.elementPresent(arr[i], many.size))
  7310. //          temp[count++] = arr[i];
  7311. //  Many res(count);
  7312. //  for (int i = 0; i < res.size; ++i)
  7313. //      res.arr[i] = temp[i];
  7314. //  return res;
  7315. //}
  7316. //
  7317. //bool Many::operator==(const Many& many) const
  7318. //{
  7319. //  if (size != many.size)
  7320. //      return false;
  7321. //  for (int i = 0; i < size; ++i)
  7322. //      if (!many.elementPresent(arr[i], size))
  7323. //          return false;
  7324. //  return true;
  7325. //}
  7326. //
  7327. //int main()
  7328. //{
  7329. //  Many M1(5), M2(5);
  7330. //  cin >> M1 >> M2;
  7331. //  cout << M1 << M2;
  7332. //  Many M3;
  7333. //
  7334. //  return 0;
  7335. //}
  7336.  
  7337. //#include <iostream>
  7338. //using namespace std;
  7339. //
  7340. //class Prism
  7341. //{
  7342. //  double volume;
  7343. //  double height;
  7344. //  int numOfLines;
  7345. //  double lineLength;
  7346. //  double squareOfMain;
  7347. //
  7348. //public:
  7349. //  double getVolume() const { return volume; };
  7350. //  void setVolume(double V) { volume = V; };
  7351. // 
  7352. //  double getHeight() const { return height; };
  7353. //  void setHeight(double H) { height = H; };
  7354. //
  7355. //  int getNumOfLines() const { return numOfLines; };
  7356. //  void setNumOfLines(int num) { numOfLines = num; };
  7357. //
  7358. //  double getLineLength() const { return lineLength; };
  7359. //  void setLineLength(double LL) { lineLength = LL; };
  7360. //
  7361. //  double getSquareOfMain() const { return squareOfMain; };
  7362. //  void setSquare(double Sq) { squareOfMain = Sq; };
  7363. //};
  7364. //
  7365. //int main()
  7366. //{
  7367. //  Prism p;
  7368. //  p.setHeight(5.5);
  7369. //  cout << p.getHeight();
  7370. //  p.setNumOfLines(2);
  7371. //  cout << p.getNumOfLines();
  7372. //  p.setSquare(23);
  7373. //  cout << p.getSquareOfMain();
  7374. //  cout << p.getVolume();
  7375. //  return 0;
  7376. //}
  7377.  
  7378. //#include <iostream>
  7379. //using namespace std;
  7380. //#define _CRT_SECURE_NO_WARNINGS
  7381. //#pragma warning(disable:4996)
  7382. //
  7383. //class String
  7384. //{
  7385. //  char** strArr;
  7386. //  int numOfStr;
  7387. //  int size;
  7388. //public:
  7389. //  String();
  7390. //  String(int size_, int numOfStr_);
  7391. //  void setString(int pos);
  7392. //  void showString(int pos) const;
  7393. //  void showString() const;
  7394. //  void addStrings(int pos1, int pos2);
  7395. //  int foundString(const char* str) const;
  7396. //};
  7397. //
  7398. //String::String()
  7399. //{
  7400. //  size = numOfStr = 0;
  7401. //  strArr = nullptr;
  7402. //}
  7403. //
  7404. //String::String(int size_, int numOfStr_)
  7405. //{
  7406. //  size = size_;
  7407. //  numOfStr = numOfStr_;
  7408. //  strArr = new char* [numOfStr];
  7409. //  for (int i = 0; i < numOfStr; ++i)
  7410. //      strArr[i] = new char[size];
  7411. //}
  7412. //
  7413. //void String::setString(int pos)
  7414. //{
  7415. //  if (pos >= numOfStr)
  7416. //      return;
  7417. //  cout << "Enter str " << pos << " - ";
  7418. //  cin.getline(strArr[pos], size, '\n');
  7419. //}
  7420. //
  7421. //void String::showString(int pos) const
  7422. //{
  7423. //  cout << endl << strArr[pos] << endl;
  7424. //}
  7425. //
  7426. //void String::showString() const
  7427. //{
  7428. //  cout << endl;
  7429. //  for(int pos = 0; pos < numOfStr; ++pos)
  7430. //      cout << strArr[pos] << endl;
  7431. //}
  7432. //
  7433. //void String::addStrings(int pos1, int pos2)
  7434. //{
  7435. //  int strlength = strlen(strArr[pos1]) + strlen(strArr[pos2]);
  7436. //  if (strlength >= size)
  7437. //      return;
  7438. //  for (int i = strlen(strArr[pos1]), j = 0; j < strlen(strArr[pos2]); ++i, ++j)
  7439. //      strArr[pos1][i] = strArr[pos2][j];
  7440. //  strArr[pos1][strlength] = '\0';
  7441. //}
  7442. //
  7443. //int String::foundString(const char* str) const
  7444. //{
  7445. //  for (int i = 0; i < numOfStr; ++i)
  7446. //      if (strncmp(strArr[i], str, size) == 0)
  7447. //          return i;
  7448. //  return -1;
  7449. //}
  7450. //
  7451. //int main()
  7452. //{
  7453. //  String str(256, 4);
  7454. //  for (int i = 0; i < 4; ++i)
  7455. //      str.setString(i);
  7456. //  for (int i = 0; i < 4; ++i)
  7457. //      str.showString(i);
  7458. //  str.showString();
  7459. //  cout << endl << str.foundString("LOX");
  7460. //  cout << endl << str.foundString("L1O2X3");
  7461. //  str.addStrings(0, 1);
  7462. //  str.showString(0);
  7463. //
  7464. //  return 0;
  7465. //}
  7466.  
  7467. //#include <iostream>
  7468. //#include <string>
  7469. //using namespace std;
  7470. //
  7471. //struct Znak
  7472. //{
  7473. //  string name;
  7474. //  string zodiac;
  7475. //  int bday[3];
  7476. //};
  7477. //
  7478. //void fillZnak(Znak book[],  int numOfZnaks)
  7479. //{
  7480. //  for (int i = 0; i < numOfZnaks; ++i)
  7481. //  {
  7482. //      cout << "Enter name: ";
  7483. //      cin >> book[i].name;
  7484. //      cout << "Enter znak: ";
  7485. //      cin >> book[i].zodiac;
  7486. //      cout << "Enter date of birth: ";
  7487. //      cin >> book[i].bday[0] >> book[i].bday[1] >> book[i].bday[2];
  7488. //  }
  7489. //}
  7490. //
  7491. //void showZnaks(Znak book[], int numOfZnaks)
  7492. //{
  7493. //  cout << endl;
  7494. //  for (int i = 0; i < numOfZnaks; ++i)
  7495. //  {
  7496. //      cout << book[i].name << endl;
  7497. //      cout << book[i].zodiac << endl;
  7498. //      cout << book[i].bday[0] << "." << book[i].bday[1] << "." << book[i].bday[2] << endl;
  7499. //      cout << endl;
  7500. //  }
  7501. //
  7502. //}
  7503. //
  7504. //void sortZnaks(Znak book[], int numOfZnaks)
  7505. //{
  7506. //  for(int i = 0; i < numOfZnaks - 1; ++i)
  7507. //      for (int j = 0; j < numOfZnaks; ++j)
  7508. //          if (book[i].bday[1] > book[j].bday[1])
  7509. //          {
  7510. //              Znak temp = book[i];
  7511. //              book[i] = book[j];
  7512. //              book[j] = temp;
  7513. //          }
  7514. //}
  7515. //
  7516. //void showZnaksWithMonth(Znak book[], int numOfZnaks, int month)
  7517. //{
  7518. //  for(int i = 0; i < numOfZnaks; ++i)
  7519. //      if (book[i].bday[1] == month)
  7520. //      {
  7521. //          cout << book[i].name << endl;
  7522. //          cout << book[i].zodiac << endl;
  7523. //          cout << book[i].bday[0] << "." << book[i].bday[1] << "." << book[i].bday[2] << endl;
  7524. //          cout << endl;
  7525. //      }
  7526. //}
  7527. //
  7528. //int main()
  7529. //{
  7530. //  const int numOfZnaks = 8;
  7531. //  Znak book[numOfZnaks];
  7532. //  fillZnak(book, numOfZnaks);
  7533. //  showZnaks(book, numOfZnaks);
  7534. //  sortZnaks(book, numOfZnaks);
  7535. //  showZnaks(book, numOfZnaks);
  7536. //  cout << "Enter the number of month - ";
  7537. //  int month;
  7538. //  cin >> month;
  7539. //  showZnaksWithMonth(book, numOfZnaks, month);
  7540. //  return 0;
  7541. //}
  7542.  
  7543. //#include <iostream>
  7544. //#include <vector>
  7545. //#include <algorithm>
  7546. //using namespace std;
  7547. //
  7548. //int main()
  7549. //{
  7550. //  int arr[6][8] =
  7551. //  {   -3,   39,   76,  -24, -62, -56,  8, - 90,
  7552. //  -83,   54,   41, -77, -10, -5, -48,   52,
  7553. //  24, -48, -82,  34, -31,  52,   68,   63,
  7554. //  -54, -97, -44,    9,   36,    0,   95, -12,
  7555. //  91, -33,   68,   17,   27,    9, - 20, -20,
  7556. //  -12,   17, -44,   41, -19,   32, -10, -5
  7557. //  };
  7558. //  vector <int> pos;
  7559. //  for (int i = 0; i < 6; ++i)
  7560. //      for (int j = 0; j < 8; ++j)
  7561. //          if (arr[i][j] >= 0)
  7562. //              pos.push_back(arr[i][j]);
  7563. //  sort(pos.begin(), pos.end());
  7564. //  for (vector<int>::const_iterator i = pos.begin(); i != pos.end(); ++i)
  7565. //      cout << *i << ' ';
  7566. //  return 0;
  7567. //}
  7568.  
  7569. //#include <iostream>
  7570. //using namespace std;
  7571. //
  7572. //int findMin(double* arr, int size)
  7573. //{
  7574. //  double min = arr[0];
  7575. //  int index = 0;
  7576. //  for(int i = 0; i < size; ++i)
  7577. //      if (arr[i] < min)
  7578. //      {
  7579. //          min = arr[i];
  7580. //          index = i;
  7581. //      }
  7582. //  return index;
  7583. //}
  7584. //
  7585. //double proiz(double* arr, int size)
  7586. //{
  7587. //  bool start = false;
  7588. //  double pro = 1.0;
  7589. //  for (int i = 0; i < size; ++i)
  7590. //  {
  7591. //      if (arr[i] < 0 && start == true)
  7592. //          break;
  7593. //      if (start)
  7594. //          pro *= arr[i];
  7595. //      if (arr[i] < 0)
  7596. //          start = true;
  7597. //  }
  7598. //  return pro;
  7599. //}
  7600. //
  7601. //void fillArr(double* arr, int size)
  7602. //{
  7603. //  for (int i = 0; i < size; ++i)
  7604. //      cin >> arr[i];
  7605. //}
  7606. //
  7607. //void preobr(double* arr, int size)
  7608. //{
  7609. //  for (int i = 0; i < size; ++i)
  7610. //      if (abs(arr[i]) < 1)
  7611. //          cout << arr[i] << " ";
  7612. //  for (int i = 0; i < size; ++i)
  7613. //      if (abs(arr[i]) >= 1)
  7614. //          cout << arr[i] << " ";
  7615. //}
  7616. //
  7617. //int main()
  7618. //{
  7619. //  cout << "Enter the size - ";
  7620. //  int size;
  7621. //  cin >> size;
  7622. //  double* arr = new double[size];
  7623. //  fillArr(arr, size);
  7624. //  cout << "Num of min = " << findMin(arr, size);
  7625. //  cout << "Proisvidenie = " << proiz(arr, size);
  7626. //  preobr(arr, size);
  7627. //  return 0;
  7628. //}
  7629.  
  7630. //#include <iostream>
  7631. //#include <fstream>
  7632. //using namespace std;
  7633. //
  7634. //void fillArr(int* arr, int size)
  7635. //{
  7636. //  for (int i = 0; i < size; ++i)
  7637. //      cin >> arr[i];
  7638. //}
  7639. //
  7640. //bool isPresent(const int* arr, int maxSize, int num)
  7641. //{
  7642. //  for (size_t i = 0; i < maxSize; i++)
  7643. //      if (arr[i] == num)
  7644. //          return true;
  7645. //  return false;
  7646. //}
  7647. //
  7648. //int arrayUnique(int* array, int size)
  7649. //{
  7650. //  int count = 0;
  7651. //  int* temp = new int[size];
  7652. //  for (int i = 0; i < size; ++i)
  7653. //      if (!isPresent(array, i, array[i]))
  7654. //          temp[count++] = array[i];
  7655. //  for (int i = 0; i < count; ++i)
  7656. //      array[i] = temp[i];
  7657. //  return count;
  7658. //}
  7659. //
  7660. //int main()
  7661. //{
  7662. //  cout << "Enter the size - ";
  7663. //  int size;
  7664. //  cin >> size;
  7665. //  int* arr = new int[size];
  7666. //  cout << "Now fill the arr: ";
  7667. //  fillArr(arr, size);
  7668. //  int length = arrayUnique(arr, size);
  7669. //  for (size_t i = 0; i < length; i++)
  7670. //  {
  7671. //      cout << arr[i] << " ";
  7672. //  }
  7673. //  return 0;
  7674. //}
  7675.  
  7676. //#include <iostream>
  7677. //#include <ctime>
  7678. //#include <cstdlib>
  7679. //using namespace std;
  7680. //
  7681. //int** createArr(int rows, int cols)
  7682. //{
  7683. //  int** arr = new int* [rows];
  7684. //  for (int j = 0; j < cols; ++j)
  7685. //      arr[j] = new int[cols];
  7686. //  return arr;
  7687. //}
  7688. //
  7689. //void fillArr(int** arr, int rows, int cols)
  7690. //{
  7691. //  srand(static_cast<unsigned>(time(0)));
  7692. //  for (int i = 0; i < rows; ++i)
  7693. //      for (int j = 0; j < cols; ++j)
  7694. //          arr[i][j] = -100 + rand() % 200;
  7695. //}
  7696. //
  7697. //void showArr(int** arr, int rows, int cols)
  7698. //{
  7699. //  cout << endl;
  7700. //  for (int i = 0; i < rows; ++i)
  7701. //  {
  7702. //      for (int j = 0; j < cols; ++j)
  7703. //      {
  7704. //          cout.width(5);
  7705. //          cout << arr[i][j] << " ";
  7706. //      }
  7707. //      cout << endl;
  7708. //  }
  7709. //  cout << endl;
  7710. //}
  7711. //
  7712. //int* fillCharact(int** arr, int rows, int cols)
  7713. //{
  7714. //  int* crah = new int[cols] {0};
  7715. //  for (int i = 0; i < cols; ++i)
  7716. //  {
  7717. //      int sum = 0;
  7718. //      for (int j = 0; j < rows; ++j)
  7719. //      {
  7720. //          if (arr[j][i] < 0 && arr[j][i] % 2)
  7721. //              sum += abs(arr[j][i]);
  7722. //      }
  7723. //      crah[i] = sum;
  7724. //  }
  7725. //  return crah;
  7726. //}
  7727. //
  7728. //void swapCols(int** arr, int rows, int cols, int* crah)
  7729. //{
  7730. //  for(int i = 0; i < cols - 1; ++i)
  7731. //      for (int j = i; j < cols; ++j)
  7732. //      {
  7733. //          if (crah[i] > crah[j])
  7734. //          {
  7735. //              int temp = crah[i];
  7736. //              crah[i] = crah[j];
  7737. //              crah[j] = temp;
  7738. //              for (int k = 0; k < rows; ++k)
  7739. //              {
  7740. //                  int temp = arr[k][i];
  7741. //                  arr[k][i] = arr[k][j];
  7742. //                  arr[k][j] = temp;
  7743. //              }
  7744. //          }
  7745. //      }
  7746. //}
  7747. //
  7748. //void showChar(int* arr, int cols)
  7749. //{
  7750. //  for (int j = 0; j < cols; ++j)
  7751. //  {
  7752. //      cout.width(5);
  7753. //      cout << arr[j] << " ";
  7754. //  }
  7755. //  cout << endl;
  7756. //}
  7757. //
  7758. //int main()
  7759. //{
  7760. //  cout << "Enter the num of rows - ";
  7761. //  int rows;
  7762. //  cin >> rows;
  7763. //  cout << "Enter the num of cols - ";
  7764. //  int cols;
  7765. //  cin >> cols;
  7766. //  int** arr = createArr(rows, cols);
  7767. //  fillArr(arr, rows, cols);
  7768. //  showArr(arr, rows, cols);
  7769. //  int* charact = fillCharact(arr, rows, cols);
  7770. //  showChar(charact, cols);
  7771. //  swapCols(arr, rows, cols, charact);
  7772. //  showArr(arr, rows, cols);
  7773. //  return 0;
  7774. //}
  7775.  
  7776. //#include <iostream>
  7777. //
  7778. //int getInt()
  7779. //{
  7780. //  using std::cin;
  7781. //  int num;
  7782. //  while (true)
  7783. //  {
  7784. //      cin >> num;
  7785. //      cin.ignore(32767, '\n');
  7786. //      if (cin.fail())
  7787. //      {
  7788. //          cin.clear();
  7789. //          cin.ignore(32767, '\n');
  7790. //          std::cout << "Bad input. Try again. - ";
  7791. //      }
  7792. //      else
  7793. //          return num;
  7794. //  }
  7795. //}
  7796. //
  7797. //int getDrib()
  7798. //{
  7799. //  using std::cin;
  7800. //  int num;
  7801. //  while (true)
  7802. //  {
  7803. //      cin >> num;
  7804. //      cin.ignore(32767, '\n');
  7805. //      if (cin.fail())
  7806. //      {
  7807. //          cin.clear();
  7808. //          cin.ignore(32767, '\n');
  7809. //          std::cout << "Bad input. Try again. - ";
  7810. //      }
  7811. //      else if (num <= 0)
  7812. //          std::cout << "Bad input. Only > 0.  - ";
  7813. //      else
  7814. //          return num;
  7815. //  }
  7816. //}
  7817. //
  7818. //class Fraction
  7819. //{
  7820. //  int integer;
  7821. //  int numerator;
  7822. //  int denominator;
  7823. //
  7824. //public:
  7825. //
  7826. //  static int numOfFractions;
  7827. //
  7828. //  Fraction();
  7829. //  Fraction(int numerator_, int denominator_, int integer_ = 0);
  7830. //  Fraction(const Fraction& frac);
  7831. //  ~Fraction();
  7832. //
  7833. //  static int getNumOfFractions();
  7834. //
  7835. //  Fraction& operator=(const Fraction& frac);
  7836. //
  7837. //  Fraction operator+(const Fraction& frac) const;
  7838. //  Fraction& operator+=(const Fraction& frac);
  7839. //
  7840. //  Fraction operator-(const Fraction& frac) const;
  7841. //  Fraction& operator-=(const Fraction& frac);
  7842. //
  7843. //  Fraction operator*(const Fraction& frac) const;
  7844. //  Fraction& operator*=(const Fraction& frac);
  7845. //
  7846. //  Fraction operator/(const Fraction& frac) const;
  7847. //  Fraction& operator/=(const Fraction& frac);
  7848. //
  7849. //  bool operator==(const Fraction& frac) const;
  7850. //  bool operator>(const Fraction& frac) const;
  7851. //  bool operator<(const Fraction& frac) const;
  7852. //  bool operator>=(const Fraction& frac) const;
  7853. //  bool operator<=(const Fraction& frac) const;
  7854. //
  7855. //  friend std::istream& operator>>(std::istream& is, Fraction& frac);
  7856. //  friend std::ostream& operator<<(std::ostream& os, const Fraction& frac);
  7857. //};
  7858. //
  7859. //int Fraction::numOfFractions = 0;
  7860. //int Fraction::getNumOfFractions() { return numOfFractions; }
  7861. //
  7862. //Fraction::Fraction() : integer(0), numerator(1), denominator(1) {++numOfFractions;}
  7863. //Fraction::Fraction(int numerator_, int denominator_, int integer_) : integer(integer_), denominator(denominator_), numerator(numerator_) {++numOfFractions;}
  7864. //Fraction::Fraction(const Fraction& frac) : integer(frac.integer), numerator(frac.numerator), denominator(frac.denominator) { ++numOfFractions; }
  7865. //Fraction::~Fraction() {--numOfFractions;}
  7866. //
  7867. //Fraction& Fraction::operator=(const Fraction& frac)
  7868. //{
  7869. //  if (this == &frac)
  7870. //      return *this;
  7871. //  integer = frac.integer;
  7872. //  numerator = frac.numerator;
  7873. //  denominator = frac.denominator;
  7874. //  ++numOfFractions;
  7875. //  return (*this);
  7876. //}
  7877. //
  7878. //Fraction Fraction::operator+(const Fraction& frac) const
  7879. //{
  7880. //  int integ, den, nom;
  7881. //  if (denominator != frac.denominator)
  7882. //  {
  7883. //      den = denominator * frac.denominator;
  7884. //      nom = ((denominator * integer + numerator) * frac.denominator + (frac.denominator * frac.integer + frac.numerator) * denominator);
  7885. //      integ = nom / (denominator * frac.denominator);
  7886. //      if (nom < 0)
  7887. //          nom = -nom;
  7888. //      nom %= (denominator * frac.denominator);
  7889. //  }
  7890. //  else
  7891. //  {
  7892. //      den = denominator;
  7893. //      nom = (denominator * integer + numerator) + (frac.denominator * frac.integer + frac.numerator);
  7894. //      integ = nom / den;
  7895. //      if (nom < 0)
  7896. //          nom = -nom;
  7897. //      nom %= den;
  7898. //  }
  7899. //  Fraction res(nom, den, integ);
  7900. //  return res;
  7901. //}
  7902. //Fraction& Fraction::operator+=(const Fraction& frac)
  7903. //{
  7904. //  int integ, den, nom;
  7905. //  if (denominator != frac.denominator)
  7906. //  {
  7907. //      den = denominator * frac.denominator;
  7908. //      nom = ((denominator * integer + numerator) * frac.denominator + (frac.denominator * frac.integer + frac.numerator) * denominator);
  7909. //      integ = nom / (denominator * frac.denominator);
  7910. //      if (nom < 0)
  7911. //          nom = -nom;
  7912. //      nom %= (denominator * frac.denominator);
  7913. //  }
  7914. //  else
  7915. //  {
  7916. //      den = denominator;
  7917. //      nom = (denominator * integer + numerator) + (frac.denominator * frac.integer + frac.numerator);
  7918. //      integ = nom / den;
  7919. //      if (nom < 0)
  7920. //          nom = -nom;
  7921. //      nom %= den;
  7922. //  }
  7923. //  integer = integ;
  7924. //  denominator = den;
  7925. //  numerator = nom;
  7926. //  return *this;
  7927. //}
  7928. //
  7929. //Fraction Fraction::operator-(const Fraction& frac) const
  7930. //{
  7931. //  int integ, den, nom;
  7932. //  if (denominator != frac.denominator)
  7933. //  {
  7934. //      den = denominator * frac.denominator;
  7935. //      nom = ((denominator * integer + numerator) * frac.denominator - (frac.denominator * frac.integer + frac.numerator) * denominator);
  7936. //      integ = nom / (denominator * frac.denominator);
  7937. //      if (nom < 0)
  7938. //          nom = -nom;
  7939. //      nom %= (denominator * frac.denominator);
  7940. //  }
  7941. //  else
  7942. //  {
  7943. //      den = denominator;
  7944. //      nom = (denominator * integer + numerator) - (frac.denominator * frac.integer + frac.numerator);
  7945. //      integ = nom / den;
  7946. //      if (nom < 0)
  7947. //          nom = -nom;
  7948. //      nom %= den;
  7949. //  }
  7950. //  Fraction res(nom, den, integ);
  7951. //  return res;
  7952. //}
  7953. //Fraction& Fraction::operator-=(const Fraction& frac)
  7954. //{
  7955. //  int integ, den, nom;
  7956. //  if (denominator != frac.denominator)
  7957. //  {
  7958. //      den = denominator * frac.denominator;
  7959. //      nom = ((denominator * integer + numerator) * frac.denominator - (frac.denominator * frac.integer + frac.numerator) * denominator);
  7960. //      integ = nom / (denominator * frac.denominator);
  7961. //      if (nom < 0)
  7962. //          nom = -nom;
  7963. //      nom %= (denominator * frac.denominator);
  7964. //  }
  7965. //  else
  7966. //  {
  7967. //      den = denominator;
  7968. //      nom = (denominator * integer + numerator) - (frac.denominator * frac.integer + frac.numerator);
  7969. //      integ = nom / den;
  7970. //      if (nom < 0)
  7971. //          nom = -nom;
  7972. //      nom %= den;
  7973. //  }
  7974. //  integer = integ;
  7975. //  numerator = nom;
  7976. //  denominator = den;
  7977. //  return *this;
  7978. //}
  7979. //
  7980. //Fraction Fraction::operator*(const Fraction& frac) const
  7981. //{
  7982. //  int integ, den, nom;
  7983. //  nom = (denominator * integer + numerator) * (frac.denominator * frac.integer + frac.numerator);
  7984. //  den = denominator * frac.denominator;
  7985. //  integ = nom / den;
  7986. //  if (nom < 0)
  7987. //      nom = -nom;
  7988. //  nom %= den;
  7989. //  Fraction res(nom, den, integ);
  7990. //  return res;
  7991. //}
  7992. //Fraction& Fraction::operator*=(const Fraction& frac)
  7993. //{
  7994. //  int integ, den, nom;
  7995. //  nom = (denominator * integer + numerator) * (frac.denominator * frac.integer + frac.numerator);
  7996. //  den = denominator * frac.denominator;
  7997. //  integ = nom / den;
  7998. //  if (nom < 0)
  7999. //      nom = -nom;
  8000. //  nom %= den;
  8001. //  numerator = nom;
  8002. //  denominator = den;
  8003. //  integer = integ;
  8004. //  return *this;
  8005. //}
  8006. //
  8007. //Fraction Fraction::operator/(const Fraction& frac) const
  8008. //{
  8009. //  int integ, den, nom;
  8010. //  nom = (denominator * integer + numerator) * frac.denominator;
  8011. //  den = denominator * (frac.denominator * frac.integer + frac.numerator);
  8012. //  integ = nom / den;
  8013. //  if (nom < 0)
  8014. //      nom = -nom;
  8015. //  nom %= den;
  8016. //  Fraction res(nom, den, integ);
  8017. //  return res;
  8018. //}
  8019. //Fraction& Fraction::operator/=(const Fraction& frac)
  8020. //{
  8021. //  int integ, den, nom;
  8022. //  nom = (denominator * integer + numerator) * frac.denominator;
  8023. //  den = denominator * (frac.denominator * frac.integer + frac.numerator);
  8024. //  integ = nom / den;
  8025. //  if (nom < 0)
  8026. //      nom = -nom;
  8027. //  nom %= den;
  8028. //  denominator = den;
  8029. //  numerator = nom;
  8030. //  integer = integ;
  8031. //  return *this;
  8032. //}
  8033. //
  8034. //bool Fraction::operator==(const Fraction& frac) const
  8035. //{
  8036. //  double size1 = (static_cast<double>(denominator) * static_cast<double>(integer) + static_cast<double>(numerator)) / static_cast<double>(denominator);
  8037. //  double size2 = (static_cast<double>(frac.denominator) * static_cast<double>(frac.integer) + static_cast<double>(frac.numerator)) / static_cast<double>(frac.denominator);
  8038. //  return size1 == size2 ? true : false;
  8039. //}
  8040. //bool Fraction::operator>(const Fraction& frac) const
  8041. //{
  8042. //  double size1 = (static_cast<double>(denominator)* static_cast<double>(integer) + static_cast<double>(numerator)) / static_cast<double>(denominator);
  8043. //  double size2 = (static_cast<double>(frac.denominator)* static_cast<double>(frac.integer) + static_cast<double>(frac.numerator)) / static_cast<double>(frac.denominator);
  8044. //  return size1 > size2 ? true : false;
  8045. //}
  8046. //bool Fraction::operator<(const Fraction& frac) const
  8047. //{
  8048. //  return frac > (*this);
  8049. //}
  8050. //bool Fraction::operator>=(const Fraction& frac) const
  8051. //{
  8052. //  return ((*this) > frac || (*this) == frac) ? true : false;
  8053. //}
  8054. //bool Fraction::operator<=(const Fraction& frac) const
  8055. //{
  8056. //  return frac >= (*this);
  8057. //}
  8058. //
  8059. //std::istream& operator>>(std::istream& is, Fraction& frac)
  8060. //{
  8061. //  std::cout << "Enter the values of Fraction : \n";
  8062. //  std::cout << "Enter integer - ";
  8063. //  frac.integer = getInt();
  8064. //  std::cout << "Enter numerator - ";
  8065. //  frac.numerator = getDrib();
  8066. //  std::cout << "Enter denominator - ";
  8067. //  frac.denominator = getDrib();
  8068. //  return is;
  8069. //}
  8070. //std::ostream& operator<<(std::ostream& os, const Fraction& frac)
  8071. //{
  8072. //  os << "\nFraction - " << frac.integer << ", " << frac.numerator << "/" << frac.denominator << std::endl;
  8073. //  return os;
  8074. //}
  8075. //
  8076. //int main()
  8077. //{
  8078. //  using std::cout;
  8079. //  using std::cin;
  8080. //  using std::endl;
  8081. //
  8082. //
  8083. //  return 0;
  8084. //}
  8085.  
  8086. //#include <iostream>
  8087. //#include <climits>
  8088. //
  8089. //int  getCash()
  8090. //{
  8091. //  using std::cin;
  8092. //  int cash;
  8093. //  while (true)
  8094. //  {
  8095. //      cin >> cash;
  8096. //      cin.ignore(32767, '\n');
  8097. //      if (cin.fail())
  8098. //      {
  8099. //          cin.clear();
  8100. //          cin.ignore(32767, '\n');
  8101. //          std::cout << "Bad input. Again - ";
  8102. //      }
  8103. //      else if (cash < 0)
  8104. //          std::cout << "Bad input. Only > 0 && < " << LONG_MAX << ". ";
  8105. //      else
  8106. //          return cash;
  8107. //  }
  8108. //}
  8109. //int getPenny()
  8110. //{
  8111. //  using std::cin;
  8112. //  int penny;
  8113. //  while (true)
  8114. //  {
  8115. //      cin >> penny;
  8116. //      cin.ignore(32767, '\n');
  8117. //      if (cin.fail())
  8118. //      {
  8119. //          cin.clear();
  8120. //          cin.ignore(32767, '\n');
  8121. //          std::cout << "Bad input. Again - ";
  8122. //      }
  8123. //      else if (penny < 0 || penny >= 100)
  8124. //          std::cout << "Bad input. Only > 0 && < 100. ";
  8125. //      else
  8126. //          return penny;
  8127. //  }
  8128. //}
  8129. //
  8130. //const int cashToPenny = 100;
  8131. //
  8132. //class Money
  8133. //{
  8134. //  int cash;
  8135. //  int penny;
  8136. //public:
  8137. //
  8138. //  static int howManyMoney;
  8139. //  static int getHowManyMoney();
  8140. //
  8141. //  Money();
  8142. //  Money(int cash_, int penny_ = 0);
  8143. //  Money(const Money& mon);
  8144. //  ~Money();
  8145. // 
  8146. //  Money& operator= (const Money& mon);
  8147. //  Money  operator+ (const Money& mon) const;
  8148. //  Money& operator+=(const Money& mon);
  8149. //  Money  operator- (const Money& mon) const;
  8150. //  Money& operator-=(const Money& mon);
  8151. //  Money  operator* (const Money& mon) const;
  8152. //  Money& operator*=(const Money& mon);
  8153. //  Money  operator/ (const Money& mon) const;
  8154. //  Money& operator/=(const Money& mon);
  8155. //  Money  operator* (const double mon) const;
  8156. //  Money& operator*=(const double mon);
  8157. //  Money  operator/ (const double mon) const;
  8158. //  Money& operator/=(const double mon);
  8159. // 
  8160. //  bool operator==(const Money& mon) const;
  8161. //  bool operator!=(const Money& mon) const;
  8162. //  bool operator> (const Money& mon) const;
  8163. //  bool operator< (const Money& mon) const;
  8164. //  bool operator>=(const Money& mon) const;
  8165. //  bool operator<=(const Money& mon) const;
  8166. // 
  8167. //  friend std::istream& operator>>(std::istream& is,       Money& mon);
  8168. //  friend std::ostream& operator<<(std::ostream& os, const Money& mon);
  8169. //};
  8170. //
  8171. //int Money::howManyMoney = 0;
  8172. //int Money::getHowManyMoney() { return howManyMoney; }
  8173. //
  8174. //Money::Money() : cash(0), penny(0)
  8175. //{ ++howManyMoney; }
  8176. //Money::Money(int cash_, int penny_) : cash(cash_), penny(penny_)
  8177. //{ ++howManyMoney; }
  8178. //Money::~Money()
  8179. //{ --howManyMoney; }
  8180. //Money::Money(const Money& mon)
  8181. //{
  8182. //  cash = mon.cash;
  8183. //  penny = mon.penny;
  8184. //  ++howManyMoney;
  8185. //}
  8186. //
  8187. //Money& Money::operator= (const Money& mon)
  8188. //{
  8189. //  if (this == &mon)
  8190. //      return (*this);
  8191. //  cash = mon.cash;
  8192. //  penny = mon.penny;
  8193. //  ++howManyMoney;
  8194. //  return (*this);
  8195. //}
  8196. //Money  Money::operator+ (const Money& mon) const
  8197. //{
  8198. //  long long sum = (cash * cashToPenny + penny) + (mon.cash * cashToPenny + mon.penny);
  8199. //  Money res(sum / cashToPenny, sum % cashToPenny);
  8200. //  return res;
  8201. //}
  8202. //Money& Money::operator+=(const Money& mon)            
  8203. //{
  8204. //  long long sum = (cash * cashToPenny + penny) + (mon.cash * cashToPenny + mon.penny);
  8205. //  cash = sum / cashToPenny;
  8206. //  penny = sum % cashToPenny;
  8207. //  return (*this);
  8208. //}
  8209. //Money  Money::operator- (const Money& mon) const
  8210. //{
  8211. //  long long sum = (cash * cashToPenny + penny) - (mon.cash * cashToPenny + mon.penny);
  8212. //  long cas = sum / cashToPenny, pen = sum % cashToPenny;
  8213. //  if (pen < 0)
  8214. //      pen = -pen;
  8215. //  Money res(cas, pen);
  8216. //  return res;
  8217. //}
  8218. //Money& Money::operator-=(const Money& mon)      
  8219. //{
  8220. //  long long sum = (cash * cashToPenny + penny) - (mon.cash * cashToPenny + mon.penny);
  8221. //  long cas = sum / cashToPenny, pen = sum % cashToPenny;
  8222. //  if (pen < 0)
  8223. //      pen = -pen;
  8224. //  cash = cas;
  8225. //  penny = pen;
  8226. //  return (*this);
  8227. //}
  8228. //Money  Money::operator* (const Money& mon) const
  8229. //{
  8230. //  long long sum = ((cash * cashToPenny + penny) * (mon.cash * cashToPenny + mon.penny)) / cashToPenny;
  8231. //  long cas = sum / cashToPenny, pen = sum % cashToPenny;
  8232. //  if (pen < 0)
  8233. //      pen = -pen;
  8234. //  Money res(cas, pen);
  8235. //  return res;
  8236. //}
  8237. //Money& Money::operator*=(const Money& mon)
  8238. //{
  8239. //  long long sum = ((cash * cashToPenny + penny) * (mon.cash * cashToPenny + mon.penny)) / cashToPenny;
  8240. //  long cas = sum / cashToPenny, pen = sum % cashToPenny;
  8241. //  if (pen < 0)
  8242. //      pen = -pen;
  8243. //  cash = cas;
  8244. //  penny = pen;
  8245. //  return (*this);
  8246. //}
  8247. //Money  Money::operator/ (const Money& mon) const
  8248. //{
  8249. //  double sum1 = static_cast<double>((cash * cashToPenny + penny)) / static_cast<double>((mon.cash * cashToPenny + mon.penny));
  8250. //  long long sum = sum1 * cashToPenny;
  8251. //  long cas = sum / cashToPenny, pen = sum % cashToPenny;
  8252. //  if (pen < 0)
  8253. //      pen = -pen;
  8254. //  Money res(cas, pen);
  8255. //  return res;
  8256. //}
  8257. //Money& Money::operator/=(const Money& mon)
  8258. //{
  8259. //  double sum1 = static_cast<double>((cash * cashToPenny + penny)) / static_cast<double>((mon.cash * cashToPenny + mon.penny));
  8260. //  long long sum = sum1 * cashToPenny;
  8261. //  long cas = sum / cashToPenny, pen = sum % cashToPenny;
  8262. //  if (pen < 0)
  8263. //      pen = -pen;
  8264. //  cash = cas;
  8265. //  penny = pen;
  8266. //  return (*this);
  8267. //}
  8268. //Money  Money::operator* (const double mon) const
  8269. //{
  8270. //  long long sum = ((cash * cashToPenny + penny) * (mon * cashToPenny)) / cashToPenny;
  8271. //  long cas = sum / cashToPenny, pen = sum % cashToPenny;
  8272. //  if (pen < 0)
  8273. //      pen = -pen;
  8274. //  Money res(cas, pen);
  8275. //  return res;
  8276. //}
  8277. //Money& Money::operator*=(const double mon)
  8278. //{
  8279. //  long long sum = ((cash * cashToPenny + penny) * (mon * cashToPenny)) / cashToPenny;
  8280. //  long cas = sum / cashToPenny, pen = sum % cashToPenny;
  8281. //  if (pen < 0)
  8282. //      pen = -pen;
  8283. //  cash = cas;
  8284. //  penny = pen;
  8285. //  return (*this);
  8286. //}
  8287. //Money  Money::operator/ (const double mon) const
  8288. //{
  8289. //  double sum1 = static_cast<double>((cash * cashToPenny + penny)) / static_cast<double>(mon * cashToPenny);
  8290. //  long long sum = sum1 * cashToPenny;
  8291. //  long cas = sum / cashToPenny, pen = sum % cashToPenny;
  8292. //  if (pen < 0)
  8293. //      pen = -pen;
  8294. //  Money res(cas, pen);
  8295. //  return res;
  8296. //}
  8297. //Money& Money::operator/=(const double mon)
  8298. //{
  8299. //  double sum1 = static_cast<double>((cash * cashToPenny + penny)) / static_cast<double>(mon * cashToPenny);
  8300. //  long long sum = sum1 * cashToPenny;
  8301. //  long cas = sum / cashToPenny, pen = sum % cashToPenny;
  8302. //  if (pen < 0)
  8303. //      pen = -pen;
  8304. //  cash = cas;
  8305. //  penny = pen;
  8306. //  return (*this);
  8307. //}
  8308. //
  8309. //
  8310. //bool Money::operator==(const Money& mon) const
  8311. //{
  8312. //  return ((cash * cashToPenny + penny) == (mon.cash * cashToPenny + mon.penny)) ? true : false;
  8313. //}
  8314. //bool Money::operator!=(const Money& mon) const
  8315. //{
  8316. //  return !((*this) == mon);
  8317. //}
  8318. //bool Money::operator> (const Money& mon) const
  8319. //{
  8320. //  return ((cash * cashToPenny + penny) > (mon.cash * cashToPenny + mon.penny)) ? true : false;
  8321. //}
  8322. //bool Money::operator< (const Money& mon) const
  8323. //{
  8324. //  return mon > (*this);
  8325. //}
  8326. //bool Money::operator>=(const Money& mon) const
  8327. //{
  8328. //  return ((*this) > mon || (*this) == mon) ? true : false;
  8329. //}
  8330. //bool Money::operator<=(const Money& mon) const
  8331. //{
  8332. //  return mon >= (*this);
  8333. //}
  8334. //
  8335. //std::istream& operator>>(std::istream& is, Money& mon)
  8336. //{
  8337. //  std::cout << "\nEnter the amount of cash - ";
  8338. //  mon.cash = getCash();
  8339. //  std::cout << "Enter the amount of pennys - ";
  8340. //  mon.penny = getPenny();
  8341. //  return is;
  8342. //}
  8343. //std::ostream& operator<<(std::ostream& os, const Money& mon)
  8344. //{
  8345. //  if(mon.penny == 0)
  8346. //      os << "\nYour money - " << mon.cash << ",00" << "\n";
  8347. //  else
  8348. //      os << "\nYour money - " << mon.cash << "," << mon.penny << "\n";
  8349. //  return os;
  8350. //}
  8351. //
  8352. //int main()
  8353. //{
  8354. //  using namespace std;
  8355. //  Money M1(8, 49);
  8356. //  Money M2(16 , 80);
  8357. //  cout << M1 / M2;
  8358. //  cout << M2 / M1;
  8359. //  cout << M1 / 2;
  8360. //  cout << M1 / 3;
  8361. //  cout << M1 / 0.5;
  8362. //  return 0;
  8363. //}
  8364.  
  8365. #include <iostream>
  8366. #include <cmath>
  8367.  
  8368. int getPoint()
  8369. {
  8370.     using std::cin;
  8371.     int num;
  8372.     while (true)
  8373.     {
  8374.         cin >> num;
  8375.         cin.ignore(32767, '\n');
  8376.         if (cin.fail())
  8377.         {
  8378.             cin.clear();
  8379.             cin.ignore(32767, '\n');
  8380.             std::cout << "Bad input. Try again - ";
  8381.         }
  8382.         else
  8383.             return num;
  8384.     }
  8385. }
  8386.  
  8387. const int numOfPoints = 4;
  8388. struct Point
  8389. {
  8390.     int x;
  8391.     int y;
  8392. };
  8393.  
  8394. class Trapeze
  8395. {
  8396.     Point Points[numOfPoints];
  8397.     static int numOfTrapezes;
  8398. public:
  8399.     Trapeze();
  8400.     Trapeze(Point P[numOfPoints]);
  8401.     Trapeze(const Trapeze& trap);
  8402.     ~Trapeze();
  8403.  
  8404.     double* calcLines();
  8405.     void showLines();
  8406.     bool isRight();
  8407.     double perimeter();
  8408.     double square();
  8409.  
  8410.     Trapeze& operator=(const Trapeze& trap);
  8411.  
  8412.     friend std::istream& operator>>(std::istream& is, Trapeze& trap);
  8413.     friend std::ostream& operator<<(std::ostream& os, const Trapeze& trap);
  8414. };
  8415.  
  8416. int Trapeze::numOfTrapezes = 0;
  8417.  
  8418. Trapeze::Trapeze()
  8419. {
  8420.     for (auto& x : Points)
  8421.         x.x = x.y = 0;
  8422.     ++numOfTrapezes;
  8423. }
  8424. Trapeze::Trapeze(Point P[numOfPoints])
  8425. {
  8426.     for (size_t i = 0; i < numOfPoints; ++i)
  8427.         Points[i] = P[i];
  8428.     ++numOfTrapezes;
  8429. }
  8430. Trapeze::Trapeze(const Trapeze& trap)
  8431. {
  8432.     for (size_t i = 0; i < numOfPoints; ++i)
  8433.         Points[i] = trap.Points[i];
  8434.     ++numOfTrapezes;
  8435. }
  8436. Trapeze::~Trapeze()
  8437. {
  8438.     --numOfTrapezes;
  8439. }
  8440.  
  8441. double* Trapeze::calcLines()
  8442. {
  8443.     double* arr = new double[numOfPoints];
  8444.     for (int i = 0; i < numOfPoints - 1; ++i)
  8445.         arr[i] = sqrt((Points[i + 1].x - Points[i].x) * (Points[i + 1].x - Points[i].x) + (Points[i + 1].y - Points[i].y) * (Points[i + 1].y - Points[i].y));
  8446.     arr[numOfPoints - 1] = sqrt((Points[numOfPoints - 1].x - Points[0].x) * (Points[numOfPoints - 1].x - Points[0].x)
  8447.         + (Points[numOfPoints - 1].y - Points[0].y) * (Points[numOfPoints - 1].y - Points[0].y));
  8448.     return arr;
  8449. }
  8450. void Trapeze::showLines()
  8451. {
  8452.     double* arr = calcLines();
  8453.     std::cout << "\nLines - ";
  8454.     for (int i = 0; i < numOfPoints; ++i)
  8455.         std::cout << arr[i] << " ";
  8456.     delete[] arr;
  8457. }
  8458. bool Trapeze::isRight()
  8459. {
  8460.     bool right = false;
  8461.     double* arr = calcLines();
  8462.     if (arr[0] == arr[2] || arr[1] == arr[3])
  8463.         right = true;
  8464.     delete[]arr;
  8465.     return right;
  8466. }
  8467. double Trapeze::perimeter()
  8468. {
  8469.     double* arr = calcLines();
  8470.     double P = 0.0;
  8471.     for (int i = 0; i < numOfPoints; ++i)
  8472.         P += arr[i];
  8473.     return P;
  8474. }
  8475. double Trapeze::square()
  8476. {
  8477.     double* arr = calcLines();
  8478.     double square = 0.0;
  8479.     if (isRight())
  8480.     {
  8481.         double p = perimeter() / 2.0;
  8482.         if (arr[0] == arr[2])
  8483.             square = sqrt((p - arr[1]) * (p - arr[3]) * (p - arr[0]) * (p - arr[0]));
  8484.         else if (arr[1] == arr[3])
  8485.             square = sqrt((p - arr[0]) * (p - arr[2]) * (p - arr[1]) * (p - arr[1]));
  8486.     }
  8487.     else
  8488.         square = 0.0;
  8489.     delete[] arr;
  8490.     return square;
  8491. }
  8492.  
  8493. Trapeze& Trapeze::operator=(const Trapeze& trap)
  8494. {
  8495.     for (size_t i = 0; i < numOfPoints; ++i)
  8496.         Points[i] = trap.Points[i];
  8497.     ++numOfTrapezes;
  8498.     return (*this);
  8499. }
  8500.  
  8501. std::istream& operator>>(std::istream& is, Trapeze& trap)
  8502. {
  8503.     std::cout << "Enter the points of trapeze - \n";
  8504.     for (int i = 0; i < numOfPoints; ++i)
  8505.     {
  8506.         std::cout << "Enter x" << i << " - ";
  8507.         trap.Points[i].x = getPoint();
  8508.         std::cout << "Entet y" << i << " - ";
  8509.         trap.Points[i].y = getPoint();
  8510.     }
  8511.     return is;
  8512. }
  8513. std::ostream& operator<<(std::ostream& os, const Trapeze& trap)
  8514. {
  8515.     os << "\n Your trapeze: ";
  8516.     for (int i = 0; i < numOfPoints; ++i)
  8517.         os << "(" << trap.Points[i].x << "," << trap.Points[i].y << "); ";
  8518.     return os;
  8519. }
  8520.  
  8521. int main()
  8522. {
  8523.     using namespace std;
  8524.     Trapeze Trap[numOfPoints];
  8525.     for (int i = 0; i < numOfPoints; ++i)
  8526.         cin >> Trap[i];
  8527.     for (int i = 0; i < numOfPoints; ++i)
  8528.         cout << Trap[i];
  8529.     for (int i = 0; i < numOfPoints; ++i)
  8530.         Trap[i].showLines();
  8531.     for (int i = 0; i < numOfPoints; ++i)
  8532.         cout << Trap[i].isRight() << endl;
  8533.     for (int i = 0; i < numOfPoints; ++i)
  8534.         cout << Trap[i].perimeter() << endl;
  8535.     for (int i = 0; i < numOfPoints; ++i)
  8536.         cout << Trap[i].square() << endl;
  8537.    
  8538.     return 0;
  8539. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement