Advertisement
kokokozhina

Untitled

Dec 11th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <map>
  4. #include <set>
  5. #include <vector>
  6. #include <string>
  7. #include <stdio.h>
  8.  
  9. using namespace std;
  10.  
  11. class Electrical_facility //электрическая установка
  12. {
  13. protected:
  14. string type;
  15. double r;
  16. public:
  17. Electrical_facility(string newtype, double newr)
  18. {
  19. type = newtype;
  20. r = newr;
  21. }
  22.  
  23. string get_type()
  24. {
  25. return type;
  26. }
  27.  
  28. //void set_type(string newtype)
  29. //{
  30. // this->type = newtype;
  31. //}
  32.  
  33. double get_r()
  34. {
  35. return r;
  36. }
  37.  
  38. void set_r(double newr)
  39. {
  40. this->r = newr;
  41. }
  42.  
  43. virtual void print()
  44. {
  45. cout << this->get_type() << ": " << this->get_r() << " Om" << endl;
  46. }
  47. };
  48.  
  49. class Lamp : public Electrical_facility
  50. {
  51. protected:
  52. bool light;
  53. public:
  54. Lamp(double newr) : Electrical_facility("LMP", newr)
  55. {
  56. light = false;
  57. }
  58.  
  59. bool get_light()
  60. {
  61. return light;
  62. }
  63.  
  64. void set_light(bool newlight)
  65. {
  66. this->light = newlight;
  67. }
  68.  
  69. void print()
  70. {
  71. cout << this->get_type() << ": " << this->get_r() << " Om ";
  72. if(this->get_light())
  73. cout << "light: on\n";
  74. else
  75. cout << "light: off\n";
  76. }
  77.  
  78. };
  79.  
  80. class Resistor : public Electrical_facility
  81. {
  82. public:
  83. Resistor(double newr) : Electrical_facility("RES", newr) {}
  84.  
  85. void print()
  86. {
  87. cout << this->get_type() << ": " << this->get_r() << " Om" << endl;
  88. }
  89. };
  90.  
  91. class Appliance : public Electrical_facility
  92. {
  93. protected:
  94. double req_u, req_i, du, di;
  95. bool is_working;
  96.  
  97. public:
  98. Appliance(double newr, double newrequ, double newreqi,
  99. double newdu, double newdi) : Electrical_facility("APP", newr)
  100. {
  101. req_u = newrequ;
  102. du = newdu;
  103. req_i = newreqi;
  104. di = newdi;
  105. is_working = false;
  106. }
  107.  
  108. double get_req_u()
  109. {
  110. return req_u;
  111. }
  112.  
  113. void set_req_u(double newreq_u)
  114. {
  115. this->req_u = newreq_u;
  116. }
  117.  
  118. double get_req_i()
  119. {
  120. return req_i;
  121. }
  122.  
  123. void set_req_i(double newreq_i)
  124. {
  125. this->req_i = newreq_i;
  126. }
  127.  
  128. double get_du()
  129. {
  130. return du;
  131. }
  132.  
  133. void set_du(double newdu)
  134. {
  135. this->du = newdu;
  136. }
  137.  
  138. double get_di()
  139. {
  140. return di;
  141. }
  142.  
  143. void set_di(double newdi)
  144. {
  145. this->di = newdi;
  146. }
  147.  
  148. void set_is_working(bool state)
  149. {
  150. this->is_working = state;
  151. }
  152.  
  153. bool get_is_working()
  154. {
  155. return is_working;
  156. }
  157.  
  158. void print()
  159. {
  160. cout << this->get_type() << ": " << this->get_r() << " Om ";
  161. if(this->get_is_working())
  162. cout << "work: on\n";
  163. else
  164. cout << "work: off\n";
  165. cout << " required: " << this->get_req_u() << "V " << this->get_req_i() << "A \n";
  166. cout << " variation: " << this->get_du() << "V " << this->get_di() << "A \n";
  167. }
  168. };
  169.  
  170. class CCS : public Electrical_facility
  171. {
  172. protected:
  173. double e;
  174.  
  175. public:
  176. CCS(double newr, double newe) : Electrical_facility("CCS", newr)
  177. {
  178. e = newe;
  179. }
  180.  
  181. double get_e()
  182. {
  183. return e;
  184. }
  185.  
  186. void set_e(double newe)
  187. {
  188. this->e = newe;
  189. }
  190.  
  191. void print()
  192. {
  193. cout << this->get_type() << ": " << this->get_r() << " Om " << this->get_e() << " V" << endl;
  194. }
  195. };
  196.  
  197. class Key : public Electrical_facility
  198. {
  199. protected:
  200. bool state;
  201.  
  202. public:
  203. Key(bool newstate) : Electrical_facility("KEY", 0)
  204. {
  205. state = newstate;
  206. }
  207.  
  208. bool get_state()
  209. {
  210. return state;
  211. }
  212.  
  213. void set_state(bool newstate)
  214. {
  215. this->state = newstate;
  216. }
  217.  
  218. void print()
  219. {
  220. cout << this->get_type() << ": ";
  221. if(this->get_state())
  222. cout << "locked \n";
  223. else
  224. cout << "unlocked \n";
  225. }
  226. };
  227.  
  228. class Branch
  229. {
  230. protected:
  231. vector<Electrical_facility*> branch;
  232. public:
  233. Branch() {}
  234. void set_el_f(int chain_number)
  235. {
  236. cout << "If you want to set a new lamp, please type 1" << endl;
  237. cout << "If you want to set a new resistor, please type 2" << endl;
  238. cout << "If you want to set a new appliance, please type 3" << endl;
  239. cout << "If you want to set a new CCS, please type 4" << endl;
  240. cout << "If you want to set a new key, please type 5" << endl;
  241. cout << "Be careful: you can set only CCS in main subchain" << endl;
  242. int type, place; cin >> type;
  243. cout << "Now please type the number of position, where you want to put it: ";
  244. cin >> place;
  245.  
  246. Electrical_facility* new_obj = new Electrical_facility("error", -100500);
  247. double r, ru, ri, du, di, e;
  248. bool f = true;
  249. switch (type)
  250. {
  251. case 1:
  252. cout << "Please enter the lamp resistance: ";
  253. cin >> r;
  254. if(chain_number)
  255. new_obj = new Lamp(r);
  256. else
  257. f = false;
  258. break;
  259. case 2:
  260. cout << "Please enter the resistor resistance: ";
  261. cin >> r;
  262. if(chain_number)
  263. new_obj = new Resistor(r);
  264. else
  265. f = false;
  266. break;
  267. case 3:
  268. cout << "Please enter the appliance resistance, then required voltage and amperage, ";
  269. cout << "then variation of voltage and amperage: ";
  270. cin >> r >> ru >> ri >> du >> di;
  271. if(chain_number)
  272. new_obj = new Appliance(r, ru, ri, du, di);
  273. else
  274. f = false;
  275. break;
  276. case 4:
  277. cout << "Please enter the CCS resistance and electromotive force: ";
  278. cin >> r >> e;
  279. if(chain_number != 0)
  280. {
  281. cout << "You can't place CCS here\n";
  282. f = false;
  283. }
  284. else
  285. new_obj = new CCS(r, e);
  286. break;
  287. case 5:
  288. cout << "Please enter the key state: ";
  289. bool st;
  290. cin >> st;
  291. if(chain_number)
  292. new_obj = new Key(st);
  293. else
  294. f = false;
  295. break;
  296. default:
  297. f = false;
  298. cout << "Something went wrong, please try again\n";
  299. break;
  300. }
  301.  
  302. place--;
  303. if(f)
  304. if(place < 0 || place > branch.size())
  305. cout << "Something went wrong, please try again\n";
  306. else
  307. {
  308. branch.insert(branch.begin() + place, new_obj);
  309. }
  310. }
  311.  
  312. //bool is_empty(){
  313. // return branch.empty();
  314. //}
  315.  
  316. void remove_el_f()
  317. {
  318. cout << "Please enter the number of the facility you want to remove: ";
  319. int n; cin >> n; n--;
  320. if(n >= branch.size() || n < 0)
  321. cout << "Something went wrong, please try again\n";
  322. else
  323. branch.erase(branch.begin() + n);
  324. }
  325.  
  326. bool is_locked()
  327. {
  328. bool res = true;
  329. for(int i = 0; i < branch.size(); i++)
  330. {
  331. if(branch[i]->get_type() == "KEY")
  332. {
  333. Key key = *(dynamic_cast<Key*>(branch[i]));
  334. if(!key.get_state())
  335. {
  336. res = false;
  337. break;
  338. }
  339. }
  340. }
  341. return res;
  342. }
  343.  
  344. double get_r_from_to(int from, int to)
  345. {
  346. double res = 0;
  347. from--, to--;
  348. if(to >= 0 && to < branch.size() && from >=0 && from < branch.size()
  349. && to >= from && this->is_locked())
  350. for(int i = from; i <= to; i++)
  351. res += branch[i]->get_r();
  352. return res;
  353. }
  354.  
  355. void change_parameters()
  356. {
  357. cout << "There are " << branch.size() << " elements in this branch\n";
  358. cout << "Enter the number of element which parameters you want to change: ";
  359. int i; cin >> i; i--;
  360. if(i >= branch.size() || i < 0)
  361. cout << "Incorrect number of element, please try again\n";
  362. else
  363. {
  364. string type = branch[i]->get_type();
  365. cout << "Availiable changes: \n";
  366. if(type == "LMP")
  367. {
  368. Lamp* lmp = (dynamic_cast<Lamp*>(branch[i]));
  369. cout << "Internal resistance: now" << lmp->get_r() << " Om\n";
  370. cout << "Type 1 for changing the internal resistance, \n";
  371. cout << " 0 for exit: ";
  372. int answer; cin >> answer;
  373. switch (answer)
  374. {
  375. case 1:
  376. cout << "Enter new value of internal resistance: ";
  377. double r; cin >> r;
  378. lmp->set_r(r);
  379. break;
  380. case 0:
  381. break;
  382. default:
  383. cout << "Incorrect command\n";
  384. break;
  385. }
  386. }
  387. else if(type == "RES")
  388. {
  389. Resistor* res = (dynamic_cast<Resistor*>(branch[i]));
  390. cout << "Resistance: now" << res->get_r() << " Om\n";
  391. cout << "Type 1 for changing the resistance, \n";
  392. cout << " 0 for exit: ";
  393. int answer; cin >> answer;
  394. switch (answer)
  395. {
  396. case 1:
  397. cout << "Enter new value of resistance: ";
  398. double r; cin >> r;
  399. res->set_r(r);
  400. break;
  401. case 0:
  402. break;
  403. default:
  404. cout << "Incorrect command\n";
  405. break;
  406. }
  407. }
  408. else if(type == "APP")
  409. {
  410. Appliance* app = (dynamic_cast<Appliance*>(branch[i]));
  411. cout << "Internal resistance: now" << app->get_r() << " Om\n";
  412. cout << "Required voltage: now " << app->get_req_u() << " V\n";
  413. cout << "Required amperage: now " << app->get_req_i() << " A\n";
  414. cout << "Variation of voltage: now " << app->get_du() << " V\n";
  415. cout << "Variation of amperage: now " << app->get_di() << " A\n";
  416. cout << "Type 1 for changing the internal resistance, \n";
  417. cout << " 2 for changing the required voltage, \n";
  418. cout << " 3 for changing the required amperage, \n";
  419. cout << " 4 for changing the variation of voltage, \n";
  420. cout << " 5 for changing the variation of amperage, \n";
  421. cout << " 0 for exit: ";
  422. int answer; cin >> answer;
  423. double u, i, r;
  424. switch (answer)
  425. {
  426. case 1:
  427. cout << "Enter new value of internal resistance: ";
  428. cin >> r;
  429. app->set_r(r);
  430. break;
  431. case 2:
  432. cout << "Enter new value of required voltage: ";
  433. cin >> u;
  434. app->set_req_u(u);
  435. break;
  436. case 3:
  437. cout << "Enter new value of required amperage: ";
  438. cin >> i;
  439. app->set_req_i(i);
  440. break;
  441. case 4:
  442. cout << "Enter new value of variation of voltage: ";
  443. cin >> u;
  444. app->set_du(u);
  445. break;
  446. case 5:
  447. cout << "Enter new value of variation of amperage: ";
  448. cin >> i;
  449. app->set_di(i);
  450. break;
  451. case 0:
  452. break;
  453. default:
  454. cout << "Incorrect command\n";
  455. break;
  456. }
  457.  
  458. }
  459. else if(type == "CCS")
  460. {
  461. CCS* ccs = (dynamic_cast<CCS*>(branch[i]));
  462. cout << "Internal resistance: now" << ccs->get_r() << " Om\n";
  463. cout << "Electromotive force of the CCS: now " << ccs->get_e() << " V\n";
  464. cout << "Type 1 for changing the internal resistance, \n";
  465. cout << " 2 for changing the electromotive force, \n";
  466. cout << " 0 for exit: ";
  467. int answer; cin >> answer;
  468. switch (answer)
  469. {
  470. case 1:
  471. cout << "Enter new value of internal resistance: ";
  472. double r; cin >> r;
  473. ccs->set_r(r);
  474. break;
  475. case 2:
  476. cout << "Enter new value of electromotive force: ";
  477. double e; cin >> e;
  478. ccs->set_e(e);
  479. break;
  480. case 0:
  481. break;
  482. default:
  483. cout << "Incorrect command\n";
  484. break;
  485. }
  486. }
  487. else if(type == "KEY")
  488. {
  489. Key* key = (dynamic_cast<Key*>(branch[i]));
  490. cout << "State of the key: now ";
  491. if(key->get_state())
  492. cout << "locked\n";
  493. else cout << "unlocked\n";
  494. cout << "Type 1 for changing the key state, 0 for exit: ";
  495. int answer; cin >> answer;
  496.  
  497. switch (answer)
  498. {
  499. case 1:
  500. cout << "Type 1 (or 0) for locking (or unlocking) the key: ";
  501. bool newstate; cin >> newstate;
  502. key->set_state(newstate);
  503. case 0:
  504. break;
  505. default:
  506. cout << "Incorrect command\n";
  507. break;
  508. }
  509. }
  510. else
  511. {
  512. cout << "Coder, you have a great error! Fix it immideately!" << endl;
  513. }
  514. }
  515. }
  516.  
  517. int size()
  518. {
  519. return branch.size();
  520. }
  521.  
  522. bool is_shorted_path()
  523. {
  524. if(branch.size() == 0)
  525. return true;
  526. if(!this->is_locked())
  527. return false;
  528. for(int i = 0; i < branch.size(); i++)
  529. {
  530. if(branch[i]->get_type() != "KEY")
  531. return false;
  532.  
  533. }
  534. return true;
  535. }
  536.  
  537. void print(){
  538. for(int i = 0; i < branch.size(); i++)
  539. branch[i]->print();
  540. }
  541. };
  542.  
  543. class Subchain //please test me, i am not tested
  544. {
  545. protected:
  546. vector<Branch*> subchain;
  547. public:
  548.  
  549. void set_branch(int subchain_number)
  550. {
  551. if(subchain_number == 0 && subchain.size() > 0)
  552. cout << "Sorry, you can't have more than 1 branch in main subchain\n";
  553. else
  554. subchain.push_back(new Branch());
  555. }
  556.  
  557. void set_el(int subchain_number)
  558. {
  559. cout << "There are " << subchain.size() << " branches in subchain\n";
  560. cout << "Please type the number of branch where you want to set the element: ";
  561. int j; cin >> j; j--;
  562. if(j >= 0 && j < subchain.size())
  563. subchain[j]->set_el_f(subchain_number);
  564. else
  565. cout << "Incorrect number of branch\n";
  566. }
  567.  
  568. void change_parameters()
  569. {
  570. cout << "There are " << subchain.size() << " branches in subchain\n";
  571. cout << "Please type the number of branch where you want to\n";
  572. cout << "change parameters of the element: ";
  573. int j; cin >> j; j--;
  574. if(j >= 0 && j < subchain.size())
  575. subchain[j]->change_parameters();
  576. else
  577. cout << "Incorrect number of branch\n";
  578. }
  579.  
  580. void remove_el()
  581. {
  582. cout << "There are " << subchain.size() << " branches in subchain\n";
  583. cout << "Please type the number of branch where you want to delete the element: ";
  584. int j; cin >> j; j--;
  585. if(j >= 0 && j < subchain.size())
  586. subchain[j]->remove_el_f();
  587. else
  588. cout << "Incorrect number of branch\n";
  589. }
  590.  
  591. bool has_shorted_paths()
  592. {
  593. for(int i = 0; i < subchain.size(); i++)
  594. {
  595. if(subchain[i]->is_shorted_path())
  596. return true;
  597. }
  598. return false;
  599. }
  600.  
  601. double get_r_from_to()
  602. {
  603. cout << "Please enter the number of branch where needed elements are: ";
  604. int j; cin >> j; j--;
  605. double res = 0;
  606. if(j >= 0 && j < subchain.size())
  607. {
  608. cout << "Please enter the numbers of first and last elements for calculating\n";
  609. int from, to; cin >> from >> to;
  610. res = subchain[j]->get_r_from_to(from, to);
  611. }
  612. else
  613. cout << "Incorrect number of branch\n";
  614. return res;
  615. }
  616.  
  617. double get_r_branch()
  618. {
  619. cout << "Please enter the number of branch where you want to find resistance value: ";
  620. int j; cin >> j; j--;
  621. double res = 0;
  622. if(j >= 0 && j < subchain.size())
  623. res = subchain[j]->get_r_from_to(1, subchain[j]->size());
  624. else
  625. cout << "Incorrect number of branch\n";
  626. return res;
  627. }
  628.  
  629. double get_r_subchain()
  630. {
  631. double mult = 1.0; //multiplication
  632. double sum = 0.0;
  633. int cnt = 0;
  634. if(this->has_shorted_paths())
  635. return 0;
  636. for(int i = 0; i < subchain.size(); i++)
  637. {
  638. if(subchain[i]->is_locked())
  639. {
  640. double r = subchain[i]->get_r_from_to(1, subchain[i]->size());
  641. mult *= r;
  642. sum += r;
  643. cnt++;
  644. }
  645. }
  646. if(cnt == 0)
  647. return 0;
  648. else if(cnt == 1)
  649. return sum;
  650. else
  651. return mult / sum;
  652. }
  653.  
  654. bool is_locked()
  655. {
  656. bool res = true;
  657. if(!subchain.empty())
  658. {
  659. res = subchain[0]->is_locked();
  660. for(int i = 1; i < subchain.size(); i++)
  661. {
  662. res = res || subchain[i]->is_locked();
  663. }
  664. }
  665. return res;
  666. }
  667.  
  668. void remove_branch()
  669. {
  670. cout << "There are " << subchain.size() << " branches in subchain\n";
  671. cout << "Please enter the number of branch you want to remove: ";
  672. int j; cin >> j; j--;
  673. if(j >= 0 && j < subchain.size())
  674. subchain.erase(subchain.begin() + j);
  675. else
  676. cout << "Incorrect number of branch\n";
  677. }
  678.  
  679. int size()
  680. {
  681. return subchain.size();
  682. }
  683.  
  684. void print()
  685. {
  686. for(int i = 0; i < subchain.size(); i++)
  687. {
  688. cout << "Branch " << i + 1 << endl;
  689. subchain[i]->print();
  690. cout << endl;
  691. }
  692. }
  693. };
  694.  
  695. class Chain
  696. {
  697. protected:
  698. vector<Subchain*> chain;
  699. public:
  700.  
  701. void set()
  702. {
  703. cout << "Type 0 to exit\n";
  704. cout << "Type 1 to set a new subchain\n";
  705. cout << "Type 2 to set a new branch\n";
  706. cout << "Type 3 to set a new element\n";
  707. int n; cin >> n;
  708. if(n == 1) chain.push_back(new Subchain());
  709. else
  710. if(n == 2 || n == 3)
  711. {
  712. cout << "Please enter the number of subchain where you want to set new ";
  713. if(n == 2) cout << "branch: ";
  714. if(n == 3) cout << "element: ";
  715. int i; cin >> i; i--;
  716. if(i >= 0 && i < chain.size())
  717. {
  718. if(n == 2) chain[i]->set_branch(i); //
  719. if(n == 3) chain[i]->set_el(i);
  720. }
  721. else
  722. cout << "Incorrect number of subchain\n";
  723. }
  724. }
  725.  
  726. /*void set_subchain()
  727. {
  728. chain.push_back(new Subchain());
  729. }
  730.  
  731. void set_branch()
  732. {
  733. cout << "Please enter the number of subchain where you want to set new branch: ";
  734. int i; cin >> i; i--;
  735. if(i >= 0 && i < chain.size())
  736. chain[i]->set_branch();
  737. else
  738. cout << "Incorrect number of subchain\n";
  739. }
  740.  
  741. void set_el()
  742. {
  743. cout << "Please enter the number of subchain where you want to set new element: ";
  744. int i; cin >> i; i--;
  745. if(i >= 0 && i < chain.size())
  746. chain[i]->set_el(i);
  747. else
  748. cout << "Incorrect number of subchain\n";
  749. }*/
  750.  
  751. //void remove_el()
  752. //{
  753. // cout << "Please enter the number of chain where you want to remove the element: ";
  754. // int i; cin >> i; i--;
  755. // if(i >= 0 && i < chain.size())
  756. // chain[i]->remove_el();
  757. // else
  758. // cout << "Incorrect number of chain\n";
  759. //}
  760.  
  761. //void remove_branch()
  762. //{
  763. // cout << "Please enter the number of chain where you want to remove the branch: ";
  764. // int i; cin >> i; i--;
  765. // if(i >= 0 && i < chain.size())
  766. // chain[i]->remove_branch();
  767. // else
  768. // cout << "Incorrect number of chain\n";
  769. //}
  770.  
  771. //void remove_chain()
  772. //{
  773. // cout << "Please enter the number of chain you want to remove: ";
  774. // int i; cin >> i; i--;
  775. // if(i >= 0 && i < chain.size())
  776. // chain.erase(chain.begin() + i);
  777. // else
  778. // cout << "Incorrect number of chain\n";
  779. //}
  780.  
  781. void remove()
  782. {
  783. map<int, pair<string, string>> m;
  784. m[0] = make_pair("exit", "error");
  785. m[1] = make_pair("element",
  786. "Please enter the number of subchain where you want to remove the element: ");
  787. m[2] = make_pair("branch",
  788. "Please enter the number of subchain where you want to remove the branch: ");
  789. m[3] = make_pair("subchain",
  790. "Please enter the number of subchain you want to remove: ");
  791. for(int i = 0; i < 4; i++)
  792. cout << "Type " << i << " to remove the " << m[i].first << endl;
  793. int n; cin >> n;
  794. if(n > 0 && n < 4)
  795. {
  796. cout << m[n].second;
  797. int i; cin >> i; i--;
  798. if(i >= 0 && i < chain.size())
  799. {
  800. if(n == 1) chain[i]->remove_el();
  801. else if(n == 2) chain[i]->remove_branch();
  802. else if(n == 3) chain.erase(chain.begin() + i);
  803. }
  804. else
  805. cout << "Incorrect number of subchain\n";
  806. }
  807. }
  808.  
  809. void change_parameters()
  810. {
  811. cout << "Please enter the number of subchain where you want to\n";
  812. cout << "change paramaters of the element: ";
  813. int i; cin >> i; i--;
  814. if(i >= 0 && i < chain.size())
  815. chain[i]->change_parameters();
  816. else
  817. cout << "Incorrect number of subchain\n";
  818. }
  819.  
  820. bool is_locked()
  821. {
  822. bool res = true;
  823. for(int i = 0; i < chain.size(); i++)
  824. {
  825. res = res && chain[i]->is_locked();
  826. }
  827. return res;
  828. }
  829.  
  830. double get_r_chain()
  831. {
  832. double r = 0.0;
  833. if(this->is_locked())
  834. {
  835. for(int i = 0; i < chain.size(); i++)
  836. r += chain[i]->get_r_subchain();
  837. }
  838. else
  839. cout << "Chain is unlocked\n";
  840. return r;
  841. }
  842.  
  843. double get_r_subchain()
  844. {
  845. cout << "Please enter the number of subchain which resistance you need: ";
  846. int i; cin >> i; i--;
  847. double r = 0;
  848. if(i >= 0 && i < chain.size())
  849. r = chain[i]->get_r_subchain();
  850. else
  851. cout << "Incorrect number of subchain\n";
  852. return r;
  853. }
  854.  
  855. double get_r_branch()
  856. {
  857. cout << "Please enter the number of subchain where needed branch is: ";
  858. int i; cin >> i; i--;
  859. double r = 0;
  860. if(i >= 0 && i < chain.size())
  861. r = chain[i]->get_r_branch();
  862. else
  863. cout << "Incorrect number of subchain\n";
  864. return r;
  865. }
  866.  
  867. double get_r_from_to()
  868. {
  869. cout << "Please enter the number of subchain where needed elements are: ";
  870. int i; cin >> i; i--;
  871. double r = 0;
  872. if(i >= 0 && i < chain.size())
  873. r = chain[i]->get_r_from_to();
  874. else
  875. cout << "Incorrect number of subchain\n";
  876. return r;
  877. }
  878.  
  879. void print()
  880. {
  881. for(int i = 0; i < chain.size(); i++)
  882. {
  883. cout << "Subchain " << i + 1 << endl;
  884. chain[i]->print();
  885. }
  886. }
  887.  
  888. double get_i()
  889. {
  890. cout << "Type the coordinates: number of subchain, \n";
  891. cout << "number of branch and the number of object: ";
  892. int subch, br, obj;
  893. cin >> subch >> br >> obj;
  894. subch--; br--; obj--;
  895. if(subch >= 0 && subch < chain.size())
  896. {
  897. if(br >= 0 && br < chain[subch]->size())
  898. {
  899. if(obj >= 0 && obj < chain[subch][br].size())
  900. {
  901. cout << "Code here, honey\n";
  902. }
  903. else
  904. cout << "Incorrect number of object\n";
  905. }
  906. else
  907. cout << "Incorrect number of branch\n";
  908. }
  909. else
  910. cout << "Incorrect number of subchain\n";
  911. return 0;
  912. }
  913. };
  914.  
  915. int main()
  916. {
  917. //#ifdef _DEBUG
  918. // freopen("in.txt", "r", stdin);
  919. // freopen("out.txt", "w", stdout);
  920. //#endif
  921.  
  922. Chain* chain = new Chain();
  923.  
  924. int n = 1;
  925. while(n != 26)
  926. {
  927. cout << "1 - set\n";
  928. cout << "2 - is_locked\n";
  929. cout << "3 - remove\n";
  930. cout << "4 - change_parameters\n";
  931. cout << "5 - print\n";
  932. cout << "6 - get_r_chain\n";
  933. cout << "7 - get_r_subchain\n";
  934. cout << "8 - get_r_branch\n";
  935. cout << "9 - get_r_from_to1\n";
  936. cout << "10 - get_i\n";
  937. cin >> n;
  938.  
  939. switch (n)
  940. {
  941.  
  942. case 1:
  943. chain->set();
  944. break;
  945. case 2:
  946. cout << chain->is_locked() << endl;
  947. break;
  948. case 3:
  949. chain->remove();
  950. break;
  951. case 4:
  952. chain->change_parameters();
  953. break;
  954. case 5:
  955. chain->print();
  956. break;
  957. case 6:
  958. cout << chain->get_r_chain() << endl;
  959. break;
  960. case 7:
  961. cout << chain->get_r_subchain() << endl;
  962. break;
  963. case 8:
  964. cout << chain->get_r_branch() << endl;
  965. break;
  966. case 9:
  967. cout << chain->get_r_from_to() << endl;
  968. break;
  969. case 10:
  970. cout << chain->get_i() << endl;
  971. break;
  972. default:
  973. break;
  974.  
  975. }
  976. }
  977. cout << "compilation completed\n";
  978. system("pause");
  979. return 0;
  980. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement