Advertisement
Guest User

zapocet

a guest
Dec 11th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 25.00 KB | None | 0 0
  1. /*
  2. Meno a priezvisko:
  3.  
  4. POKYNY:
  5. (1)  Subor premenujte na Priezvisko_Meno_ID_pisomka2.cpp (pouzite vase udaje bez diakritiky).
  6. (2)  Implementujte funkcie, metody, konstruktory a operatory tak, aby splnali popis (pri ich deklaraciach).
  7. (3)  Cela implementacia musi byt v tomto jednom subore.
  8. (4)  Odovzdajte len tento (spravne premenovany) zdrojovy subor.
  9. (5)  Program musi byt kompilovatelny.
  10. (6)  Globalne a staticke premenne su zakazane.
  11. (7)  V ziadnom pripade nemente deklaracie funkcii, ktore mate za ulohu naprogramovat
  12.      (nemente nazvy, navratove hodnoty ani typ a pocet parametrov v zadanych funkciach).
  13.      Nemente implementacie zadanych datovych typov, ani implementacie hotovych pomocnych funkcii
  14.      (ak nie je v zadani ulohy uvedene inak).
  15. (8)  V pripade potreby mozete kod doplnit o dalsie pomocne funkcie alebo struktury.
  16. (9)  Vase riesenie otestujte (vo funkcii 'main' a pomocou doplnenych pomocnych funkcii alebo struktur).
  17.      Testovaci kod ale nebude hodnoteny.
  18. (10) Funkcia 'main' musi byt v zdrojovom kode posledna.
  19. */
  20.  
  21. #include <iostream>
  22. #include <iomanip>
  23. #include <vector>
  24. #include <list>
  25. #include <algorithm>
  26. #include <cctype>
  27. #include <string>
  28.  
  29. using namespace std;
  30.  
  31. //-------------------------------------------------------------------------------------------------
  32. // 1. ULOHA (3 body)
  33. //-------------------------------------------------------------------------------------------------
  34. /*
  35.     Do triedy 'Rectangle' doplnte:
  36.  
  37.     a)  metodu 'getArea', ktora vrati obsah obdlznika
  38.         Testovaci kod pre tuto ulohu musi byt kompilovatelny. Odkomentujte ho.
  39.  
  40.     b)  kopirovaci konstruktor,
  41.         ktory v novovytvorenom objekte nastavi sirku aj vysku o 1 vacsiu ako su v objekte, ktoreho kopia sa vytvara.
  42.  
  43.     c)  operator porovnania ('operator==')
  44.         Dva objekty triedy 'Rectangle' su rovnake, ak maju rovnake sirky a rovnake vysky.
  45.         Mozete ho implementova ako clensky, alebo globalny.
  46.         Testovaci kod pre tuto ulohu musi byt kompilovatelny. Odkomentujte ho.
  47.  
  48.     Poznamka: atributy su verejne len kvoli testovaciemu kodu.
  49. */
  50. class Rectangle {
  51. public:
  52.     int width; // sirka obdlznika
  53.     int height; // vyska obdlznika
  54.  
  55.     Rectangle(int width, int height) : width(width) , height(height) {
  56.     }
  57.  
  58.     // TODO 1a), 1b), 1c)
  59.     //double getArea(){}
  60.     double getArea(){
  61.         return (double)width * (double)height;
  62.     }
  63.  
  64.     Rectangle(const Rectangle &x) { width = x.width + 1; height= x.height + 1; }
  65.  
  66. };
  67.  
  68. //-------------------------------------------------------------------------------------------------
  69. // 2. ULOHA (1 bod)
  70. //-------------------------------------------------------------------------------------------------
  71. /*
  72.     Implementujte funkciu 'transformToUpper' tak, aby skonvertovala vsetky pismena vo vektore 'text' na velke.
  73.     Vektor 'text' moze obsahovat lubovolne znaky, nie len pismena.
  74.  
  75.     Odporucanie: pouzite 'std::transform' a 'toUpper'.
  76. */
  77.  
  78. // pomocna funkcia
  79. int toUpper(unsigned char c) noexcept {
  80.     return std::toupper(c);
  81. }
  82.  
  83. void transformToUpper(vector<char> & text) noexcept {
  84.     for (int i = 0; i < text.size(); i++)
  85.     {
  86.         text[i] = toUpper(text[i]);
  87.     }
  88. }
  89.  
  90. //-------------------------------------------------------------------------------------------------
  91. // 3. ULOHA (1 bod)
  92. //-------------------------------------------------------------------------------------------------
  93. /*
  94.     Funkcia 'divide' vykona celociselne delenie a vrati vysledok.
  95.  
  96.     Doplnte implementaciu funkcie 'divide' tak, aby v pripade delenia nulou, vyhodila vynimku typu 'DivisionByZeroException'.
  97.     Poznamka: funkcia vynimku vyhodi, ale nezachytava.
  98.  
  99.     PARAMETRE:
  100.         [in] divident - delenec
  101.         [in] divisor - delitel
  102.  
  103.     RETURN:
  104.         Podiel (divident/divisor)
  105.  
  106.     EXCEPTION:
  107.         Ak je 'divisor' (delitel) nula, tak vyhodi vynimku typu 'DivisionByZeroException'.
  108.  
  109.     Odkomentujte testovaci kod.
  110. */
  111.  
  112. class DivisionByZeroException {
  113.    
  114. };
  115.  
  116. int divide(int divident, int divisor) {
  117.     if (divisor == 0)
  118.     {
  119.         throw DivisionByZeroException();
  120.     }
  121.     else
  122.     {
  123.         int podiel = 0;
  124.         podiel = divident / divisor;
  125.         return podiel;
  126.     }
  127.     //return divident / divisor;
  128. }
  129.  
  130. //-------------------------------------------------------------------------------------------------
  131. // 4. ULOHA ( 2 body)
  132. //-------------------------------------------------------------------------------------------------
  133.  
  134. // Datove typy pre 4. a 5. ulohu
  135.  
  136. // Uzol binarneho vyhladavacieho stromu
  137. struct Node {
  138.     int value; // hodnota uzla
  139.     Node *left; // mensie prvky
  140.     Node *right; // vacsie prvky
  141. };
  142.  
  143. // Strom
  144. struct Tree {
  145.     Node *root; // koren stromu
  146. };
  147.  
  148. /*
  149.     Implementujte funkciu 'all', ktora vrati usporiadany zoznam vsetkych prvkov v strome 'tree'.
  150.     Usporiadanie vystupneho zoznamu je od najmensieho prvku po najvacsi.
  151.     Usporiadanie dosiahnite prechodom stromu do hlbky, v poradi inorder.
  152.     Pre kazdy uzol stromu plati, ze v jeho lavom podstrome su prvky s mensou hodnotou, v pravom podstrome prvky s vacsou hodnotou.
  153.  
  154.     Ak sa rozhodnete pre rekurzivnu implementaciu, tak mozete vytvorit a zavolat dalsiu funkciu,
  155.     v ktorej bude prevazna cast implementacie.
  156. */
  157.  
  158. list<int> all(const Tree * tree) {
  159.     /*list<int> zoznam;
  160.     if (tree->root)
  161.     {
  162.         if()
  163.     }*/
  164.     return list<int>(); // tento riadok zmente podla zadania, je tu len kvoli kompilacii
  165. }
  166.  
  167. //-------------------------------------------------------------------------------------------------
  168. // 5. ULOHA ( 3 body)
  169. //-------------------------------------------------------------------------------------------------
  170. /*
  171.     Implementujte funkciu 'add', ktora prida novy uzol s hodnotou 'value' do binarneho vyhladavacieho stromu 'tree'.
  172.     Ak sa 'value' v strome 'tree' uz nachadza, tak funkcia neprida novy uzol (nezmeni strom).
  173.  
  174.     Ak sa rozhodnete pre rekurzivnu implementaciu, tak mozete vytvorit a zavolat dalsiu funkciu,
  175.     v ktorej bude prevazna cast implementacie.
  176. */
  177.  
  178. Node* addNodeRecursive(Node* root, const int value)
  179. {
  180.     if (root)
  181.     {
  182.         if (value < root->value)
  183.         {
  184.             root->left = addNodeRecursive(root->left, value);
  185.         }
  186.         else if (value > root->value)
  187.         {
  188.             root->right = addNodeRecursive(root->right, value);
  189.         }
  190.         else
  191.         {
  192.             throw string{ "Note: uzol sa uz v strome nachadza" };
  193.         }
  194.         return root;
  195.     }
  196.     return new Node{ value, nullptr, nullptr };
  197. }
  198.  
  199. void add(Tree* tree, const int value)
  200. {
  201.     try {
  202.         tree->root = addNodeRecursive(tree->root, value);
  203.     }
  204.     catch (const string& e)
  205.     {
  206.         cout << e << endl;
  207.     }
  208. }
  209.  
  210. //-------------------------------------------------------------------------------------------------
  211. // TESTOVANIE
  212. //-------------------------------------------------------------------------------------------------
  213.  
  214. // pomocny operator na vypis obsahu vektora znakov
  215. ostream& operator<<(ostream& out, const vector<char> vector) {
  216.     for_each(vector.begin(), vector.end(), [&out](const char letter)->void{ out << letter; });
  217.     return out;
  218. }
  219.  
  220. // pomocny operator na vypis obsahu zoznamu cisiel
  221. ostream& operator<<(ostream& out, const list<int> list) {
  222.     for_each(list.begin(), list.end(), [&out](const int number)->void{ out << number << " "; });
  223.     return out;
  224. }
  225.  
  226. // ...........................................................
  227. //          TEST ULOHY 1 a
  228. // ...........................................................
  229. void testUloha1a() {
  230.     cout << "TESTY ULOHA 1a (getArea):" << endl;
  231.     cout << "--------------------------------------------------" << endl;
  232.  
  233.     Rectangle r1(10, 20);
  234.     Rectangle r2(2, 4);
  235.  
  236.     cout << "odkomentujte testovaci kod (a tento vypis vymazte)" << endl << endl;
  237.     cout << "r1.getArea(): " << r1.getArea() << " (spravna hodnota: 200) " << endl;
  238.     cout << "r2.getArea(): " << r2.getArea() << " (spravna hodnota: 8) " << endl << endl;
  239. }
  240.  
  241. // ...........................................................
  242. //          TEST ULOHY 1 b
  243. // ...........................................................
  244. void testUloha1b() {
  245.     cout << "TESTY ULOHA 1b (kopirovaci konstruktor):" << endl;
  246.     cout << "--------------------------------------------------" << endl;
  247.  
  248.     Rectangle r1(10, 20);
  249.     Rectangle r2(2, 4);
  250.  
  251.     Rectangle r3(r1);
  252.     Rectangle r4(r3);
  253.     Rectangle r5(r2);
  254.  
  255.     cout << "r3.width  = " << r3.width  << " (spravna hodnota: 11) " << endl;
  256.     cout << "r3.height = " << r3.height << " (spravna hodnota: 21) " << endl << endl;
  257.  
  258.     cout << "r4.width  = " << r4.width  << " (spravna hodnota: 12) " << endl;
  259.     cout << "r4.height = " << r4.height << " (spravna hodnota: 22) " << endl << endl;
  260.  
  261.     cout << "r5.width  = " << r5.width  << " (spravna hodnota: 3) " << endl;
  262.     cout << "r5.height = " << r5.height << " (spravna hodnota: 5) " << endl << endl;
  263. }
  264.  
  265. // ...........................................................
  266. //          TEST ULOHY 1 c
  267. // ...........................................................
  268. void testUloha1c() {
  269.     cout << "TESTY ULOHA 1c (operator==):" << endl;
  270.     cout << "--------------------------------------------------" << endl;
  271.  
  272.     Rectangle r1(1, 2);
  273.     Rectangle r2(2, 2);
  274.     Rectangle r3(2, 1);
  275.     Rectangle r4(1, 2);
  276.  
  277.     cout << "odkomentujte testovaci kod (a tento vypis vymazte)" << endl << endl;
  278.     //cout << "(r1 == r1): " << setw(5) << left << (r1 == r1) << " (spravna hodnota: true) " << endl;
  279.     //cout << "(r1 == r2): " << setw(5) << left << (r1 == r2) << " (spravna hodnota: false) " << endl;
  280.     //cout << "(r1 == r3): " << setw(5) << left << (r1 == r3) << " (spravna hodnota: false) " << endl;
  281.     //cout << "(r1 == r4): " << setw(5) << left << (r1 == r4) << " (spravna hodnota: true) " << endl << endl;
  282. }
  283.  
  284. // ...........................................................
  285. //          TEST ULOHY 2
  286. // ...........................................................
  287. void testUloha2() {
  288.     cout << "TESTY ULOHA 2 (transformToUpper):" << endl;
  289.     cout << "--------------------------------------------------" << endl;
  290.  
  291.     vector<char> a = {'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'};
  292.     cout << "a) pred volanim transformToUpper: " << a << endl;
  293.     transformToUpper(a);
  294.     cout << "   po zavolani transformToUpper : " << a << endl << endl;
  295.  
  296.     vector<char> b = {'A', '1', 'b', '?', '/', 'C', 'd', 'E'};
  297.     cout << "b) pred volanim transformToUpper: " << b << endl;
  298.     transformToUpper(b);
  299.     cout << "   po zavolani transformToUpper : " << b << endl << endl;
  300.  
  301.     vector<char> c;
  302.     cout << "c) pred volanim transformToUpper: " << c << endl;
  303.     transformToUpper(c);
  304.     cout << "   po zavolani transformToUpper : " << c << endl << endl;
  305. }
  306.  
  307. // ...........................................................
  308. //          TEST ULOHY 3
  309. // ...........................................................
  310. void testUloha3() {
  311.     cout << "TESTY ULOHA 3 (divide):" << endl;
  312.     cout << "--------------------------------------------------" << endl;
  313.  
  314.     cout << "odkomentujte testovaci kod (a tento vypis vymazte)" << endl << endl;
  315.  
  316.     cout << "test vratenia spravnej hodnoty: " << endl;
  317.     cout << "  divide( 12,   5): " << setw(2) << right << divide(12,    5) << " (spravna hodnota:  2)" << endl;
  318.     cout << "  divide(100, -20): " << setw(2) << right << divide(100, -20) << " (spravna hodnota: -5)" << endl << endl;
  319.  
  320.     cout << "test vyhodenia vynimky: " << endl;
  321.     try {
  322.         divide(10, 0);
  323.         cout << "  FAILED: volanie 'divide(10, 0)' nevyhodilo vynimku" << endl << endl;
  324.     }
  325.     catch(const DivisionByZeroException& ) {
  326.         cout << "  PASSED: volanie 'divide(10, 0)' vyhodilo spravny typ vynimky" << endl << endl;
  327.     }
  328.     catch(...) {
  329.         cout << "  FAILED: volanie 'divide(10, 0)' vyhodilo nespravny typ vynimky" << endl << endl;
  330.     }
  331. }
  332.  
  333. // ...........................................................
  334. //          TEST ULOHY 4
  335. // ...........................................................
  336.  
  337. Tree* createTreeA() {
  338.     return new Tree{nullptr};
  339. }
  340.  
  341. Tree* createTreeB() {
  342.     return new Tree{
  343.             new Node { 10,
  344.                        nullptr,
  345.                        nullptr
  346.             }
  347.     };
  348. }
  349.  
  350. Tree* createTreeC() {
  351.     return new Tree{
  352.             new Node { 10,
  353.                        new Node { 5,
  354.                                 nullptr,
  355.                                 nullptr
  356.                        },
  357.                        nullptr
  358.             }
  359.     };
  360. }
  361.  
  362. Tree* createTreeD() {
  363.     return new Tree{
  364.             new Node { 10,
  365.                        nullptr,
  366.                        new Node { 15,
  367.                                 nullptr,
  368.                                 nullptr
  369.                        }
  370.             }
  371.     };
  372. }
  373.  
  374. Tree* createTreeE() {
  375.     return new Tree{
  376.             new Node { 10,
  377.                        new Node { 5,
  378.                                 nullptr,
  379.                                 nullptr
  380.                        },
  381.                        new Node{ 15,
  382.                                 nullptr,
  383.                                 nullptr
  384.                        }
  385.             }
  386.     };
  387. }
  388.  
  389. Tree* createTreeF() {
  390.     return new Tree{
  391.             new Node { 10,
  392.                        new Node{ 5,
  393.                                  new Node { 2,
  394.                                             nullptr,
  395.                                             nullptr
  396.                                  },
  397.                                  new Node { 8,
  398.                                             nullptr,
  399.                                             nullptr
  400.                                  }
  401.                        },
  402.                        new Node{ 15,
  403.                                  new Node { 12,
  404.                                             nullptr,
  405.                                             nullptr
  406.                                  },
  407.                                  new Node { 20,
  408.                                             nullptr,
  409.                                             nullptr
  410.                                  }
  411.                        }
  412.             }
  413.     };
  414. }
  415.  
  416. Tree* createTreeG() {
  417.     return new Tree{
  418.             new Node { 10,
  419.                        new Node{ 5,
  420.                                  new Node { 2,
  421.                                             new Node { 1,
  422.                                                        nullptr,
  423.                                                        nullptr
  424.                                             },
  425.                                             new Node { 3,
  426.                                                        nullptr,
  427.                                                        nullptr
  428.                                             }
  429.                                  },
  430.                                  new Node { 8,
  431.                                             new Node { 7,
  432.                                                        nullptr,
  433.                                                        nullptr
  434.                                             },
  435.                                             new Node { 9,
  436.                                                        nullptr,
  437.                                                        nullptr
  438.                                             }
  439.                                  }
  440.                        },
  441.                        new Node{ 15,
  442.                                  new Node { 12,
  443.                                             nullptr,
  444.                                             nullptr
  445.                                  },
  446.                                  new Node { 20,
  447.                                             new Node { 18,
  448.                                                        nullptr,
  449.                                                        nullptr
  450.                                             },
  451.                                             new Node { 25,
  452.                                                        nullptr,
  453.                                                        nullptr
  454.                                             }
  455.                                  }
  456.                        }
  457.             }
  458.     };
  459. }
  460.  
  461. Tree* createTreeH() {
  462.     return new Tree{
  463.             new Node { 10,
  464.                        new Node{ 5,
  465.                                  new Node { 2,
  466.                                             new Node { 1,
  467.                                                        nullptr,
  468.                                                        nullptr
  469.                                             },
  470.                                             new Node { 3,
  471.                                                        nullptr,
  472.                                                        new Node { 4,
  473.                                                                   nullptr,
  474.                                                                   nullptr
  475.                                                        }
  476.                                             }
  477.                                  },
  478.                                  new Node { 8,
  479.                                             new Node { 7,
  480.                                                        nullptr,
  481.                                                        nullptr
  482.                                             },
  483.                                             new Node { 9,
  484.                                                        nullptr,
  485.                                                        nullptr
  486.                                             }
  487.                                  }
  488.                        },
  489.                        new Node{ 15,
  490.                                  new Node { 12,
  491.                                             nullptr,
  492.                                             nullptr
  493.                                  },
  494.                                  new Node { 20,
  495.                                             new Node { 18,
  496.                                                        new Node { 17,
  497.                                                                   nullptr,
  498.                                                                   nullptr
  499.                                                        },
  500.                                                        nullptr
  501.                                             },
  502.                                             new Node { 25,
  503.                                                        nullptr,
  504.                                                        nullptr
  505.                                             }
  506.                                  }
  507.                        }
  508.             }
  509.     };
  510. }
  511.  
  512. void testUloha4() {
  513.     cout << "TESTY ULOHA 4 (all):" << endl;
  514.     cout << "--------------------------------------------------" << endl;
  515.  
  516.     const Tree *treeA = createTreeA();
  517.     const list<int> listA = all(treeA);
  518.     cout << "a) Vas vystup:     " << listA << endl;
  519.     cout << "   Spravny vystup: " << endl << endl;
  520.  
  521.     const Tree *treeB = createTreeB();
  522.     const list<int> listB = all(treeB);
  523.     cout << "b) Vas vystup:     " << listB << endl;
  524.     cout << "   Spravny vystup: 10" << endl << endl;
  525.  
  526.     const Tree *treeC = createTreeC();
  527.     const list<int> listC = all(treeC);
  528.     cout << "c) Vas vystup:     " << listC << endl;
  529.     cout << "   Spravny vystup: 5 10" << endl << endl;
  530.  
  531.     const Tree *treeD = createTreeD();
  532.     const list<int> listD = all(treeD);
  533.     cout << "d) Vas vystup:     " << listD << endl;
  534.     cout << "   Spravny vystup: 10 15" << endl << endl;
  535.  
  536.     const Tree *treeE = createTreeE();
  537.     const list<int> listE = all(treeE);
  538.     cout << "e) Vas vystup:     " << listE << endl;
  539.     cout << "   Spravny vystup: 5 10 15" << endl << endl;
  540.  
  541.     const Tree *treeF = createTreeF();
  542.     const list<int> listF = all(treeF);
  543.     cout << "f) Vas vystup:     " << listF << endl;
  544.     cout << "   Spravny vystup: 2 5 8 10 12 15 20" << endl << endl;
  545.  
  546.     const Tree *treeG = createTreeG();
  547.     const list<int> listG = all(treeG);
  548.     cout << "g) Vas vystup:     " << listG << endl;
  549.     cout << "   Spravny vystup: 1 2 3 5 7 8 9 10 12 15 18 20 25" << endl << endl;
  550.  
  551.     const Tree *treeH = createTreeH();
  552.     const list<int> listH = all(treeH);
  553.     cout << "h) Vas vystup:     " << listH << endl;
  554.     cout << "   Spravny vystup: 1 2 3 4 5 7 8 9 10 12 15 17 18 20 25" << endl << endl;
  555. }
  556.  
  557. // ...........................................................
  558. //          TEST ULOHY 5
  559. // ...........................................................
  560.  
  561. string testLeaf(const Node *node, const int value) {
  562.     if(node == nullptr) {
  563.         return "FAILED: uzol neexistuje";
  564.     }
  565.     else if(node->value != value) {
  566.         return "FAILED: chybna hodnota uzla";
  567.     }
  568.     else if(node->left != nullptr) {
  569.         return "FAILED: left nie je nullptr";
  570.     }
  571.     else if(node->right != nullptr) {
  572.         return "FAILED: right nie je nullptr";
  573.     }
  574.     else {
  575.         return "PASSED: uzol je listom so spravnou hodnotou";
  576.     }
  577. }
  578.  
  579. void testUloha5() {
  580.     cout << "TESTY ULOHA 5 (add):" << endl;
  581.     cout << "--------------------------------------------------" << endl;
  582.  
  583.     Tree *treeA = createTreeA();
  584.     add(treeA, 10);
  585.     cout << "treeA->root                " << testLeaf(treeA->root, 10) << endl;
  586.  
  587.     Tree *treeB1 = createTreeB();
  588.     add(treeB1, 5);
  589.     cout << "treeB1->root->left         " << testLeaf(treeB1->root->left, 5) << endl;
  590.  
  591.     Tree *treeB2 = createTreeB();
  592.     add(treeB2, 15);
  593.     cout << "treeB2->root->right        " << testLeaf(treeB2->root->right, 15) << endl;
  594.  
  595.     Tree *treeB3 = createTreeB();
  596.     add(treeB3, 10);
  597.     cout << "treeB3->root               " << testLeaf(treeB3->root, 10) << endl;
  598.  
  599.     Tree *treeC1 = createTreeC();
  600.     add(treeC1, 15);
  601.     cout << "treeC1->root->right        " << testLeaf(treeC1->root->right, 15) << endl;
  602.  
  603.     Tree *treeD1 = createTreeD();
  604.     add(treeD1, 5);
  605.     cout << "treeD1->root->left         " << testLeaf(treeD1->root->left, 5) << endl;
  606.  
  607.     Tree *treeC2 = createTreeC();
  608.     add(treeC2, 2);
  609.     cout << "treeC2->root->left->left   " << testLeaf(treeC2->root->left->left, 2) << endl;
  610.  
  611.     Tree *treeD2 = createTreeD();
  612.     add(treeD2, 20);
  613.     cout << "treeD2->root->right->right " << testLeaf(treeD2->root->right->right, 20) << endl;
  614.  
  615.     Tree *treeE1 = createTreeE();
  616.     add(treeE1, 2);
  617.     cout << "treeE1->root->left->left   " << testLeaf(treeE1->root->left->left, 2) << endl;
  618.  
  619.     Tree *treeE2 = createTreeE();
  620.     add(treeE2, 8);
  621.     cout << "treeE2->root->left->right  " << testLeaf(treeE2->root->left->right, 8) << endl;
  622.  
  623.     Tree *treeE3 = createTreeE();
  624.     add(treeE3, 12);
  625.     cout << "treeE3->root->right->left  " << testLeaf(treeE3->root->right->left, 12) << endl;
  626.  
  627.     Tree *treeE4 = createTreeE();
  628.     add(treeE4, 20);
  629.     cout << "treeE4->root->right->right " << testLeaf(treeE4->root->right->right, 20) << endl;
  630.  
  631.     Tree *treeE5 = createTreeE();
  632.     add(treeE5, 10);
  633.     cout << "treeE5->root               " << (treeE5->root->value == 10 ? "PASSED" : "FAILED: chybna hodnota") << endl;
  634.     cout << "treeE5->root->left         " << testLeaf(treeE5->root->left, 5) << endl;
  635.     cout << "treeE5->root->right        " << testLeaf(treeE5->root->right, 15) << endl;
  636.  
  637.     Tree *treeE6 = createTreeE();
  638.     add(treeE6, 5);
  639.     cout << "treeE6->root               " << (treeE6->root->value == 10 ? "PASSED" : "FAILED: chybna hodnota") << endl;
  640.     cout << "treeE6->root->left         " << testLeaf(treeE6->root->left, 5) << endl;
  641.     cout << "treeE6->root->right        " << testLeaf(treeE6->root->right, 15) << endl;
  642.  
  643.     Tree *treeE7 = createTreeE();
  644.     add(treeE7, 15);
  645.     cout << "treeE7->root               " << (treeE7->root->value == 10 ? "PASSED" : "FAILED: chybna hodnota") << endl;
  646.     cout << "treeE7->root->left         " << testLeaf(treeE7->root->left, 5) << endl;
  647.     cout << "treeE7->root->right        " << testLeaf(treeE7->root->right, 15) << endl;
  648.  
  649.     Tree *treeG1 = createTreeG();
  650.     add(treeG1, 0);
  651.     cout << "treeG1->root->left->left->left->left" << endl << "    " << testLeaf(treeG1->root->left->left->left->left, 0) << endl;
  652.  
  653.     Tree *treeG2 = createTreeG();
  654.     add(treeG2, 4);
  655.     cout << "treeG2->root->left->left->right->right " << endl << "    " << testLeaf(treeG2->root->left->left->right->right, 4) << endl;
  656.  
  657.     Tree *treeG3 = createTreeG();
  658.     add(treeG3, 17);
  659.     cout << "treeG3->root->right->right->left->left " << endl << "    " << testLeaf(treeG3->root->right->right->left->left, 17) << endl;
  660.  
  661.     Tree *treeG4 = createTreeG();
  662.     add(treeG4, 30);
  663.     cout << "treeG4->root->right->right->right->right " << endl << "    " << testLeaf(treeG4->root->right->right->right->right, 30) << endl;
  664.  
  665.     Tree *treeG5 = createTreeG();
  666.     add(treeG5, 18);
  667.     cout << "treeG5->root->right->right->left " << endl << "    " << testLeaf(treeG5->root->right->right->left, 18) << endl;
  668. }
  669.  
  670. // tu mozete doplnit pomocne testovacie funkcie a struktury
  671.  
  672. int main() {
  673.  
  674.     cout << boolalpha; // aby true a false vypisoval ako "true" a "false", nie 1 a 0
  675.  
  676.     testUloha1a();
  677.     testUloha1b();
  678.     testUloha1c();
  679.     testUloha2();
  680.     testUloha3();
  681.     testUloha4();
  682.     testUloha5();
  683.  
  684.     // tu mozete doplnit testovaci kod
  685.  
  686.     return 0;
  687. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement