Advertisement
Loloverr

rehcfx(ljgbkbnm)

Jun 23rd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.46 KB | None | 0 0
  1. // ConsoleApplication18.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <string>
  6. #include <vector>
  7. #include <ctime>
  8. #include <iostream>
  9.  
  10. using namespace std;
  11. string RandomName()
  12. {
  13. switch (rand() % 15)
  14. {
  15. case 0: {
  16. return "John";
  17. }
  18. case 1: {return "Josh";
  19.  
  20. case 2: {return "Bob";
  21.  
  22. }
  23. case 3: {return "Tony";
  24.  
  25. }
  26. case 4: {return "David";
  27.  
  28. }
  29. case 5: {return "Shawn";
  30.  
  31. }
  32. case 6: {return "Paul";
  33.  
  34. }
  35. case 7: {return "Toby";
  36.  
  37. }
  38. case 8: { return"Bill";
  39.  
  40. }
  41. case 9: { return"Nail";
  42.  
  43. }
  44. case 10: {return "Bill";
  45.  
  46. }
  47. case 11: {return "Spenser";
  48.  
  49. }
  50. case 12: {return "Homer";
  51.  
  52. }
  53. case 13: { return"Gabriel";
  54.  
  55. }
  56. case 14: {return "Dennis";
  57.  
  58. }
  59. }
  60. }
  61. }
  62. string RandomSurname()
  63. {
  64. switch (rand() % 15)
  65. {
  66. case 0: {
  67. return "Smith";
  68. }
  69. case 1: {return "White";
  70. }
  71. case 2: {return "Brown";
  72. }
  73. case 3: {return "Muller";
  74. }
  75. case 4: {return "Garcia"; }
  76. case 5: {return "Nowak";
  77. }
  78. case 6: {return "Anderson";
  79. }
  80. case 7: {return "Martin";
  81. }
  82. case 8: {return "Rossi";
  83. }
  84. case 9: {return "Silva";
  85. }
  86. case 10: {return "Gruber";
  87. }
  88. case 11: {return "Russu";
  89. }
  90. case 12: {return "Hodja";
  91. }
  92. case 13: {return "Murphy";
  93.  
  94. }
  95. case 14: {return "Borg";
  96.  
  97. }
  98. }
  99. }
  100.  
  101. class CrewMember
  102. {
  103. protected:
  104. string m_name;
  105. string m_surname;
  106. int m_expiriance;
  107. public:
  108. string GetName() { return m_name; }
  109. string GetSurname() { return m_surname; }
  110. int GetExp() { return m_expiriance; }
  111.  
  112. void PrintInfo()
  113. {
  114. cout << "This crew member name is " << m_name << " " << m_surname << endl
  115. << "This crew member expiriance at this role is " << m_expiriance << endl;
  116. }
  117.  
  118. virtual ~CrewMember() {}
  119. };
  120.  
  121. class Capitan :public CrewMember
  122. {
  123. private:
  124. void CheckExp()
  125. {
  126. if (m_expiriance == 300)
  127. {
  128. cout << "Congratsulations! Your Capitan reached max expiriance and now he is leaving you." << endl;
  129. Capitan::GenerateNewCapitan();
  130. }
  131. }
  132. public:
  133. //build random Capitan
  134. Capitan()
  135. {
  136. //set name
  137. m_name = RandomName();
  138. //set surname
  139. m_surname = RandomSurname();
  140. //set exp
  141. m_expiriance = rand() % 150 + 150;
  142. }
  143.  
  144. Capitan(string name, string surname, int expiriance)
  145. {
  146. m_name = name;
  147. m_surname = surname;
  148. m_expiriance = expiriance;
  149. }
  150. void Sail()
  151. {
  152. m_expiriance += 1;
  153. Capitan::CheckExp();
  154. }
  155.  
  156. static Capitan GenerateNewCapitan()
  157. {
  158. Capitan NewCapitan;
  159. string answer;
  160. cout << "Do you want to choose new random Capitan or create one by yourself?"
  161. << endl << "Input \"create\" to create new Capitan. Else it would be randomed." << endl;
  162.  
  163. cin >> answer;
  164. if (answer == "create")
  165. {
  166. cout << "Input new capitans name" << endl;
  167. string name;
  168. cin >> name;
  169.  
  170. cout << "Input new capitans surname" << endl;
  171. string surname;
  172. cin >> surname;
  173.  
  174. cout << "Input new capitans expiriance" << endl;
  175. int expiriance;
  176. cin >> expiriance;
  177.  
  178. try
  179. {
  180. Capitan capitan(name, surname, expiriance);
  181.  
  182. if (capitan.GetName().find_first_of
  183. ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
  184. throw invalid_argument("Invalid symbol at the name!");
  185. if (capitan.GetSurname().find_first_of
  186. ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
  187. throw invalid_argument("Invalid symbol at the surname!");
  188. if (capitan.GetExp()<75)
  189. throw invalid_argument("Invalid value of Capitan expiriance!");
  190. }
  191. catch (const invalid_argument& e)
  192. {
  193. cout << "Error:" << e.what() << endl;
  194. }
  195.  
  196. NewCapitan = Capitan::Capitan(name, surname, expiriance);
  197. }
  198. else
  199. NewCapitan = Capitan::Capitan();
  200.  
  201. cout << "This is your new Capitan!" << endl;
  202. NewCapitan.PrintInfo();
  203. return NewCapitan;
  204. }
  205. };
  206.  
  207.  
  208.  
  209. class Mate :public CrewMember
  210. {
  211. private:
  212. void CheckExp()
  213. {
  214. if (m_expiriance == 75)
  215. {
  216. cout << "Congratsulations! Your Mate became Capitan and now you need someone to become new Mate!" << endl;
  217. Mate::GenerateNewMate();
  218. }
  219. }
  220.  
  221.  
  222. public:
  223. Mate GenerateNewMate()
  224. {
  225. Mate NewMate;
  226. string answer;
  227. cout << "Do you want to choose random Mate or create one by yourself?"
  228. << endl << "Input \"create\" to create new mate. Else he would be randomed." << endl;
  229.  
  230. cin >> answer;
  231. if (answer == "create")
  232. {
  233. cout << "Input new Mates name" << endl;
  234. string name;
  235. cin >> name;
  236.  
  237. cout << "Input new Mates surname" << endl;
  238. string surname;
  239. cin >> surname;
  240.  
  241. cout << "Input new Mates expiriance" << endl;
  242. int expiriance;
  243. cin >> expiriance;
  244.  
  245. try
  246. {
  247. Mate mate(name, surname, expiriance);
  248.  
  249. if (mate.GetName().find_first_of
  250. ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
  251. throw invalid_argument("Invalid symbol at the name!");
  252. if (mate.GetSurname().find_first_of
  253. ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
  254. throw invalid_argument("Invalid symbol at the surname!");
  255. if (mate.GetExp()<75 || mate.GetExp()>150)
  256. throw invalid_argument("Invalid value of Mates expiriance!");
  257. }
  258. catch (invalid_argument e)
  259. {
  260. cout << "Error:" << e.what() << endl;
  261. }
  262.  
  263. NewMate = Mate::Mate(name, surname, expiriance);
  264. }
  265. else
  266. NewMate = Mate::Mate();
  267.  
  268. cout << "This is your new Mate!" << endl;
  269. NewMate.PrintInfo();
  270. return NewMate;
  271. }
  272.  
  273. void Sail()
  274. {
  275. m_expiriance += 1;
  276. Mate::CheckExp();
  277. }
  278.  
  279. Mate()
  280. {
  281. //set name
  282. m_name = RandomName();
  283. //set surname
  284. m_surname = RandomSurname();
  285. //set exp
  286. m_expiriance = rand() % 100 + 50;
  287. }
  288.  
  289. Mate(string name, string surname, int expiriance)
  290. {
  291. m_name = name;
  292. m_surname = surname;
  293. m_expiriance = expiriance;
  294. }
  295.  
  296. };
  297.  
  298. class OlderEngineer :public CrewMember {
  299. private:
  300. void CheckExp()
  301. {
  302. if (m_expiriance == 50)
  303. {
  304. cout << "Congratsulations! Your Older Engeneer reached max expiriance and now he is leaving you." << endl;
  305. OlderEngineer::GenerateNewOlderEngineer();
  306. }
  307. }
  308.  
  309.  
  310. public:
  311. OlderEngineer GenerateNewOlderEngineer()
  312. {
  313. OlderEngineer NewOlderEngineer;
  314. string answer;
  315. cout << "Do you want to choose new random Older Engineer or create one by yourself?"
  316. << endl << "Input \"create\" to create new Older Engineer. Else it would be randomed." << endl;
  317.  
  318. cin >> answer;
  319. if (answer == "create")
  320. {
  321. cout << "Input new Older Engineer name" << endl;
  322. string name;
  323. cin >> name;
  324.  
  325. cout << "Input new Older Engineer surname" << endl;
  326. string surname;
  327. cin >> surname;
  328.  
  329. cout << "Input new Older Engineer expiriance" << endl;
  330. int expiriance;
  331. cin >> expiriance;
  332.  
  333. try
  334. {
  335. OlderEngineer NewOlderEngineer(name, surname, expiriance);
  336.  
  337. if (NewOlderEngineer.GetName().find_first_of
  338. ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
  339. throw invalid_argument("Invalid symbol at the name!");
  340. if (NewOlderEngineer.GetSurname().find_first_of
  341. ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
  342. throw invalid_argument("Invalid symbol at the surname!");
  343. if (NewOlderEngineer.GetExp()<150)
  344. throw invalid_argument("Invalid value of Older Engineer expiriance!");
  345. }
  346. catch (invalid_argument e)
  347. {
  348. cout << "Error:" << e.what() << endl;
  349. }
  350.  
  351. NewOlderEngineer = OlderEngineer::OlderEngineer(name, surname, expiriance);
  352. }
  353. else
  354. NewOlderEngineer = OlderEngineer::OlderEngineer();
  355.  
  356. cout << "This is your new Older Engineer!" << endl;
  357. NewOlderEngineer.PrintInfo();
  358. return NewOlderEngineer;
  359. }
  360. OlderEngineer()
  361. {
  362. //set name
  363. m_name = RandomName();
  364. //set surname
  365. m_surname = RandomSurname();
  366. //set exp
  367. m_expiriance = rand() % 15 + 35;
  368. }
  369.  
  370. OlderEngineer(string name, string surname, int expiriance)
  371. {
  372. m_name = name;
  373. m_surname = surname;
  374. m_expiriance = expiriance;
  375. }
  376. void FixSmth()
  377. {
  378. m_expiriance += 1;
  379. OlderEngineer::CheckExp();
  380. }
  381. };
  382.  
  383. class OlderOfficer :public CrewMember {
  384. private:
  385. void CheckExp()
  386. {
  387. if (m_expiriance == 50)
  388. {
  389. cout << "Congratsulations! Your Older Engeneer reached max expiriance and now he is leaving you." << endl;
  390. OlderOfficer::GenerateNewOlderOfficer();
  391. }
  392. }
  393.  
  394. public
  395. :OlderOfficer GenerateNewOlderOfficer()
  396. {
  397. OlderOfficer NewOlderOfficer;
  398. string answer;
  399. cout << "Do you want to choose new random Older Officer or create one by yourself?"
  400. << endl << "Input \"create\" to create new Older Officer. Else it would be randomed." << endl;
  401.  
  402. cin >> answer;
  403. if (answer == "create")
  404. {
  405. cout << "Input new Older Officer name" << endl;
  406. string name;
  407. cin >> name;
  408.  
  409. cout << "Input new Older Officer surname" << endl;
  410. string surname;
  411. cin >> surname;
  412.  
  413. cout << "Input new Older Officer expiriance" << endl;
  414. int expiriance;
  415. cin >> expiriance;
  416.  
  417. try
  418. {
  419. OlderEngineer NewOlderOfficer(name, surname, expiriance);
  420.  
  421. if (NewOlderOfficer.GetName().find_first_of
  422. ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
  423. throw invalid_argument("Invalid symbol at the name!");
  424. if (NewOlderOfficer.GetSurname().find_first_of
  425. ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
  426. throw invalid_argument("Invalid symbol at the surname!");
  427. if (NewOlderOfficer.GetExp()<15 || NewOlderOfficer.GetExp()>50)
  428. throw invalid_argument("Invalid value of Older Officer expiriance!");
  429. }
  430. catch (invalid_argument e)
  431. {
  432. cout << "Error:" << e.what() << endl;
  433. }
  434.  
  435. NewOlderOfficer = OlderOfficer::OlderOfficer(name, surname, expiriance);
  436. }
  437. else
  438. NewOlderOfficer = OlderOfficer::OlderOfficer();
  439.  
  440. cout << "This is your new Older Engineer!" << endl;
  441. NewOlderOfficer.PrintInfo();
  442. return NewOlderOfficer;
  443. }
  444. OlderOfficer()
  445. {
  446. //set name
  447. m_name = RandomName();
  448. //set surname
  449. m_surname = RandomSurname();
  450. //set exp
  451. m_expiriance = rand() % 150 + 150;
  452. }
  453.  
  454. OlderOfficer(string name, string surname, int expiriance)
  455. {
  456. m_name = name;
  457. m_surname = surname;
  458. m_expiriance = expiriance;
  459. }
  460. void EmergState()
  461. {
  462. m_expiriance += 1;
  463. OlderOfficer::CheckExp();
  464. }
  465. };
  466.  
  467. class OlderSailor :public CrewMember {
  468. private:
  469. void CheckExp()
  470. {
  471. if (m_expiriance == 50)
  472. {
  473. cout << "Congratsulations! Your Older Sailor reached max expiriance and now he is leaving you." << endl;
  474. OlderSailor::GenerateNewOlderSailor();
  475. }
  476. }
  477.  
  478.  
  479.  
  480. public:
  481. OlderSailor GenerateNewOlderSailor()
  482. {
  483. OlderSailor NewOlderSailor;
  484. string answer;
  485. cout << "Do you want to choose new random Older Sailor or create one by yourself?"
  486. << endl << "Input \"create\" to create new Older Sailor. Else it would be randomed." << endl;
  487.  
  488. cin >> answer;
  489. if (answer == "create")
  490. {
  491. cout << "Input new Older Sailor name" << endl;
  492. string name;
  493. cin >> name;
  494.  
  495. cout << "Input new Older Sailor surname" << endl;
  496. string surname;
  497. cin >> surname;
  498.  
  499. cout << "Input new Older Sailor expiriance" << endl;
  500. int expiriance;
  501. cin >> expiriance;
  502.  
  503. try
  504. {
  505. OlderEngineer NewOlderOfficer(name, surname, expiriance);
  506.  
  507. if (NewOlderOfficer.GetName().find_first_of
  508. ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
  509. throw invalid_argument("Invalid symbol at the name!");
  510. if (NewOlderOfficer.GetSurname().find_first_of
  511. ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
  512. throw invalid_argument("Invalid symbol at the surname!");
  513. if (NewOlderOfficer.GetExp()<150)
  514. throw invalid_argument("Invalid value of Capitan expiriance!");
  515. }
  516. catch (invalid_argument e)
  517. {
  518. cout << "Error:" << e.what() << endl;
  519. }
  520.  
  521. NewOlderSailor = OlderSailor::OlderSailor(name, surname, expiriance);
  522. }
  523. else
  524. NewOlderSailor = OlderSailor::OlderSailor();
  525.  
  526. cout << "This is your new Older Engineer!" << endl;
  527. NewOlderSailor.PrintInfo();
  528. return NewOlderSailor;
  529. }
  530. OlderSailor()
  531. {
  532. //set name
  533. m_name = RandomName();
  534. //set surname
  535. m_surname = RandomSurname();
  536. //set exp
  537. m_expiriance = rand() % 25 + 25;
  538. }
  539.  
  540. OlderSailor(string name, string surname, int expiriance)
  541. {
  542. m_name = name;
  543. m_surname = surname;
  544. m_expiriance = expiriance;
  545. }
  546. void Sail()
  547. {
  548. m_expiriance += 1;
  549. OlderSailor::CheckExp();
  550. }
  551. };
  552.  
  553.  
  554. class Engineer :public CrewMember
  555. {
  556. private:
  557. void CheckExp()
  558. {
  559. if (m_expiriance == 50)
  560. {
  561. cout << "Congratsulations! Your Engeneer reached max expiriance and now he is leaving you." << endl;
  562. Engineer::GenerateNewEngineer();
  563. }
  564. }
  565.  
  566.  
  567. public:
  568. Engineer GenerateNewEngineer()
  569. {
  570. Engineer NewEngineer;
  571. string answer;
  572. cout << "Do you want to choose new Engineer or create one by yourself?"
  573. << endl << "Input \"create\" to create new Engineer. Else it would be randomed." << endl;
  574.  
  575. cin >> answer;
  576. if (answer == "create")
  577. {
  578. cout << "Input new Engineer name" << endl;
  579. string name;
  580. cin >> name;
  581.  
  582. cout << "Input new Engineer surname" << endl;
  583. string surname;
  584. cin >> surname;
  585.  
  586. cout << "Input new Engineer expiriance" << endl;
  587. int expiriance;
  588. cin >> expiriance;
  589.  
  590. try
  591. {
  592. OlderEngineer NewEngineer(name, surname, expiriance);
  593.  
  594. if (NewEngineer.GetName().find_first_of
  595. ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
  596. throw invalid_argument("Invalid symbol at the name!");
  597. if (NewEngineer.GetSurname().find_first_of
  598. ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
  599. throw invalid_argument("Invalid symbol at the surname!");
  600. if (NewEngineer.GetExp()<0 || NewEngineer.GetExp()>15)
  601. throw invalid_argument("Invalid value of Engineer expiriance!");
  602. }
  603. catch (invalid_argument e)
  604. {
  605. cout << "Error:" << e.what() << endl;
  606. }
  607.  
  608. NewEngineer = Engineer::Engineer(name, surname, expiriance);
  609. }
  610. else
  611. NewEngineer = Engineer::Engineer();
  612.  
  613. cout << "This is your new Engineer!" << endl;
  614. NewEngineer.PrintInfo();
  615. return NewEngineer;
  616. }
  617. Engineer()
  618. {
  619. //set name
  620. m_name = RandomName();
  621. //set surname
  622. m_surname = RandomSurname();
  623. //set exp
  624. m_expiriance = rand() % 15;
  625. }
  626.  
  627. Engineer(string name, string surname, int expiriance)
  628. {
  629. m_name = name;
  630. m_surname = surname;
  631. m_expiriance = expiriance;
  632. }
  633.  
  634. void FixSmth()
  635. {
  636. m_expiriance += 1;
  637. Engineer::CheckExp();
  638. }
  639. };
  640.  
  641.  
  642. class Sailor :public CrewMember {
  643. private:
  644. void CheckExp()
  645. {
  646. if (m_expiriance == 25)
  647. {
  648. cout << "Congratsulations! Your Sailor reached max expiriance and now he is leaving you." << endl;
  649. Sailor::GenerateNewSailor();
  650. }
  651. }
  652.  
  653.  
  654.  
  655. public:
  656. Sailor()
  657. {
  658. //set name
  659. m_name = RandomName();
  660. //set surname
  661. m_surname = RandomSurname();
  662. //set exp
  663. m_expiriance = rand() % 25;
  664. }
  665.  
  666. Sailor(string name, string surname, int expiriance)
  667. {
  668. m_name = name;
  669. m_surname = surname;
  670. m_expiriance = expiriance;
  671. }
  672. void Sail()
  673. {
  674. m_expiriance += 1;
  675. Sailor::CheckExp();
  676. }
  677. Sailor GenerateNewSailor()
  678. {
  679. Sailor NewSailor;
  680. string answer;
  681. cout << "Do you want to choose new random Sailor or create one by yourself?"
  682. << endl << "Input \"create\" to create new Sailor. Else it would be randomed." << endl;
  683.  
  684. cin >> answer;
  685. if (answer == "create")
  686. {
  687. cout << "Input new Sailor name" << endl;
  688. string name;
  689. cin >> name;
  690.  
  691. cout << "Input new Sailor surname" << endl;
  692. string surname;
  693. cin >> surname;
  694.  
  695. cout << "Input new Sailor expiriance" << endl;
  696. int expiriance;
  697. cin >> expiriance;
  698.  
  699. try
  700. {
  701. Sailor sailor(name, surname, expiriance);
  702.  
  703. if (sailor.GetName().find_first_of
  704. ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
  705. throw invalid_argument("Invalid symbol at the name!");
  706. if (sailor.GetSurname().find_first_of
  707. ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
  708. throw invalid_argument("Invalid symbol at the surname!");
  709. if (sailor.GetExp()<0 || sailor.GetExp()>25)
  710. throw invalid_argument("Invalid value of expiriance!");
  711. }
  712. catch (invalid_argument e)
  713. {
  714. cout << "Error:" << e.what() << endl;
  715. }
  716.  
  717. NewSailor = Sailor::Sailor(name, surname, expiriance);
  718. }
  719. else
  720. NewSailor = Sailor::Sailor();
  721.  
  722. cout << "This is your new Sailor!" << endl;
  723. NewSailor.PrintInfo();
  724. return NewSailor;
  725. }
  726. };
  727.  
  728. class Officer :public CrewMember {
  729. private:
  730. void CheckExp()
  731. {
  732. if (m_expiriance == 15)
  733. {
  734. cout << "Congratsulations! Your Officer reached max expiriance and now he is leaving you." << endl;
  735. Officer::GenerateNewOfficer();
  736. }
  737. }
  738.  
  739.  
  740. public:
  741. Officer()
  742. {
  743. //set name
  744. m_name = RandomName();
  745. //set surname
  746. m_surname = RandomSurname();
  747. //set exp
  748. //set exp
  749. m_expiriance = rand() % 15;
  750. }
  751.  
  752. Officer(string name, string surname, int expiriance)
  753. {
  754. m_name = name;
  755. m_surname = surname;
  756. m_expiriance = expiriance;
  757. }
  758. void EmergState()
  759. {
  760. m_expiriance += 1;
  761. Officer::CheckExp();
  762. }
  763. Officer GenerateNewOfficer()
  764. {
  765. Officer NewOfficer;
  766. string answer;
  767. cout << "Do you want to choose new random Officer or create one by yourself?"
  768. << endl << "Input \"create\" to create new Officer. Else it would be randomed." << endl;
  769.  
  770. cin >> answer;
  771. if (answer == "create")
  772. {
  773. cout << "Input new Officer name" << endl;
  774. string name;
  775. cin >> name;
  776.  
  777. cout << "Input new Officer surname" << endl;
  778. string surname;
  779. cin >> surname;
  780.  
  781. cout << "Input new Officer expiriance" << endl;
  782. int expiriance;
  783. cin >> expiriance;
  784.  
  785. try
  786. {
  787. Officer NewOfficer(name, surname, expiriance);
  788.  
  789. if (NewOfficer.GetName().find_first_of
  790. ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
  791. throw invalid_argument("Invalid symbol at the name!");
  792. if (NewOfficer.GetSurname().find_first_of
  793. ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
  794. throw invalid_argument("Invalid symbol at the surname!");
  795. if (NewOfficer.GetExp()<0 || NewOfficer.GetExp()>15)
  796. throw invalid_argument("Invalid value of expiriance!");
  797. }
  798. catch (invalid_argument e)
  799. {
  800. cout << "Error:" << e.what() << endl;
  801. }
  802.  
  803. NewOfficer = Officer::Officer(name, surname, expiriance);
  804. }
  805. else
  806. NewOfficer = Officer::Officer();
  807.  
  808. cout << "This is your new Older Engineer!" << endl;
  809. NewOfficer.PrintInfo();
  810. return NewOfficer;
  811. }
  812. };
  813.  
  814. class Chief :public CrewMember {
  815.  
  816. private:
  817. void CheckExp()
  818. {
  819. if (m_expiriance == 300)
  820. {
  821. cout << "Congratsulations! Your Chief reached max expiriance and now he is leaving you." << endl;
  822. Chief::GenerateNewChief();
  823. }
  824. }
  825.  
  826.  
  827. public:
  828.  
  829. Chief()
  830. {
  831. //set name
  832. m_name = RandomName();
  833. //set surname
  834. m_surname = RandomSurname();
  835. //set exp
  836. m_expiriance = rand() % 15 + 35;
  837. }
  838.  
  839. Chief(string name, string surname, int expiriance)
  840. {
  841. m_name = name;
  842. m_surname = surname;
  843. m_expiriance = expiriance;
  844. }
  845. void Sail()
  846. {
  847. m_expiriance += 1;
  848. Chief::CheckExp();
  849. }
  850. Chief GenerateNewChief()
  851. {
  852. Chief NewChief;
  853. string answer;
  854. cout << "Do you want to choose new random Chief or create one by yourself?"
  855. << endl << "Input \"create\" to create new Chief. Else it would be randomed." << endl;
  856.  
  857. cin >> answer;
  858. if (answer == "create")
  859. {
  860. cout << "Input new Chief name" << endl;
  861. string name;
  862. cin >> name;
  863.  
  864. cout << "Input new Chief surname" << endl;
  865. string surname;
  866. cin >> surname;
  867.  
  868. cout << "Input new Chief expiriance" << endl;
  869. int expiriance;
  870. cin >> expiriance;
  871.  
  872. try
  873. {
  874. Chief NewChief(name, surname, expiriance);
  875.  
  876. if (NewChief.GetName().find_first_of
  877. ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
  878. throw invalid_argument("Invalid symbol at the name!");
  879. if (NewChief.GetSurname().find_first_of
  880. ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
  881. throw invalid_argument("Invalid symbol at the surname!");
  882. if (NewChief.GetExp()<0 || NewChief.GetExp()>300)
  883. throw invalid_argument("Invalid value of Chief expiriance!");
  884. }
  885. catch (invalid_argument e)
  886. {
  887. cout << "Error:" << e.what() << endl;
  888. }
  889.  
  890. NewChief = Chief::Chief(name, surname, expiriance);
  891. }
  892. else
  893. NewChief = Chief::Chief();
  894.  
  895. cout << "This is your new Chief!" << endl;
  896. NewChief.PrintInfo();
  897. return NewChief;
  898. }
  899. };
  900.  
  901. class Crew
  902. {
  903. private:
  904. const int StockSailorsNum = 10;
  905. const int StockEngineersNum = 3;
  906. int SailorNum;
  907. int EngineerNum;
  908. Capitan m_Capitan;
  909. Mate m_Mate;
  910. OlderEngineer m_OlderEngineer;
  911. OlderOfficer m_OlderOfficer;
  912. OlderSailor m_OlderSailor;
  913. Chief m_Chief;
  914. vector<Sailor> m_Sailors;
  915. vector<Engineer> m_Engineers;
  916.  
  917. public:
  918. // 6 основных членов команды
  919. int CrewSize() { return (6 + m_Engineers.size() + m_Sailors.size()); }
  920. Crew& operator=(const Crew & other);
  921. Crew()
  922. {
  923. m_Capitan = Capitan::Capitan();
  924. m_Mate = Mate::Mate();
  925. m_OlderEngineer = OlderEngineer::OlderEngineer();
  926. m_OlderOfficer = OlderOfficer::OlderOfficer();
  927. m_OlderSailor = OlderSailor::OlderSailor();
  928. m_Chief = Chief::Chief();
  929. for (int i = 0; i<StockSailorsNum; i++)
  930. m_Sailors.push_back(Sailor::Sailor());
  931. for (int i = 0; i<StockEngineersNum; i++)
  932. m_Engineers.push_back(Engineer::Engineer());
  933. }
  934. Crew(const Capitan& capitan, Mate mate, OlderEngineer older_engineer, OlderOfficer older_officer, OlderSailor older_sailor,
  935. vector<Sailor>& sailors, vector<Engineer>& engineers, Chief chief)
  936. {
  937. m_Capitan = capitan;
  938. m_Mate = mate;
  939. m_OlderEngineer = older_engineer;
  940. m_OlderOfficer = older_officer;
  941. m_OlderSailor = older_sailor;
  942. m_Sailors = sailors;
  943. m_Engineers = engineers;
  944. m_Chief = chief;
  945. }
  946. void GenerateNewCrew()
  947. {
  948. cout << "Do you want to create new team? Or choose it randomly?" << endl <<
  949. "Input \"create\" to create new team. Else it would be randomed" << endl;
  950. string answer;
  951. cin >> answer;
  952. if (answer == "create")
  953. {
  954. m_Capitan = m_Capitan.GenerateNewCapitan();
  955. m_Mate = m_Mate.GenerateNewMate();
  956. m_OlderOfficer = m_OlderOfficer.GenerateNewOlderOfficer();
  957. m_OlderEngineer = m_OlderEngineer.GenerateNewOlderEngineer();
  958. m_OlderSailor = m_OlderSailor.GenerateNewOlderSailor();
  959. for (int i = 0; i < m_Sailors.size(); i++)
  960. {
  961. m_Sailors[i] = m_Sailors[i].GenerateNewSailor();
  962. }
  963. for (int i = 0; i < m_Engineers.size(); i++)
  964. {
  965. m_Engineers[i] = m_Engineers[i].GenerateNewEngineer();
  966. }
  967. //Crew NewCrew(m_Capitan, m_Mate, m_OlderEngineer, m_OlderOfficer, m_OlderSailor, m_Sailors, m_Engineers, m_Chief);
  968.  
  969. //return NewCrew;
  970. }
  971. else
  972. {
  973. Crew NewCrew = Crew::Crew();
  974. }
  975.  
  976.  
  977. }
  978. void Info()
  979. {
  980. m_Capitan.PrintInfo();
  981. cout << endl;
  982.  
  983. m_Mate.PrintInfo();
  984. cout << endl;
  985.  
  986. m_OlderOfficer.PrintInfo();
  987. cout << endl;
  988.  
  989. m_OlderEngineer.PrintInfo();
  990. cout << endl;
  991.  
  992. m_OlderSailor.PrintInfo();
  993. cout << endl;
  994.  
  995. m_Chief.PrintInfo();
  996. cout << endl;
  997.  
  998. for (int i = 0; i < m_Sailors.size(); i++)
  999. {
  1000. m_Sailors[i].PrintInfo();
  1001. cout << endl;
  1002. }
  1003.  
  1004. for (int i = 0; i < m_Engineers.size(); i++)
  1005. {
  1006. m_Engineers[i].PrintInfo();
  1007. cout << endl;
  1008. }
  1009. }
  1010. };
  1011. class Ship
  1012. {
  1013. protected:
  1014. double perc;
  1015. double m_EnginePower;
  1016. double m_Displacement;
  1017. string m_ShipName;
  1018. string m_PortName;
  1019. Crew m_Crew;
  1020. bool CheckPerc(int perc)
  1021. {
  1022. return (perc > 0);
  1023. }
  1024. public:
  1025. virtual ~Ship()
  1026. {
  1027.  
  1028. }
  1029.  
  1030. double UpgradeEngine()
  1031. {
  1032. cout << "Input percenatge of upgrade" << endl;
  1033. cin >> perc;
  1034. if (CheckPerc(perc) == 1)
  1035. m_EnginePower *= (1 + perc / 100);
  1036. return m_EnginePower;
  1037. }
  1038.  
  1039. double UpgradeDisplacement()
  1040. {
  1041. cout << "Input percenatge of upgrade" << endl;
  1042. cin >> perc;
  1043. if (CheckPerc(perc) == 1)
  1044. m_Displacement *= (1 + perc / 100);
  1045. return m_Displacement;
  1046. }
  1047.  
  1048. string& UpgradeShipName()
  1049. {
  1050. cout << "Input New Ships name" << endl;
  1051. cin >> m_ShipName;
  1052. return m_ShipName;
  1053. }
  1054.  
  1055. string& UpdatePort()
  1056. {
  1057. cout << "Input new Home Port" << endl;
  1058. cin >> m_PortName;
  1059. return m_PortName;
  1060. }
  1061. Ship()
  1062. {
  1063. m_EnginePower = 1000;
  1064. m_Displacement = 1000;
  1065. m_ShipName = "Ship";
  1066. m_PortName = "Port";
  1067. m_Crew = Crew();
  1068. }
  1069. Ship(int EnginePower, int Displacement, string ShipName, string PortName, const Crew& crew): m_Crew(crew)
  1070. {
  1071. if (EnginePower < 1000)
  1072. {
  1073. throw invalid_argument("- Invalid value of Engine Power!");
  1074. }
  1075. m_EnginePower = EnginePower;
  1076.  
  1077.  
  1078.  
  1079.  
  1080.  
  1081. if (Displacement < 1000)
  1082. {
  1083. throw invalid_argument("- Invalid value of Displacement!");
  1084. }
  1085. m_Displacement = Displacement;
  1086.  
  1087.  
  1088.  
  1089. m_ShipName = ShipName;
  1090. m_PortName = PortName;
  1091. }
  1092. void ModifyShip()
  1093. {
  1094. string str;
  1095. cout << "Do you want to modify your ship?" << endl << "Input y or yes to continue. Input smth else to exit" << endl;
  1096. cin >> str;
  1097. while (str == "yes" || str == "y")
  1098. {
  1099. {
  1100. int x;
  1101. cout << "What do you want to upgrade?" << endl <<
  1102. "Input 0 for upgrading Engine Power" << endl <<
  1103. "Input 1 for upgrading Displacement" << endl <<
  1104. "Input 2 to refresh Ship Name" << endl <<
  1105. "Input 3 to change Port Name" << endl <<
  1106. "Input 4 to change team" << endl;
  1107. cin >> x;
  1108. try
  1109. {
  1110. if (x < 0)
  1111. {
  1112. throw (invalid_argument("x cant be more then 4 or less then 0"));
  1113. }
  1114.  
  1115. switch (x)
  1116. {
  1117. case(0):
  1118. {
  1119. Ship::UpgradeEngine();
  1120. cout << m_EnginePower << endl;
  1121. break;
  1122. }
  1123. case(1):
  1124. {
  1125.  
  1126. Ship::UpgradeDisplacement();
  1127. cout << m_Displacement << endl;
  1128. break;
  1129. }
  1130. case(2):
  1131. {
  1132.  
  1133. Ship::UpgradeShipName();
  1134. cout << m_ShipName << endl;;
  1135. break;
  1136. }
  1137. case(3):
  1138. {
  1139. Ship::UpdatePort();
  1140. cout << m_PortName << endl;
  1141. break;
  1142. }
  1143. case(4):
  1144. {
  1145. m_Crew.GenerateNewCrew();
  1146. m_Crew.Info();
  1147. break;
  1148. }
  1149. default:
  1150. {
  1151. break;
  1152. }
  1153. }
  1154.  
  1155. }
  1156. catch (invalid_argument e)
  1157. {
  1158. cout << "Error:" << e.what() << endl;
  1159. }
  1160. }
  1161. cout << "Do you want to continue modifiying your ship?" << endl <<
  1162. "Input y or yes to continue.Input smth else to exit" << endl;
  1163. cin >> str;
  1164. }
  1165. }
  1166.  
  1167. };
  1168.  
  1169.  
  1170. class PassangerShip : public Ship
  1171. {
  1172. private:
  1173. const int BoatSize = 15;
  1174. int m_BoatNum;
  1175. int m_PassNum;
  1176.  
  1177. public:
  1178. void Info()
  1179. {
  1180. cout << "Engine power is " << m_EnginePower << endl;
  1181. cout << "Displacement is " << m_Displacement << endl;
  1182. cout << "EShip Name is " << m_ShipName << endl;
  1183. cout << "Home Port is " << m_PortName << endl;
  1184. cout << "Boat Number is " << m_BoatNum << endl;
  1185. cout << "Passenger number is " << m_PassNum << endl;
  1186. m_Crew.Info();
  1187. }
  1188. bool CheckBoatNum()
  1189. {
  1190. return (m_BoatNum * BoatSize > m_PassNum + m_Crew.CrewSize());
  1191. }
  1192.  
  1193. void AddBoat()
  1194. {
  1195. if (PassangerShip::CheckBoatNum() == 0)
  1196. {
  1197. m_BoatNum += ((m_PassNum + BoatSize * m_BoatNum) % BoatSize + 1);
  1198. }
  1199. }
  1200. PassangerShip()
  1201. {
  1202. m_EnginePower = 1000;
  1203. m_Displacement = 1000;
  1204. m_ShipName = "Ship";
  1205. m_PortName = "Port";
  1206. m_Crew = Crew::Crew();
  1207. m_PassNum = 10;
  1208. m_BoatNum = 2;
  1209. }
  1210. PassangerShip(int EnginePower, int Displacement, string ShipName, string PortName, Crew crew, int PassNum, int BoatNum)
  1211. :Ship(EnginePower, Displacement, ShipName, PortName, crew)
  1212. {
  1213. try
  1214. {
  1215. if (EnginePower < 1000)
  1216. {
  1217. throw invalid_argument("Engine Power is too small");
  1218. }
  1219. m_EnginePower = EnginePower;
  1220. }
  1221. catch (invalid_argument e)
  1222. {
  1223. cout << "Error:" << e.what() << endl;
  1224. }
  1225.  
  1226.  
  1227. try
  1228. {
  1229. if (Displacement < 1000)
  1230. {
  1231. throw invalid_argument("Displacement is too small");
  1232. }
  1233. m_Displacement = Displacement;
  1234. }
  1235. catch (invalid_argument e)
  1236. {
  1237. cout << "Error:" << e.what() << endl;
  1238. }
  1239.  
  1240. m_ShipName = ShipName;
  1241. m_PortName = PortName;
  1242. m_Crew = crew;
  1243.  
  1244. try
  1245. {
  1246. if (PassNum < 15)
  1247. {
  1248. throw invalid_argument("not enough passangers");
  1249. }
  1250. m_PassNum = PassNum;
  1251. }
  1252. catch (invalid_argument e)
  1253. {
  1254. cout << "Error:" << e.what() << endl;
  1255. }
  1256. try
  1257. {
  1258. if (BoatNum < 1)
  1259. {
  1260. throw invalid_argument("Number of boas cant be less then 1");
  1261. }
  1262. m_BoatNum = BoatNum;
  1263. }
  1264. catch (invalid_argument e)
  1265. {
  1266. cout << "Error:" << e.what() << endl;
  1267. }
  1268. }
  1269. void AddExtraBoats(int AddictibleBoats)
  1270. {
  1271. m_BoatNum += AddictibleBoats;
  1272. }
  1273. };
  1274.  
  1275. class CargoShip :public Ship
  1276. {
  1277. private:
  1278. int m_LoadCapacity;
  1279. public:
  1280. CargoShip()
  1281. {
  1282. m_EnginePower = 1000;
  1283. m_Displacement = 1000;
  1284. m_ShipName = "Ship";
  1285. m_PortName = "Port";
  1286. m_Crew = Crew::Crew();
  1287. m_LoadCapacity = 1000;
  1288. }
  1289. CargoShip(int EnginePower, int Displacement, string ShipName, string PortName, Crew crew, int LoadCapacity)
  1290. :Ship(EnginePower, Displacement, ShipName, PortName, crew)
  1291. {
  1292. m_EnginePower = EnginePower;
  1293. m_Displacement = Displacement;
  1294. m_ShipName = ShipName;
  1295. m_PortName = PortName;
  1296. m_Crew = crew;
  1297. try
  1298. {
  1299. if (LoadCapacity < 1000)
  1300. {
  1301. throw (invalid_argument(" - Invalid value of this field!"));
  1302. }
  1303. m_LoadCapacity = LoadCapacity;
  1304. }
  1305. catch (invalid_argument e)
  1306. {
  1307. cout << "Error!" << e.what() << endl;
  1308. }
  1309. }
  1310. };
  1311.  
  1312. void StartProgram()
  1313. {
  1314. cout << "What dou you want to do?" << endl;
  1315. cout << "1) Generate Passanger ship" << endl;
  1316. cout << "2) Generate Cargo ship" << endl;
  1317. int x;
  1318. cin >> x;
  1319. switch (x)
  1320. {
  1321. case 1:
  1322. {
  1323. try
  1324. {
  1325. string name, port;
  1326. int EnginePower, Displacement, BoatNum, PassNum;
  1327. Crew crew;
  1328. cout << "Input ships name" << endl;
  1329. cin >> name;
  1330. cout << "Input ships Home Port" << endl;
  1331. cin >> port;
  1332. cout << "Input ships Engine Power" << endl;
  1333. cin >> EnginePower;
  1334. cout << "Input ships Displacement" << endl;
  1335. cin >> Displacement;
  1336. cout << "Input Boat number" << endl;
  1337. cin >> BoatNum;
  1338. cout << "Input Passenger number" << endl;
  1339. cin >> PassNum;
  1340. crew.GenerateNewCrew();
  1341. PassangerShip ship(EnginePower, Displacement, name, port, crew, PassNum, BoatNum);
  1342. ship.AddBoat();
  1343. ship.Info();
  1344. cout << "Do you want to modify ship?" << endl;
  1345. string answer;
  1346. cin >> answer;
  1347. if (answer == "yes" || answer == "y")
  1348. ship.ModifyShip();
  1349. }
  1350. catch (const invalid_argument& e)
  1351. {
  1352. cout << "Error:" << e.what() << endl;
  1353. }
  1354. catch (const exception& e)
  1355. {
  1356. cout << "Unexpected Error:" << e.what() << endl;
  1357. }
  1358.  
  1359. break;
  1360. }
  1361. case 2:
  1362. {
  1363. string name, port;
  1364. int EnginePower, Displacement, LoadCapacity;
  1365. Crew crew;
  1366. cout << "Input ships name" << endl;
  1367. cin >> name;
  1368. cout << "Input ships Home Port" << endl;
  1369. cin >> port;
  1370. cout << "Input ships Engine Power" << endl;
  1371. cin >> EnginePower;
  1372. cout << "Input ships Displacement" << endl;
  1373. cin >> Displacement;
  1374. cout << "Input Load Capacity" << endl;
  1375. cin >> LoadCapacity;
  1376. crew.GenerateNewCrew();
  1377. CargoShip ship(EnginePower, Displacement, name, port, crew, LoadCapacity);
  1378. break;
  1379. }
  1380. default:
  1381. {
  1382. cout << "Gool Luck!" << endl;
  1383. }
  1384. }
  1385. }
  1386.  
  1387. int main()
  1388. {
  1389. srand(time(NULL));
  1390. StartProgram();
  1391. return 0;
  1392. }
  1393.  
  1394. Crew& Crew::operator=(const Crew & other)
  1395. {
  1396. this->m_Capitan = other.m_Capitan;
  1397. this->m_Mate = other.m_Mate;
  1398. this->m_Chief = other.m_Chief;
  1399. this->m_OlderOfficer = other.m_OlderOfficer;
  1400. this->m_OlderEngineer = other.m_OlderEngineer;
  1401. this->SailorNum = other.SailorNum;
  1402. this->EngineerNum = other.EngineerNum;
  1403. this->m_OlderSailor = other.m_OlderSailor;
  1404. this->m_Sailors = other.m_Sailors;
  1405. this->m_Engineers = other.m_Engineers;
  1406. return *this;
  1407. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement