Guest User

Untitled

a guest
Mar 4th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 59.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <fstream>
  6. #include <algorithm>
  7. #include <sstream>
  8. #include <stdio.h>
  9. #include <ctype.h>
  10. using namespace std;
  11. int betid=1;
  12. int ctoggle=1;
  13. int cflag=0;
  14. class category;
  15. class subcategory;
  16. class event;
  17. class market;
  18. class selection;
  19. class Users;
  20. struct Bethistory;
  21. struct History;
  22. void capitalow(string *str){
  23.     transform(str->begin(), str->end(), str->begin(), ::tolower);  
  24. }
  25. class root{
  26. protected:
  27.     string name;
  28.     string ID;
  29.     int visibility;
  30.     vector <root*> nodes;
  31. public:
  32.  
  33.     root(string n="Location",string id=" "):visibility(1)
  34.     {   name.assign(n);
  35.         if (name.find("Copied-")!=name.npos || name.find("Hidden-")!=name.npos)
  36.             visibility=0;
  37.         ID.assign(id);
  38.     }
  39.     ~root()
  40.     {   for(int i=0;i<nodes.size();i++)
  41.         {   delete nodes[i];
  42.         }
  43.         nodes.clear();
  44.         delete this;
  45.     }
  46.     root* visiblenode(int i)
  47.     {   int l=0,j=0;
  48.         while(l<i && j<nodes.size())
  49.         {   if(nodes[j]->get_visibility())
  50.             {   l++;
  51.             }
  52.             j++;
  53.         }
  54.         return nodes[l];
  55.     }
  56.     virtual string get_date()
  57.     {
  58.     }
  59.     virtual string get_time()
  60.     {
  61.     }
  62.     int Size()
  63.     {   return nodes.size();
  64.     }
  65.     root* notvisiblenode(int i)
  66.     {   return nodes[i];
  67.     }
  68.     int get_visibility()
  69.     {   return visibility;
  70.     }
  71.     void change_name(string n)
  72.     {   name.replace(name.begin(),name.end(),n);
  73.     }
  74.     virtual void change_visibility()
  75.     {   cout << "You cannot change the visibility of root"<<endl;
  76.     }
  77.     string path()
  78.     {   return ID;
  79.     }
  80.     string get_name()
  81.     {   return name;
  82.     }
  83.     virtual string get_price()
  84.     {
  85.     }
  86.     virtual double get_price2()
  87.     {  
  88.     }
  89.     void vshow()
  90.     {   for(int i=0;i<nodes.size();i++)
  91.         {   if(nodes[i]->get_visibility())
  92.             {   cout<<i+1<<" ";
  93.                 nodes[i]->printext2();
  94.             }
  95.         }
  96.     }
  97.     void show()
  98.     {   for(int i=0;i<nodes.size();i++)
  99.         {   cout<<i+1<<" ";
  100.             nodes[i]->printext();
  101.         }
  102.     }
  103.     virtual void printext()
  104.     {   cout<< name <<endl;
  105.     }
  106.     virtual void printext2()
  107.     {   cout<<name<<endl;
  108.     }
  109.     virtual void push(string choice);
  110.     void readh(root* temp)
  111.     {   nodes.push_back(temp);
  112.     }
  113.     void readh(category* temp);
  114.     virtual void readh(subcategory* temp)
  115.     {
  116.     }
  117.     virtual void readh(event* temp)
  118.     {
  119.     }
  120.     virtual void readh(market* temp)
  121.     {
  122.     }
  123.     virtual void readh(selection* temp)
  124.     {
  125.     }
  126.  
  127.     virtual void copynode(int i)
  128.     {   cflag=1;
  129.         string n;
  130.         n.assign("Copied-");
  131.         n.append(nodes[i]->get_name());
  132.         push(n);
  133.         nodes[nodes.size()-1]->copyn(nodes[i]);
  134.         nodes[nodes.size()-1]->change_visibility();
  135.     }
  136.     virtual void copyn(root* copying)
  137.     {
  138.     }
  139.     virtual string voidd(int i)
  140.     {   root* node;
  141.         node=visiblenode(i);
  142.         return node->path();
  143.     }
  144.     virtual void deletes(int i)
  145.     {   nodes.erase(nodes.begin()+i);
  146.         for(int i=0;i<nodes.size();i++)
  147.         {   nodes[i]->changeid(ID,i+1);
  148.         }
  149.     }
  150.     void changeid(string ID2,int l)
  151.     {   ID.replace(ID.begin(),ID.end(),ID2);    
  152.         ostringstream convert;
  153.         convert <<  l;  
  154.         string temp3=convert.str();  
  155.         ID.insert(ID.size(),temp3);
  156.         ID.insert(ID.end(),'.');
  157.         for(int i=0;i<nodes.size();i++)
  158.         {   nodes[i]->changeid(ID,i+1);
  159.         }
  160.     }
  161.     virtual void write(ofstream& file)
  162.     {   for(int i=0;i<nodes.size();i++)
  163.             nodes[i]->write(file);
  164.     }
  165.     virtual int preplace(Users* current_user,vector <Bethistory*> &bethistory,vector <History*> &history)
  166.     {   return 0;
  167.     }
  168.     virtual int prevoid(Users* current_user,vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid)
  169.     {   return 0;
  170.     }
  171.     virtual int presettle(Users* current_user,vector <Users*> &User,vector <Bethistory*> &bethistory,root* nodeid)
  172.     {   return 0;
  173.     }
  174.     virtual void preprint(Users* current_user);
  175. };
  176.  
  177. class category : public root{
  178. public:
  179.     category(string n,string id):root(n,id)
  180.     {  
  181.     }
  182.     void change_visibility()
  183.     {   visibility=!visibility;
  184.         if(visibility==0 && get_name().find("Copied-")==get_name().npos)
  185.         {   string temp;
  186.             temp=get_name();
  187.             temp.insert(0,"Hidden-");
  188.             change_name(temp);
  189.         }
  190.         else
  191.         {   string temp;
  192.             temp=get_name();
  193.             temp.erase(0,7);
  194.         }
  195.         for(int i=0;i<nodes.size();i++)
  196.         {   nodes[i]->change_visibility();
  197.         }
  198.     }
  199.     void copyn(root* copying);
  200.     void push(string choice);
  201.     void readh(subcategory* temp);
  202.     root* cpush(category* copying,string);
  203.     void write(ofstream& file)
  204.     {  
  205.         file << path() << " " << get_name() << endl;
  206.         for(int i=0;i<nodes.size();i++)
  207.             nodes[i]->write(file);
  208.     }
  209. };
  210.  
  211. class subcategory : public root{
  212. public:
  213.     subcategory(string n=" ",string id=" "):root(n,id)
  214.     {
  215.     }
  216.     void change_visibility()
  217.     {   visibility=!visibility;
  218.         if(visibility==0 && get_name().find("Copied-")==get_name().npos)
  219.         {   string temp;
  220.             temp=get_name();
  221.             temp.insert(0,"Hidden-");
  222.             change_name(temp);
  223.         }
  224.         else
  225.         {   string temp;
  226.             temp=get_name();
  227.             temp.erase(0,7);
  228.         }
  229.         for(int i=0;i<nodes.size();i++)
  230.         {   nodes[i]->change_visibility();
  231.         }
  232.     }
  233.     void push(string choice);
  234.     void copyn(root* copying);
  235.     void readh(event* temp);
  236.     root* cpush(subcategory* copying,string);
  237.     void copynode(int i);
  238.     void write(ofstream& file)
  239.     {   file << path() << " " << get_name() << endl;
  240.         for(int i=0;i<nodes.size();i++)
  241.             nodes[i]->write(file);
  242.     }
  243. };
  244.  
  245. class event : public root{
  246.     string date;
  247.     string time;
  248. public:
  249.     event(string n=" ",string id=" " , string d=" ",string t=" "):root(n,id)
  250.     {   date.assign(d);
  251.         time.assign(t);
  252.     }
  253.     void change_visibility()
  254.     {   visibility=!visibility;
  255.         if(visibility==0 && get_name().find("Copied-")==get_name().npos)
  256.         {   string temp;
  257.             temp=get_name();
  258.             temp.insert(0,"Hidden-");
  259.             change_name(temp);
  260.         }
  261.         else
  262.         {   string temp;
  263.             temp=get_name();
  264.             temp.erase(0,7);
  265.         }
  266.         for(int i=0;i<nodes.size();i++)
  267.         {   nodes[i]->change_visibility();
  268.         }
  269.     }
  270.     string get_date(){
  271.         return date;
  272.     }
  273.     string get_time(){
  274.         return time;
  275.     }
  276.     void printext()
  277.     {   cout<< get_name() <<" - "<<date<<" "<<time <<endl;
  278.     }
  279.     void printext2()
  280.     {   cout<<get_name() <<" - "<<date<<" "<<time <<endl;
  281.     }
  282.     void push(string choice);
  283.     void readh(market* temp);
  284.     void copyn(root* copying);
  285.     void write(ofstream& file)
  286.     {   file << ID << " " << name << "|" << date << "|" << time <<endl;
  287.         for(int i=0;i<nodes.size();i++)
  288.             nodes[i]->write(file);
  289.     }
  290.    
  291.     root* cpush(event* copying,string);
  292. };
  293. void subcategory::copynode(int i)
  294.     {   cflag=1;
  295.         string choice;
  296.         choice.assign("Copied-");
  297.         choice.append(nodes[i]->get_name());
  298.         string NID;
  299.         NID.assign(nodes[i]->path());    
  300.         string date,time;
  301.         date.assign(nodes[i]->get_date());
  302.         time.assign(nodes[i]->get_time());
  303.         root* temp2=new event(choice,NID,date,time);
  304.         nodes.push_back(temp2);
  305.         nodes[nodes.size()-1]->copyn(nodes[i]);
  306.         nodes[nodes.size()-1]->change_visibility();
  307.        
  308.     }
  309. class selection : public root{
  310.     string price;
  311.     double price2;
  312. public:
  313.     selection(string n=" ",string id=" ",string p=" "):root(n,id)
  314.     {   price.assign(p);
  315.         double t1,t2;
  316.         string temp1;
  317.         char *temp2 = new char[price.length() + 1];
  318.         copy(price.begin(),price.end(),temp2);
  319.         char s[2]="/";
  320.         temp1=strtok(temp2,s);
  321.         temp2=strtok(NULL,"\n");
  322.         stringstream buffer(temp1);
  323.         buffer >> t1;
  324.         stringstream buffer2(temp2);
  325.         buffer2 >> t2;
  326.         price2=((double)t1)/((double)t2) +1.0;
  327.     }
  328.     string get_price(){
  329.         return price;
  330.     }
  331.     double get_price2()
  332.     {   return price2;
  333.     }
  334.     void change_visibility()
  335.     {   visibility=!visibility;
  336.         if(visibility==0 && get_name().find("Copied-")==get_name().npos)
  337.         {   string temp;
  338.             temp=get_name();
  339.             temp.insert(0,"Hidden-");
  340.             change_name(temp);
  341.         }
  342.         else
  343.         {   string temp;
  344.             temp=get_name();
  345.             temp.erase(0,7);
  346.         }
  347.         for(int i=0;i<nodes.size();i++)
  348.         {   nodes[i]->change_visibility();
  349.         }
  350.     }
  351.     void copynode(int i)
  352.     {   cout<<"Not available"<<endl;
  353.     }
  354.     void printext()
  355.     {   if(ctoggle==0)
  356.             cout<< name <<"#"<<price<<endl;
  357.         else
  358.             cout<< name <<"#"<<price2<<endl;
  359.     }
  360.     void printext2()
  361.     {   if(ctoggle==0)
  362.             cout<< name <<"#"<<price<<endl;
  363.         else
  364.             cout<< name <<"#"<<price2<<endl;
  365.     }
  366.     void copyn(root* copying);
  367.     void write(ofstream& file)
  368.     {   file << ID << " " << name << '#' << price <<endl;
  369.         for(int i=0;i<nodes.size();i++)
  370.             nodes[i]->write(file);
  371.     }
  372.     root* cpush(selection* copying,string);
  373. };
  374.  
  375. class market : public root{
  376. public:
  377.     market(string n=" ",string id=" "):root(n,id)
  378.     {
  379.     }
  380.     void change_visibility()
  381.     {   visibility=!visibility;
  382.         if(visibility==0 && get_name().find("Copied-")==get_name().npos)
  383.         {   string temp;
  384.             temp=get_name();
  385.             temp.insert(0,"Hidden-");
  386.             change_name(temp);
  387.         }
  388.         else
  389.         {   string temp;
  390.             temp=get_name();
  391.             temp.erase(0,7);
  392.         }
  393.         for(int i=0;i<nodes.size();i++)
  394.         {   nodes[i]->change_visibility();
  395.         }
  396.     }
  397.     void push(string choice);
  398.     void readh(selection* temp);
  399.     root* cpush(market* copying,string);
  400.     void write(ofstream& file)
  401.     {   file << ID << " " << name << endl;
  402.         for(int i=0;i<nodes.size();i++)
  403.             nodes[i]->write(file);
  404.     }
  405.     void copyn(root* copying);
  406.     virtual void copynode(int i)
  407.     {   cflag=1;
  408.         string choice;
  409.         choice.assign("Copied-");
  410.         choice.append(nodes[i]->get_name());
  411.         string NID;
  412.         NID.assign(nodes[i]->path());
  413.         string price;
  414.         price.assign(nodes[i]->get_price());
  415.         root* temp2=new selection(choice,NID,price);
  416.         nodes.push_back(temp2);
  417.         nodes[nodes.size()-1]->copyn(nodes[i]);
  418.         nodes[nodes.size()-1]->change_visibility();
  419.     }
  420.     int preplace(Users* current_user,vector <Bethistory*> &bethistory,vector <History*> &history);
  421.     int prevoid(Users* current_user,vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid);
  422.     int presettle(Users* current_user,vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid);
  423.     void preprint(Users* current_user);
  424. };
  425. void root::readh(category* temp)
  426. {   nodes.push_back(temp);
  427. }
  428. void category::readh(subcategory* temp)
  429. {   nodes.push_back(temp);
  430. }
  431. void subcategory::readh(event* temp)
  432. {   nodes.push_back(temp);
  433. }
  434. void event::readh(market* temp)
  435. {   nodes.push_back(temp);
  436. }
  437. void market::readh(selection* temp)
  438. {   nodes.push_back(temp);
  439. }
  440.  
  441. void category::copyn(root* copying)
  442. {   category* temp=new category(copying->get_name(),path());
  443.     if(cflag==0)
  444.     {   string temp2;
  445.         cpush(temp,temp2);
  446.     }
  447.     else
  448.     {   cflag=0;
  449.     }
  450.     for(int i=0;i<copying->Size();i++)
  451.     {   nodes.push_back(new subcategory());
  452.     }
  453.     for(int i=0;i<copying->Size();i++)
  454.     {   notvisiblenode(i)->copyn(copying->notvisiblenode(i));
  455.     }
  456. }
  457. void subcategory::copyn(root* copying)
  458. {   subcategory* temp=new subcategory(copying->get_name(),copying->path());
  459.     if(cflag==0)
  460.     {   string temp2;
  461.         temp2=copying->path();
  462.         cpush(temp,temp2);
  463.     }
  464.     else
  465.     {   cflag=0;
  466.     }
  467.     for(int i=0;i<copying->Size();i++)
  468.     {   nodes.push_back(new event());
  469.     }
  470.     for(int i=0;i<copying->Size();i++)
  471.     {   notvisiblenode(i)->copyn(copying->notvisiblenode(i));
  472.     }
  473. }
  474. void event::copyn(root* copying)
  475. {   event* temp=new event(copying->get_name(),copying->path(),copying->get_date(),copying->get_time());
  476.     if(cflag==0)
  477.     {   string temp2;
  478.         temp2=copying->path();
  479.         cpush(temp,temp2);
  480.     }
  481.     else
  482.     {   cflag=0;
  483.     }
  484.     for(int i=0;i<copying->Size();i++)
  485.     {   nodes.push_back(new market());
  486.     }
  487.     for(int i=0;i<copying->Size();i++)
  488.     {   notvisiblenode(i)->copyn(copying->notvisiblenode(i));
  489.     }
  490. }
  491. void market::copyn(root* copying)
  492. {   market* temp=new market(copying->get_name(),copying->path());
  493.     if(cflag==0)
  494.     {   string temp2;
  495.         temp2=copying->path();
  496.         cpush(temp,temp2);
  497.     }
  498.     else
  499.     {   cflag=0;
  500.     }
  501.     for(int i=0;i<copying->Size();i++)
  502.     {   nodes.push_back(new selection(" "," ","1/1"));
  503.     }
  504.     for(int i=0;i<copying->Size();i++)
  505.     {   notvisiblenode(i)->copyn(copying->notvisiblenode(i));
  506.     }
  507. }
  508. void selection::copyn(root* copying)
  509. {   selection* temp=new selection(copying->get_name(),copying->path(),copying->get_price());
  510.     if(cflag==0)
  511.     {   string temp2;
  512.         temp2=copying->path();
  513.         cpush(temp,temp2);
  514.     }
  515.     else
  516.     {   cflag=0;
  517.     }
  518. }
  519.  
  520.  
  521. void root::push(string choice)
  522. {   string NID;
  523.     ostringstream convert;
  524.     convert << nodes.size()+1;  
  525.     string temp3=convert.str();  
  526.     NID.append(temp3);
  527.     NID.insert(NID.end(),'.');
  528.     root* temp2=new category(choice,NID);
  529.     nodes.push_back(temp2);
  530. }
  531. void category::push(string choice)
  532. {   string NID;
  533.     NID.assign(ID);    
  534.     ostringstream convert;
  535.     convert << nodes.size()+1;  
  536.     string temp3=convert.str();  
  537.     NID.insert(NID.size(),temp3);
  538.     NID.insert(NID.end(),'.');
  539.     root* temp2=new subcategory(choice,NID);
  540.     nodes.push_back(temp2);    
  541. }
  542. void subcategory::push(string choice)
  543. {   string NID;
  544.     NID.assign(ID);    
  545.     ostringstream convert;
  546.     convert << nodes.size()+1;  
  547.     string temp3=convert.str();  
  548.     NID.insert(NID.size(),temp3);
  549.     NID.insert(NID.end(),'.');
  550.     string date;
  551.     string time;
  552.     cout<<"Dwse hmeromhnia"<<endl;
  553.     getline(cin,date);
  554.     cout<<"Dwse xrono"<<endl;
  555.     getline(cin,time);
  556.     root* temp2=new event(choice,NID,date,time);       
  557.     nodes.push_back(temp2);
  558. }
  559. void event::push(string choice)
  560. {   string NID;
  561.     NID.assign(ID);  
  562.     ostringstream convert;
  563.     convert << nodes.size()+1;  
  564.     string temp3=convert.str();  
  565.     NID.insert(NID.size(),temp3);
  566.     NID.insert(NID.end(),'.');  
  567.     root* temp2=new market(choice,NID);
  568.     nodes.push_back(temp2);
  569. }
  570. void market::push(string choice)
  571. {   string NID;
  572.     NID.assign(ID);  
  573.     ostringstream convert;
  574.     convert << nodes.size()+1;  
  575.     string temp3=convert.str();  
  576.     NID.insert(NID.size(),temp3);
  577.     NID.insert(NID.end(),'.');  
  578.     cout<<"Dwse price se klasma"<<endl;
  579.     string price;
  580.     getline(cin,price);
  581.     root* temp2=new selection(choice,NID,price);
  582.     nodes.push_back(temp2);
  583. }
  584.  
  585.  
  586. root* category::cpush(category* copying,string NID)
  587. {   string choice;
  588.     choice.assign("Copied-");
  589.     choice.append(copying->get_name());
  590.     change_name(choice);
  591.     ID.replace(ID.begin(),ID.end(),NID);   
  592. }
  593. root* subcategory::cpush(subcategory* copying,string NID)
  594. {   string choice;
  595.     choice.assign("Copied-");
  596.     choice.append(copying->get_name());
  597.     change_name(choice);
  598.     ID.replace(ID.begin(),ID.end(),NID);
  599. }
  600. root* event::cpush(event* copying,string NID)
  601. {   string choice;
  602.     choice.assign("Copied-");
  603.     choice.append(copying->get_name());
  604.     change_name(choice);
  605.     date.replace(date.begin(),date.end(),copying->get_date());
  606.     time.replace(time.begin(),time.end(),copying->get_time());
  607.     ID.replace(ID.begin(),ID.end(),NID);
  608. }
  609. root* market::cpush(market* copying,string NID)
  610. {   string choice;
  611.     choice.assign("Copied-");
  612.     choice.append(copying->get_name());
  613.     change_name(choice);
  614.     ID.replace(ID.begin(),ID.end(),NID);
  615. }
  616. root* selection::cpush(selection* copying,string NID)
  617. {   string choice;
  618.     choice.assign("Copied-");
  619.     choice.append(copying->get_name());
  620.     change_name(choice);
  621.     price.replace(price.begin(),price.end(),copying->get_price());
  622.     int t1,t2;
  623.     string temp1;
  624.     char *temp2 = new char[price.length() + 1];
  625.     copy(price.begin(),price.end(),temp2);
  626.     char s[2]="/";
  627.     temp1=strtok(temp2,s);
  628.     temp2=strtok(NULL,"\n");
  629.     stringstream buffer(temp1);
  630.     buffer >> t1;
  631.     stringstream buffer2(temp2);
  632.     buffer2 >> t2;
  633.     price2=(double)t1/(double)t2 +1;
  634.     ID.replace(ID.begin(),ID.end(),NID);
  635. }
  636.  
  637.  
  638. struct History
  639. {   string username;
  640.     string operation;
  641.     string rename;
  642.     string target;
  643.     double   money;
  644. };
  645. struct Bethistory
  646. {   int bet_id;
  647.     int user_id;
  648.     string node_id;
  649.     double stake;
  650.     char result;
  651. };
  652.  
  653. void historyfun(vector<History*> &history,string operation,string target,string rename,string username,double x)
  654. {   history.push_back(new History);
  655.     int i=history.size()-1;
  656.     history[i]->operation.assign(operation);
  657.     history[i]->money=x;
  658.     history[i]->target.assign(target);
  659.     history[i]->rename.assign(rename);
  660.     history[i]->username.assign(username);
  661.      
  662. }
  663.  
  664. void bethistoryfun(vector<Bethistory*> &bethistory,int bet_id,int user_id,string node_id,double stake,char result)
  665. {   bethistory.push_back(new Bethistory);
  666.     int i=bethistory.size()-1;
  667.     bethistory[i]->bet_id=bet_id;
  668.     bethistory[i]->user_id=user_id;
  669.     bethistory[i]->node_id.assign(node_id);
  670.     bethistory[i]->stake=stake;
  671.     bethistory[i]->result=result;
  672. }
  673. class Users
  674. {   int user_id1;
  675.     string username1;
  676.     string fullname1;
  677.     string password1;
  678.     int type1;
  679.     string status1;
  680.     double balance1;
  681.     vector<double> freebets1;
  682.     public:
  683.         int get_id()
  684.         {   return user_id1;
  685.         }
  686.         void change_id(int i)
  687.         {   user_id1=i;
  688.         }
  689.         string get_username()
  690.         {   return username1;
  691.         }
  692.         void change_username(string temp)
  693.         {   username1.replace(username1.begin(),username1.end(),temp);
  694.         }
  695.         string get_password()
  696.         {   return password1;
  697.         }
  698.         void change_password(string temp)
  699.         {   password1.replace(password1.begin(),password1.end(),temp);
  700.         }
  701.         string get_fullname()
  702.         {   return fullname1;
  703.         }
  704.         void change_fullname(string temp)
  705.         {   fullname1.replace(fullname1.begin(),fullname1.end(),temp);
  706.         }
  707.         string get_status()
  708.         {   return status1;
  709.         }
  710.         void change_status(string temp)
  711.         {   status1.replace(status1.begin(),status1.end(),temp);
  712.         }
  713.         int get_type()
  714.         {   return type1;
  715.         }
  716.         void change_type(int i)
  717.         {   type1=i;
  718.         }
  719.         double get_balance()
  720.         {   return balance1;
  721.         }
  722.         void add_balance(double i)
  723.         {   balance1+=i;
  724.         }
  725.         void change_balance(double i)
  726.         {   balance1=i;
  727.         }
  728.         int get_freebets(int i)
  729.         {   return freebets1[i];
  730.         }
  731.         void add_freebets(int i)
  732.         {   freebets1.push_back(i);
  733.         }
  734.         int size_freebets()
  735.         {   return freebets1.size();
  736.         }
  737.         int remove_freebets(int i)
  738.         {   int l=freebets1[i];
  739.             freebets1.erase(freebets1.begin()+i);
  740.             return l;
  741.         }
  742.         virtual void print()
  743.         {  
  744.         }
  745.         virtual void guide(root* &nodeid,string entoli)
  746.         {   int i;
  747.             stringstream buffer(entoli);
  748.             buffer>>i;
  749.             i--;
  750.             if(i<nodeid->Size())
  751.             {   nodeid=nodeid->visiblenode(i);
  752.             }
  753.             else
  754.             {   cout<<"Invalid input"<<endl;
  755.             }
  756.         }
  757.         virtual void exprint()
  758.         {   print();
  759.         }
  760.         virtual void show(root* current_node)
  761.         {   current_node->vshow();
  762.         }
  763.         void home(vector <root*> &path,root* current_node)
  764.         {   for(int i=path.size()-1;i>0;i--)
  765.             {   path.erase(path.begin()+i);
  766.             }
  767.             current_node=path[0];
  768.         }
  769.         void toggle()
  770.         {   ctoggle= !ctoggle;
  771.         }
  772.         virtual void bets(vector<Bethistory*> &bethistory,vector<History*> &history)
  773.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  774.         }
  775.         virtual void freebets(vector<Users*> &User,vector<History*> &history)
  776.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  777.         }
  778.         virtual void account(vector<History*> &history)
  779.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  780.         }
  781.         virtual int save(root* root,vector<Users*> &User,vector<History*> &history,vector <Bethistory*> &bethistory)
  782.         {   return 0;
  783.         }
  784.         virtual int logs(vector<History*> &history)
  785.         {   return 0;
  786.         }
  787.         virtual void users()
  788.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  789.         }
  790.         virtual void Rename(vector<Users*> &User,vector<History*> &history,root* nodeid)
  791.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  792.         }
  793.         virtual void New(root *nodeid)
  794.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  795.         }
  796.         virtual void Copy(root* nodeid)
  797.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  798.         }
  799.         virtual int Delete(root* nodeid)
  800.         {   return 0;
  801.         }
  802.         virtual int view(vector <Users*> &User)
  803.         {   return 0;
  804.         }
  805.         virtual void search(vector <Users*> &User)
  806.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  807.         }
  808.         virtual void place(vector<Bethistory*> &bethistory,vector<History*> &history,string nodeid)
  809.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  810.         }
  811.         virtual void lock(vector<Users*> &User)
  812.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  813.         }
  814.         virtual void password(vector<History*> &history)
  815.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  816.         }
  817.         virtual void deposit (vector<History*> &history)
  818.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  819.         }
  820.         virtual void Void(vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid)
  821.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  822.         }
  823.         virtual void Settle(vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid)
  824.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  825.         }
  826.         virtual void visibility(root* nodeid)
  827.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  828.         }
  829. };
  830.  
  831. class Guest:public Users
  832. {   public:
  833.         void print()
  834.         {   cout<<"Epile3te" << endl << "To ID tou kombou pou epi8umeite na episkefteite" <<endl<<"H(Home),gia epistrofh sthn arxikh o8onh"<<endl<<"T(Toggle) gia enallagh probolhs timwn" << endl<< "X(Exit) gia e3odo apo to susthma"<<endl;
  835.         }
  836. };
  837. class Punter:public Users
  838. {   public:
  839.         void print()
  840.         {   cout<<"Epile3te" << endl << "To ID tou kombou pou epi8umeite na episkefteite" <<endl<<"H(Home),gia epistrofh sthn arxikh o8onh"<<endl<<"T(Toggle) gia enallagh probolhs timwn" << endl<< "X(Exit) gia e3odo apo to susthma"<<endl<<"A(Account),gia diaxeirish twn plhroforiwn tou logariasmou xrhsth"<<endl;
  841.         }
  842.         void exprint()
  843.         {   print();
  844.             cout<<"P(Place),gia enapo8esh stoixhmatos"<<endl;
  845.         }
  846.         void Rename(vector<Users*> &User,vector<History*> &history,root* nodeid)
  847.         {   if(flag==1)
  848.             {   string str;
  849.                 while(1)
  850.                 {   int flag2=0;
  851.                      getline(cin,str);
  852.                     for(int i=0;i<User.size();i++)
  853.                     {   if (!User[i]->get_username().compare(str))
  854.                         {   flag2=1;
  855.                             cout<<"To username xrhshmopoieitai hdh"<<endl;
  856.                             break;
  857.                         }
  858.                     }
  859.                     if(flag2==0)
  860.                         break;
  861.                 }
  862.                 change_username(str);
  863.                 historyfun(history,"Rename","-","-",get_username(),0.0);
  864.             }
  865.             else
  866.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  867.             flag=0;
  868.         }
  869.         void password(vector<History*> &history)
  870.         {   if(flag==1)
  871.             {   string str,str1;
  872.                 while(1)
  873.                 {   cout<< "Dwse ton neo kwdiko"<<endl;
  874.                     getline(cin,str);
  875.                     cout<< "Epanalabe"<<endl;
  876.                     getline(cin,str1);
  877.                     if (!str.compare(str1))
  878.                     {   change_password(str);
  879.                         historyfun(history,"Password","-","-",get_username(),0.0);
  880.                         break;
  881.                     }
  882.                 }
  883.  
  884.             }
  885.             else
  886.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  887.             flag=0;
  888.  
  889.         }
  890.         void bets(vector<Bethistory*> &bethistory,vector<History*> &history)
  891.         {   if(flag==1)
  892.             {   for (int i=0;i<bethistory.size();i++)
  893.                 {   if (bethistory[i]->user_id==get_id())
  894.                     {   cout<<"Bet to "<<bethistory[i]->node_id<< " "<< bethistory[i]->stake<< endl;
  895.  
  896.                     }
  897.                 }
  898.                 historyfun(history,"Bet","-","-",get_username(),0.0);
  899.             }
  900.             else
  901.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  902.  
  903.         }
  904.         void deposit(vector<History*> &history)
  905.         {   if(flag==1)
  906.             {   double x;
  907.                 cin >> x;
  908.                 add_balance(x);
  909.                 cout << "To neo sas poso sto logariasmo sas einai" << get_balance()<<endl;
  910.                 historyfun(history,"Deposit","-","-",get_username(),x);
  911.             }
  912.             else
  913.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  914.             flag=0;
  915.  
  916.         }
  917.         void account(vector<History*> &history)
  918.         {   cout<<"Paixths: " << get_username()<<endl<<"Dia8esimo upoloipo: "<< get_balance()<<endl<<"Dia8esima kouponia:";
  919.             for(int i=0;i<size_freebets();i++)
  920.             {   if(i!=size_freebets())
  921.                     cout<<get_freebets(i)<<",";
  922.                 else
  923.                     cout<<get_freebets(i)<<endl;
  924.             }
  925.             cout<<"Epiloges:"<<endl<<"R(Rename),gia allagh onomatos paikth"<<endl<<"P(Password),gia allagh kwdikou"<<endl<<"B(Bets),gia probolh istorikou stoixhmatwn"<<endl<<"D(Deposit),gia gemisma logariasmou upoloipou"<<endl;
  926.             flag=1;
  927.             historyfun(history,"Account","-","-",get_username(),0.0);
  928.         }
  929.         void place(vector<Bethistory*> &bethistory,vector<History*> &history,string nodeid)
  930.         {   string choice;
  931.             string bet;
  932.             cout<<"Upoloipo portofoliou: "<<get_balance()<<endl;
  933.             cout<<"Dwse id h cancel gia akurwsh"<<endl;
  934.             getline(cin,choice);
  935.             if(choice.compare("cancel"));
  936.             {   stringstream buffer(choice);
  937.                 int i;
  938.                 buffer >> i;
  939.                 i--;
  940.                 ostringstream buffer2;
  941.                 buffer2<<i+1;
  942.                 choice.replace(choice.begin(),choice.end(),buffer2.str());
  943.                 nodeid.append(choice);
  944.                 nodeid.insert(nodeid.end(),'.');
  945.                 char x='a';
  946.                 for(int i=0;i<size_freebets();i++)
  947.                 {   cout<<x++<<"."<<get_freebets(i)<<endl;
  948.                 }
  949.                 cout << "Dwse poso stoixhmatos"<<endl;
  950.                 while (1)
  951.                 {   getline(cin,bet);
  952.                     if(bet[0]>='a' && bet[0]<x)
  953.                     {   int l=bet[0]-'a';
  954.                         bethistoryfun(bethistory,betid++,get_id(),nodeid,get_freebets(l),'-');
  955.                         remove_freebets(l);
  956.                         break;
  957.                     }
  958.                     else if(isdigit(bet[0]))
  959.                     {   double bett=atof( bet.c_str());
  960.                         if(bett>get_balance() && get_balance()==0)
  961.                         {   cout<<"Mhdeniko upoloipo parakalw gemise to portofoli s apo to menou diaxeirhshs"<<endl;
  962.                             break;
  963.                         }
  964.                         else if(bett>get_balance())
  965.                         {   cout<< "Dwse mikrotero poso"<<endl;
  966.                             continue;
  967.                         }
  968.                         else if(bett<=get_balance())
  969.                         {   add_balance(-bett);
  970.                             bethistoryfun(bethistory,betid++,get_id(),nodeid,bett,'-');
  971.                             historyfun(history,"bet",nodeid,"-",get_username(),bett);
  972.                             break;
  973.                         }
  974.                     }
  975.                     else
  976.                     {   cout<<"La8os epilogh"<<endl;
  977.                         break;
  978.                     }
  979.                 }
  980.  
  981.             }
  982.             flag=0;
  983.         }
  984.     private:
  985.         int flag;
  986. };
  987. class Trader:public Users
  988. {   public:
  989.         void bets(vector<Bethistory*> &bethistory,vector<History*> &history)
  990.         {   int l=0;
  991.             cout<< "bet_id | user_id | node_id | stake | result " << endl;
  992.             for (int i=0;i<bethistory.size();i++)
  993.             {   if (l++==20)
  994.                     break;
  995.                 cout << bethistory[i]->bet_id<< '\t' <<bethistory[i]->user_id<< '\t' <<bethistory[i]->node_id<< '\t' <<bethistory[i]->stake<< '\t' <<bethistory[i]->result<<endl;
  996.             }
  997.         }
  998.         void freebets(vector<Users*> &User,vector<History*> &history)
  999.         {   string name;
  1000.             double x;
  1001.             int flag=0,i;
  1002.             while(1)
  1003.             {   cout<<"Dwse onoma xrhsth"<<endl;
  1004.                 getline(cin,name);
  1005.                 for(i=0;i<User.size();i++)
  1006.                 {   if(!User[i]->get_username().compare(name))
  1007.                     {   flag=1;
  1008.                         break;
  1009.                     }
  1010.                 }
  1011.                 if(flag==1)
  1012.                     break;
  1013.  
  1014.             }
  1015.             if(flag==1)
  1016.             {   cout<<"Dwse poso kouponiou"<<endl;
  1017.                 cin >> x;
  1018.                 getline(cin,name);
  1019.                 User[i]->add_freebets(x);
  1020.             }
  1021.  
  1022.         }
  1023.         void Void(vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid);
  1024.         void Settle(vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid);
  1025.         void print()
  1026.         {   cout<<"Epile3te" << endl << "To ID tou kombou pou epi8umeite na episkefteite" <<endl<<"H(Home),gia epistrofh sthn arxikh o8onh"<<endl<<"T(Toggle) gia enallagh probolhs timwn" << endl<< "X(Exit) gia e3odo apo to susthma"<<endl<<"B(Bets),gia emfanish 20 teleutaiwn stoixhmatwn"<<endl<<"F(Freebets),gia apodosh kouponiou se xrhsth"<<endl;
  1027.         }
  1028.         void exprint()
  1029.         {   print();
  1030.             cout<<"V(Void),gia na akurw8ei mia epilogh"<<endl<<"S(Settle),gia dieu8ethsh ths agoras"<<endl;
  1031.         }
  1032.  
  1033. };
  1034. class Director:public Users
  1035. {   public:
  1036.         void guide(root* &nodeid,string entoli)
  1037.         {   int i;
  1038.             stringstream buffer(entoli);
  1039.             buffer>>i;
  1040.             i--;
  1041.             if(i<nodeid->Size())
  1042.             {   nodeid=nodeid->notvisiblenode(i);
  1043.             }
  1044.             else
  1045.             {   cout<<"Invalid input"<<endl;
  1046.             }
  1047.         }
  1048.         void show(root* current_node)
  1049.         {   current_node->show();
  1050.         }
  1051.         void bets(vector<Bethistory*> &bethistory,vector<History*> &history)
  1052.         {   int l=0;
  1053.             cout<< "bet_id | user_id | node_id | stake | result " << endl ;
  1054.             for (int i=0;i<bethistory.size();i++)
  1055.             {   if (l++==20)
  1056.                     break;
  1057.                 cout << bethistory[i]->bet_id<< '\t' <<bethistory[i]->user_id<< '\t' <<bethistory[i]->node_id<< '\t' <<bethistory[i]->stake<< '\t' <<bethistory[i]->result<<endl;
  1058.             }
  1059.             historyfun(history,"Bets","-","-",get_username(),0);
  1060.             flag=0;
  1061.         }
  1062.         void freebets(vector<Users*> &User,vector<History*> &history)
  1063.         {   string name;
  1064.             double x;
  1065.             int flag=0,i;
  1066.             while(1)
  1067.             {   cout<<"Dwse onoma xrhsth"<<endl;
  1068.                 getline(cin,name);
  1069.                 for(i=0;i<User.size();i++)
  1070.                 {   if(!User[i]->get_username().compare(name))
  1071.                     {   flag=1;
  1072.                         break;
  1073.                     }
  1074.                 }
  1075.                 if(flag==1)
  1076.                     break;
  1077.  
  1078.             }
  1079.             if(flag==1)
  1080.             {   cout<<"Dwse poso kouponiou"<<endl;
  1081.                 cin >> x;
  1082.                 getline(cin,name);
  1083.                 User[i]->add_freebets(x);
  1084.             }
  1085.  
  1086.         }
  1087.         int save(root* root,vector<Users*> &User,vector<History*> &history,vector <Bethistory*> &bethistory);
  1088.         int logs(vector<History*> &history)
  1089.         {   int l=0;
  1090.             for (int i=0;i<history.size();i++)
  1091.             {   if (l++==25)
  1092.                     break;
  1093.                 cout<<history[i]->username<<'\t'<<history[i]->operation<<'\t'<<history[i]->target<<'\t'<<history[i]->rename<<'\t'<<history[i]->money<<endl;
  1094.             }
  1095.             flag=0;
  1096.             return 1;
  1097.         }
  1098.         void users()
  1099.         {   cout<<"Epiloges:"<<endl<<"V(View),gia emfanish xrhstwn pinaka xrhstwn"<<endl<<"S(Search),gia anazhthsh xrhsth"<<endl<<"L(Lock,gia enallagh katastashs apokleismou"<<endl;
  1100.             flag=1;
  1101.         }
  1102.         void visibility(root* nodeid)
  1103.         {   nodeid->change_visibility();
  1104.             flag=0;
  1105.         }
  1106.         void Rename(vector<Users*> &User,vector<History*> &history,root* nodeid)
  1107.         {   nodeid->show();
  1108.             string choice;
  1109.             cout<<"Dwse id h cancel/abort gia akurwsh"<<endl;
  1110.             getline(cin,choice);
  1111.             if(isdigit(choice[0]))
  1112.             {   stringstream buffer(choice);
  1113.                 int i;
  1114.                 buffer >> i;
  1115.                 i--;
  1116.                 root* temp=nodeid->notvisiblenode(i);
  1117.                 cout<<"Dwse neo onoma h abort/cancel gia akurwsh"<<endl;
  1118.                 string rename;
  1119.                 getline(cin,rename);
  1120.                 string temp2;
  1121.                 temp2.assign(rename);
  1122.                 capitalow(&temp2);
  1123.                 if(temp2!="cancel"&& temp2!="abort" && temp2!="a" && temp2!="c")
  1124.                 {   temp->change_name(rename);
  1125.                 }
  1126.                 else
  1127.                     cout<<"Procedure aborted"<<endl;
  1128.             }
  1129.             else
  1130.             {   cout<<"Procedure aborted"<<endl;
  1131.             }
  1132.             flag=0;
  1133.         }
  1134.         void New(root *nodeid)
  1135.         {   nodeid->show();
  1136.             cout<<"Dwse neo onoma kombou h cancel/abort gia akurwsh"<<endl;
  1137.             string choice;
  1138.             getline(cin,choice);
  1139.             string temp=choice;
  1140.             capitalow(&temp);
  1141.             if(temp!="cancel"&& temp!="abort" && temp!="a" && temp!="c")
  1142.             {   nodeid->push(choice);      
  1143.             }
  1144.             else
  1145.                 cout<<"Procedure aborted"<<endl;
  1146.             flag=0;
  1147.         }
  1148.         void Copy(root* nodeid)
  1149.         {   cout << "Dwse  ID gia na ginei copy h cancel/abort gia akurwsh"<<endl;
  1150.             string choice;
  1151.             getline(cin,choice);
  1152.             if(isdigit(choice[0]))
  1153.             {   stringstream buffer(choice);
  1154.                 int i;
  1155.                 buffer >> i;
  1156.                 i--;
  1157.                 nodeid->copynode(i);
  1158.             }
  1159.             else
  1160.             {   cout<<"Procedure aborted"<<endl;
  1161.             }
  1162.             flag=0;
  1163.         }
  1164.         int Delete(root* nodeid)
  1165.         {   string choice;
  1166.             cout<<"Id kombou gia diagrafh"<<endl;
  1167.             getline (cin,choice);
  1168.             capitalow(&choice);
  1169.             if(isdigit(choice[0]))
  1170.             {   stringstream buffer(choice);
  1171.                 int i;
  1172.                 buffer >> i;
  1173.                 i--;
  1174.                 string choice2;
  1175.                 cout<<"Eisai sigouros? Y gia nai kai N gia oxi"<<endl;
  1176.                 getline(cin,choice2);
  1177.                 if (choice2[0]=='Y' || choice2[0]=='y')
  1178.                     nodeid->deletes(i);
  1179.                 else
  1180.                     cout<<"Aborted"<<endl;
  1181.             }
  1182.             else
  1183.                 cout<<"Aborted"<<endl;
  1184.             flag=0;
  1185.             return 1;
  1186.         }
  1187.         int view(vector <Users*> &User)
  1188.         {   if (flag==1)
  1189.             {   cout << "user_id | username | fullname | password | type | status | balance | freebets" << endl ;
  1190.                 for (int i=0;i<User.size();i++)
  1191.                 {   cout<< User[i]->get_id()<<'\t'<<User[i]->get_username()<<'\t'<<User[i]->get_fullname()<<'\t'<<User[i]->get_password()<<'\t'<<User[i]->get_type()<<'\t'<<User[i]->get_status()<<'\t'<<User[i]->get_balance()<<'\t';
  1192.                     for (int l=0;l<User[i]->size_freebets();l++)
  1193.                     {   cout<< User[i]->get_freebets(l);
  1194.                         if(l!=User[i]->size_freebets()-1)
  1195.                         {    cout<<",";
  1196.                         }
  1197.                         else
  1198.                         {    cout << endl;
  1199.                         }
  1200.                     }
  1201.                 }
  1202.             }
  1203.             else
  1204.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  1205.             flag=0;
  1206.             return 2;
  1207.         }
  1208.         void search(vector <Users*> &User)
  1209.         {   if (flag==1)
  1210.             {   cout<<"Dwse onoma xrhsth h substring autou"<<endl;
  1211.                 string name;
  1212.                 getline(cin,name);
  1213.                 for(int i=0;i<User.size();i++)
  1214.                 {   if(User[i]->get_username().find(name)!=User[i]->get_username().npos)
  1215.                     {   cout<< User[i]->get_id()<<'\t'<<User[i]->get_username()<<'\t'<<User[i]->get_fullname()<<'\t'<<User[i]->get_password()<<'\t'<<User[i]->get_type()<<'\t'<<User[i]->get_status()<<'\t'<<User[i]->get_balance()<<'\t';
  1216.                         for (int l=0;l<User[i]->size_freebets();l++)
  1217.                         {   cout<< User[i]->get_freebets(l);
  1218.                             if(l!=User[i]->size_freebets()-1)
  1219.                                 cout<<",";
  1220.                             else
  1221.                                 cout << endl;
  1222.                         }
  1223.                     }
  1224.                 }
  1225.  
  1226.             }
  1227.             else
  1228.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  1229.             flag=0;
  1230.         }
  1231.         void lock(vector<Users*> &User)
  1232.         {   if (flag==1)
  1233.             {   string name;
  1234.                 string name3;
  1235.                 int flag2=0,i;
  1236.                 cout<<"Dwse onoma"<<endl;
  1237.                 getline(cin,name);
  1238.                 for(i=0;i<User.size();i++)
  1239.                 {  
  1240.                     if(!User[i]->get_username().compare(name) && User[i]->get_type()!=3)
  1241.                     {   if(User[i]->get_status()[0]!='L')
  1242.                         {   flag2=1;
  1243.                             cout<<"Anefere logo"<<endl;
  1244.                             getline(cin, name3);
  1245.                             string name2="L,";
  1246.                             name2.append(name3);
  1247.                             User[i]->change_status(name3);
  1248.                             break;
  1249.                         }
  1250.                         else if(User[i]->get_status()[0]=='L')
  1251.                         {   flag2=1;
  1252.                             cout<<"Anefere logo"<<endl;
  1253.                             getline(cin, name3);
  1254.                             string temp="A,";
  1255.                             temp.append(name3);
  1256.                             User[i]->change_status(temp);
  1257.                             break;
  1258.                         }
  1259.                     }
  1260.                 }
  1261.             }
  1262.             else
  1263.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  1264.             flag=0;
  1265.         }
  1266.         void print()
  1267.         {   cout<<"Epile3te" << endl << "To ID tou kombou pou epi8umeite na episkefteite" <<endl<<"H(Home),gia epistrofh sthn arxikh o8onh"<<endl<<"T(Toggle) gia enallagh probolhs timwn" << endl<< "X(Exit) gia e3odo apo to susthma"<<endl<<"B(Bets),gia emfanish 20 teleutaiwn stoixhmatwn"<<endl<<"F(Freebets),gia apodosh kouponiou se xrhsth"<<endl<<"S(Save),gia swsimo ths trexousas katastashs kai sugxronismo twn arxeiwn susthmatos"<<endl<<"Management:"<<endl<<"L(Logs),gia emfanish twn teleutaiwn 25 energeiwn sto susthma"<<endl<<"U(Users),gia diaxeirhsh xrhstwn"<<endl<<"V(Visibility),gia enallgah oratothtas kombou"<<endl<<"R(Rename),gia metonomasia kombou"<<endl<<"N(New),gia dhmiourgia kombou"<<endl<<"C(Copy),gia thn antigrafh enos kombou (ws mh oratou)"<<endl<<"D(Delete),gia th diagrafh kombou"<<endl;
  1268.         }
  1269.         void exprint()
  1270.         {   print();
  1271.               }
  1272.     private:
  1273.         int flag;
  1274. };
  1275. void root::preprint(Users* current_user)
  1276. {   current_user->print();
  1277. }
  1278. int market::preplace(Users* current_user,vector <Bethistory*> &bethistory,vector <History*> &history)
  1279. {   current_user->place(bethistory,history,ID);
  1280.     return 1;
  1281. }
  1282. int market::prevoid(Users* current_user,vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid)
  1283. {   current_user->Void(User,bethistory,nodeid);
  1284.     return 1;
  1285. }
  1286. int market::presettle(Users* current_user,vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid)
  1287. {   current_user->Settle(User,bethistory,nodeid);
  1288.     return 2;
  1289. }
  1290. void market::preprint(Users* current_user)
  1291. {   current_user->exprint();
  1292. }
  1293.  
  1294.  
  1295.  
  1296. void write_users(vector<Users*>& User){
  1297.     remove("users.csv");
  1298.     ofstream file;
  1299.     file.open("users.csv",ios::out);
  1300.     file << "user_id | username | fullname | password | type | status | balance | freebets |" << endl ;
  1301.     int i,j;
  1302.     for(i=0;i<User.size();i++){
  1303.         file << User[i]->get_id() << "|" << User[i]->get_username() << "|" << User[i]->get_fullname() << "|";
  1304.         file << User[i]->get_password() << "|" << User[i]->get_type() << "|" << User[i]->get_status() << "|" << User[i]->get_balance() << "|";
  1305.         for(j=0;j<User[i]->size_freebets();j++){
  1306.             file << User[i]->get_freebets(j);
  1307.             if (j<User[i]->size_freebets()-1){
  1308.                 file << ",";
  1309.             }
  1310.         }
  1311.         file << "|" <<endl;
  1312.     }
  1313.     file.close();
  1314. }
  1315.  
  1316. void write_history(vector <History*> &history){
  1317.     remove("audit.log");
  1318.     ofstream file;
  1319.     file.open("audit.log",ios::out);
  1320.     file << "username | operation | money | target | rename |"<<endl;
  1321.     for(int i=0;i<history.size();i++){
  1322.         file << history[i]->username << "|" << history[i]->operation << "|" << history[i]->money << "|" << history[i]->target << "|" << history[i]->rename << "|" <<endl;
  1323.     }
  1324.     file.close();
  1325. }
  1326.  
  1327. void write_bet(vector <Bethistory*> &bethistory){
  1328.     remove("bets.csv");
  1329.     ofstream file;
  1330.     file.open("bets.csv",ios::out);
  1331.     file << "bet_id | user_id | node_id | stake | result |" << endl ;
  1332.     for(int i=0;i<bethistory.size() ;i++){
  1333.         file << bethistory[i]->bet_id<< "|" << bethistory[i]->user_id << "|" << bethistory[i]->node_id << "|" << bethistory[i]->stake <<"|" << bethistory[i]->result <<"|" <<endl;
  1334.     }
  1335.     file.close();
  1336. }
  1337.  
  1338. void write_hierarchy(root* Root)
  1339. {   remove("hierarchy.dat.txt");
  1340.     ofstream file;
  1341.     file.open("hierarchy.dat.txt",ios::out);
  1342.     Root->write(file);
  1343.     file.close();
  1344. }
  1345.  
  1346. int Director::save(root* root,vector<Users*> &User,vector<History*> &history,vector <Bethistory*> &bethistory)
  1347. {   write_users(User);
  1348.     write_history(history);
  1349.     write_bet(bethistory);
  1350.     write_hierarchy(root);
  1351.     cout<<"Ta arxeia enhmerw8hkan"<<endl;
  1352.     return 1;
  1353. }
  1354.  
  1355.  
  1356. void read_hierarchy(root* Root){
  1357.     vector <root*> hierarchy2;
  1358.     vector <root*> hierarchy3;
  1359.     vector <root*> hierarchy4;
  1360.     vector <root*> hierarchy5;
  1361.     ifstream file;
  1362.     file.open("hierarchy.dat.txt",ios::in);
  1363.     if(file.fail()){
  1364.         cerr << "Error openning file" << endl;
  1365.         exit(1);
  1366.     }
  1367.     string line;
  1368.     while(getline(file,line)){
  1369.         const char s[2]=" ";
  1370.         const char d[2]="\n";
  1371.         char* token;
  1372.         //converting string to char*
  1373.         char *str = new char[line.length() + 1];
  1374.         strcpy(str, line.c_str());
  1375.         //
  1376.         token = strtok(str,s);  
  1377.         string node(token);
  1378.         size_t n = count(node.begin(), node.end(), '.'); // number of dots
  1379.         token = strtok(NULL, d); //oti apomenei meta to node
  1380.        
  1381.         if(n == 1)
  1382.         {   category* temp=new category(token,node);
  1383.             Root->readh(temp);
  1384.             hierarchy2.push_back(temp);
  1385.         }
  1386.         if(n==2){
  1387.             subcategory* temp=new subcategory(token,node);
  1388.             hierarchy2[hierarchy2.size()-1]->readh(temp);
  1389.             hierarchy3.push_back(temp);
  1390.         }
  1391.         if(n == 3){
  1392.             strcpy(str,token); //str = token
  1393.             const char h[2] = "|";
  1394.             char* n;
  1395.             char* date;
  1396.             char* time;
  1397.             n = strtok(str,h);
  1398.             date=strtok(NULL,h); //date
  1399.             time = strtok(NULL,d);
  1400.             event* temp=new event(n,node,date,time);
  1401.             hierarchy3[hierarchy3.size()-1]->readh(temp);
  1402.             hierarchy4.push_back(temp);
  1403.            
  1404.         }
  1405.         if(n == 4){
  1406.             market* temp=new market(token,node);
  1407.             hierarchy4[hierarchy4.size()-1]->readh(temp);
  1408.             hierarchy5.push_back(temp);
  1409.         }
  1410.         if(n == 5){
  1411.             strcpy(str,token); //str = token
  1412.             const char h[2] = "#";
  1413.             char* n;
  1414.             n = strtok(str,h);
  1415.             token = strtok(NULL,h); //price
  1416.             selection* temp=new selection(n,node,token);
  1417.             hierarchy5[hierarchy5.size()-1]->readh(temp);
  1418.         }
  1419.     }
  1420. }
  1421.  
  1422.  
  1423. void read_users(vector<Users*> &User){
  1424.     ifstream file;
  1425.     file.open("users.csv",ios::in);
  1426.     if(file.fail()){
  1427.         cerr << "Error openning file" << endl;
  1428.         exit(1);
  1429.     }
  1430.     string line;
  1431.     getline(file,line);
  1432.     //pairnw to prwto line to arxeiasto me ta userid username ktl kai de to xrhsimopoiw
  1433.     while(getline(file,line)){
  1434.         //exw twra to line pou me | exei ola ta stoixeia
  1435.         const char s[2]="|";
  1436.         char* token;
  1437.         Users temp;
  1438.         //converting string to char*
  1439.         char *str = new char[line.length() + 1];
  1440.         strcpy(str, line.c_str());
  1441.         //
  1442.         token = strtok(str,s);
  1443.         temp.change_id(atoi(token)); //(kanw to char* int)
  1444.         token = strtok(NULL, s);
  1445.         temp.change_username(token);
  1446.         token = strtok(NULL, s);
  1447.         temp.change_fullname(token);
  1448.         token = strtok(NULL, s);
  1449.         temp.change_password(token);
  1450.         token = strtok(NULL, s);
  1451.         temp.change_type(atoi(token)) ; //kanw to char* int
  1452.         token = strtok(NULL, s);
  1453.         temp.change_status(token);
  1454.         token = strtok(NULL, s);
  1455.         temp.change_balance(atof(token)) ; //kanw char* float
  1456.         token = strtok(NULL, s);
  1457.         //twra to token einai san ena char* kai prepei pali na to kopsw me delimeter to ,
  1458.         char* token2;
  1459.         const char d[2]=",";
  1460.         token2=strtok(token,d);
  1461.         while(token2 != NULL){
  1462.             temp.add_freebets(atof(token2)); //char* to float
  1463.             token2 = strtok(NULL, d);
  1464.         }
  1465.         if(temp.get_type()==1){  
  1466.             User.push_back(new Punter());
  1467.         }
  1468.         else if(temp.get_type()==2){  
  1469.             User.push_back(new Trader());
  1470.         }
  1471.         else{  
  1472.             User.push_back(new Director());
  1473.         }
  1474.         int i=User.size()-1;
  1475.         User[i]->change_id(temp.get_id());
  1476.         User[i]->change_username(temp.get_username());
  1477.         User[i]->change_fullname(temp.get_fullname());
  1478.         User[i]->change_password(temp.get_password());
  1479.         User[i]->change_type(temp.get_type());
  1480.         User[i]->change_status(temp.get_status());
  1481.         User[i]->change_balance(temp.get_balance());
  1482.         for(int l=0;l<temp.size_freebets();l++)
  1483.         {   User[i]->add_freebets(temp.get_freebets(l));
  1484.         }
  1485.     }
  1486.    
  1487.     //etoimo to User
  1488.     file.close();
  1489. }
  1490.  
  1491. void read_history(vector <History*> &history){
  1492.     ifstream file;
  1493.     file.open("audit.log",ios::in);
  1494.     if(file.fail()){
  1495.         cerr << "Error openning file" << endl;
  1496.         exit(1);
  1497.     }
  1498.     string line;
  1499.     getline(file,line);
  1500.     while(getline(file,line)){
  1501.         const char s[2]="|";
  1502.         char* token;
  1503.         History temp;
  1504.         //converting string to char*
  1505.         char *str = new char[line.length() + 1];
  1506.         strcpy(str, line.c_str());
  1507.         //
  1508.         token = strtok(str,s);
  1509.         temp.username = token;
  1510.         token = strtok(NULL, s);
  1511.         temp.operation = token;
  1512.         token = strtok(NULL, s);
  1513.         temp.money = atof(token);
  1514.         token = strtok(NULL, s);
  1515.         temp.target =token;
  1516.         token = strtok(NULL, s);
  1517.         temp.rename =token;
  1518.         //
  1519.         history.push_back(new History());
  1520.         int i = history.size()-1;
  1521.         //
  1522.         history[i]->username.assign(temp.username);
  1523.         history[i]->operation.assign(temp.operation);
  1524.         history[i]->target.assign(temp.target);
  1525.         history[i]->rename.assign(temp.rename);
  1526.         history[i]->money = temp.money;
  1527.         //
  1528.     }
  1529.     file.close();
  1530. }
  1531.  
  1532. void read_bet(vector <Bethistory*> &bethistory){
  1533.     ifstream file;
  1534.     file.open("bets.csv",ios::in);
  1535.     if(file.fail()){
  1536.         cerr << "Error openning file" << endl;
  1537.         exit(1);
  1538.     }
  1539.     string line;
  1540.     getline(file,line);
  1541.     while(getline(file,line)){
  1542.         const char s[2]="|";
  1543.         char* token;
  1544.         Bethistory temp;
  1545.         //converting string to char*
  1546.         char *str = new char[line.length() + 1];
  1547.         strcpy(str, line.c_str());
  1548.         //
  1549.         token = strtok(str,s);
  1550.         temp.bet_id = atoi(token);
  1551.         token = strtok(NULL, s);
  1552.         temp.user_id = atoi(token);
  1553.         token = strtok(NULL, s);
  1554.         temp.node_id = token;
  1555.         token = strtok(NULL, s);
  1556.         temp.stake = atof(token);
  1557.         token = strtok(NULL, s);
  1558.         temp.result = token[0];
  1559.         token = strtok(NULL, s);
  1560.         //
  1561.         bethistory.push_back(new Bethistory());
  1562.         int i = bethistory.size()-1;
  1563.         //
  1564.         bethistory[i]->bet_id = temp.bet_id;
  1565.         bethistory[i]->user_id = temp.user_id;
  1566.         bethistory[i]->node_id.assign(temp.node_id);
  1567.         bethistory[i]->stake = temp.stake;
  1568.         bethistory[i]->result= temp.result;
  1569.         //
  1570.     }
  1571.     file.close();
  1572. }
  1573.  
  1574. void management_input(Users* currentUser,vector<Users*> &User, vector<History*> &history, vector<Bethistory*> &bethistory, vector<root*> &Root){
  1575.     while(1){
  1576.         root* current_node;
  1577.         int i=Root.size()-1;
  1578.         current_node = Root[i];
  1579.         current_node->preprint(currentUser);
  1580.         for(int l=0;l<Root.size();l++)
  1581.         {   cout<<Root[l]->get_name()<<'/';
  1582.         }
  1583.         cout<<endl;
  1584.         currentUser->show(current_node);
  1585.        
  1586.         string entoli;
  1587.         getline(cin,entoli);
  1588.         if(isdigit(entoli[0])){
  1589.             currentUser->guide(current_node,entoli);
  1590.             if(Root[i]->get_name().compare(current_node->get_name()))
  1591.             {   Root.push_back(current_node);
  1592.             }
  1593.         }
  1594.         else{
  1595.             int check =0;
  1596.             capitalow(&entoli);
  1597.             if(entoli.size() > 1){
  1598.                 check = 1;
  1599.             }
  1600.             char ent;
  1601.             ent=entoli[0]; 
  1602.             if(ent == 'a'){
  1603.                 if(check){
  1604.                     if(entoli.compare("account") == 0){
  1605.                         currentUser->account(history);
  1606.                     }
  1607.                 }
  1608.                 else{
  1609.                     currentUser->account(history);
  1610.                 }
  1611.             }
  1612.             if(ent == 'b'){
  1613.                 if(check){
  1614.                     if(entoli.compare("bets") == 0){
  1615.                         currentUser->bets(bethistory,history);
  1616.                     }
  1617.                 }
  1618.                 else{
  1619.                     currentUser->bets(bethistory,history);
  1620.                 }
  1621.             }
  1622.             if(ent == 'c'){
  1623.                 if(check){
  1624.                     if(entoli.compare("copy") == 0){
  1625.                         currentUser->Copy(current_node);    // copy
  1626.                     }
  1627.                 }
  1628.                 else{
  1629.                     currentUser->Copy(current_node);
  1630.                 }
  1631.             }
  1632.             if(ent == 'd'){
  1633.                 if(check){
  1634.                     if(entoli.compare("delete") == 0){
  1635.                         currentUser->Delete(current_node);
  1636.                     }
  1637.                     else if (entoli.compare("deposit") == 0){
  1638.                         currentUser->deposit(history);
  1639.                     }
  1640.                 }
  1641.                 else{
  1642.                     int i;
  1643.                     i=currentUser->Delete(current_node); //an den ginetai ,deposit
  1644.                     if(i == 0){
  1645.                         currentUser->deposit(history);
  1646.                     }              
  1647.                 }
  1648.             }
  1649.             if(ent == 'f'){
  1650.                 if(check){
  1651.                     if(entoli.compare("freebets") == 0){
  1652.                         currentUser->freebets(User,history);
  1653.                     }
  1654.                 }
  1655.                 else{
  1656.                     currentUser->freebets(User,history);
  1657.                 }
  1658.             }
  1659.             if(ent == 'h'){
  1660.                 if(check){
  1661.                     if(entoli.compare("home") == 0){
  1662.                         currentUser->home(Root,current_node);
  1663.                     }
  1664.                 }
  1665.                 else{
  1666.                     currentUser->home(Root,current_node);
  1667.                 }
  1668.             }
  1669.             if(ent == 't'){
  1670.                 if(check){
  1671.                     if(entoli.compare("toggle") == 0){
  1672.                         currentUser->toggle();
  1673.                     }
  1674.                 }
  1675.                 else{
  1676.                     currentUser->toggle();
  1677.                 }
  1678.             }
  1679.             if(ent == 'x'){
  1680.                 if(check){
  1681.                     if(entoli.compare("exit") == 0){
  1682.                         write_users(User);
  1683.                         write_history(history);
  1684.                         write_bet(bethistory);
  1685.                         write_hierarchy(Root[0]);
  1686.                         exit(2);
  1687.                     }
  1688.                 }
  1689.                 else{
  1690.                     write_users(User);
  1691.                     write_history(history);
  1692.                     write_bet(bethistory);
  1693.                     write_hierarchy(Root[0]);
  1694.                     exit(2);
  1695.                 }
  1696.             }
  1697.             if(ent == 's'){
  1698.                 if(check){
  1699.                     if(entoli.compare("save") == 0){
  1700.                         currentUser->save(current_node,User,history,bethistory);
  1701.                     }
  1702.                     else if(entoli.compare("settle") == 0){
  1703.                         current_node->presettle(currentUser,User,bethistory,current_node);
  1704.                     }
  1705.                     else if(entoli.compare("search") == 0){
  1706.                         currentUser->search(User);
  1707.                     }
  1708.                 }
  1709.                 else{
  1710.                     int i;
  1711.                     i=currentUser->save(current_node,User,history,bethistory);
  1712.                     if(i == 0){
  1713.                         int j;
  1714.                         j=current_node->presettle(currentUser,User,bethistory,current_node);
  1715.                         if(j==0){
  1716.                             currentUser->search(User);
  1717.                         }
  1718.                     }
  1719.                 }
  1720.             }
  1721.             if(ent == 'l'){
  1722.                 if(check){
  1723.                     if(entoli.compare("logs") == 0){
  1724.                         currentUser->logs(history);
  1725.                     }
  1726.                     else if(entoli.compare("lock") == 0){
  1727.                         currentUser->lock(User);
  1728.                     }
  1729.                 }
  1730.                 else{
  1731.                     int i;
  1732.                     i=currentUser->logs(history);
  1733.                     if(i == 0){
  1734.                         currentUser->lock(User);
  1735.                     }
  1736.                 }
  1737.             }
  1738.             if(ent == 'u'){
  1739.                 if(check){
  1740.                     if(entoli.compare("users") == 0){
  1741.                         currentUser->users();
  1742.                     }
  1743.                 }
  1744.                 else{
  1745.                     currentUser->users();
  1746.                 }
  1747.             }
  1748.            
  1749.             if(ent == 'r'){
  1750.                 if(check){
  1751.                     if(entoli.compare("rename") == 0){
  1752.                         currentUser->Rename(User,history,current_node);
  1753.                     }
  1754.                 }
  1755.                 else{
  1756.                     currentUser->Rename(User,history,current_node);
  1757.                 }
  1758.             }
  1759.             if(ent == 'n'){
  1760.                 if(check){
  1761.                     if(entoli.compare("new") == 0){
  1762.                         currentUser->New(current_node);
  1763.                     }
  1764.                 }
  1765.                 else{
  1766.                     currentUser->New(current_node);
  1767.                 }
  1768.             }
  1769.            
  1770.             if(ent == 'p'){
  1771.                 if(check){
  1772.                     if(entoli.compare("place") == 0){
  1773.                         current_node->preplace(currentUser,bethistory,history);
  1774.                     }
  1775.                     else if(entoli.compare("password") == 0){
  1776.                         currentUser->password(history);
  1777.                     }
  1778.                 }
  1779.                 else{
  1780.                     int i;
  1781.                     i=current_node->preplace(currentUser,bethistory,history);
  1782.                     if(i==0){
  1783.                         currentUser->password(history);
  1784.                     }
  1785.                 }
  1786.             }
  1787.             if(ent == 'v'){
  1788.                 if(check){
  1789.                     if(entoli.compare("void") == 0){
  1790.                         current_node->prevoid(currentUser,User,bethistory,current_node);
  1791.                     }
  1792.                     else if(entoli.compare("view") == 0){
  1793.                         currentUser->view(User);
  1794.                     }
  1795.                     else if(entoli.compare("visibility") == 0){
  1796.                         currentUser->visibility(current_node);
  1797.                     }
  1798.                 }
  1799.                 else{
  1800.                     int i;
  1801.                     i=current_node->prevoid(currentUser,User,bethistory,current_node);
  1802.                     if(i==0){
  1803.                         int j;
  1804.                         j=currentUser->view(User);
  1805.                         if(j==0){
  1806.                             currentUser->visibility(current_node);
  1807.                         }
  1808.                     }
  1809.                 }
  1810.             }
  1811.         }
  1812.     }
  1813. }
  1814.  
  1815. void register_user(vector<Users*> &User,Users* current_user,vector<History*> &history,vector<Bethistory*> &bethistory,vector<root*> Root){
  1816.     int redo;
  1817.     string name;
  1818.     do{
  1819.         redo=0;
  1820.         cout << "username: ";
  1821.         getline (cin, name);
  1822.         for(int i=0;i<User.size();i++){
  1823.             if(name.compare(User[i]->get_username()) == 0){
  1824.                 cout << "This name already exists please type a different name!" << endl;
  1825.                 redo = 1;
  1826.             }
  1827.             if(name.compare("\n") == 0 || name.compare("guest:guest")==0){
  1828.                 cout << "forbidden name,please type a different name" << endl;
  1829.                 redo=1;
  1830.             }
  1831.         }
  1832.     }while(redo);
  1833. //
  1834.     User.push_back(new Punter);
  1835.     int i = User.size()-1;
  1836.     User[i]->change_id(i+1);
  1837.     User[i]->change_username(name);
  1838.     User[i]->change_fullname(name); // this could be changed later in the account settings
  1839.     User[i]->change_type(1);
  1840.     User[i]->change_status("A");
  1841.     User[i]->change_balance(0.0);
  1842.     User[i]->add_freebets(0.0); //
  1843.     do{
  1844.         redo=0;
  1845.         cout << "password: ";
  1846.         string pass1;
  1847.         getline (cin,pass1);
  1848.         cout << "Please retype your password:" ;
  1849.         string pass2;
  1850.         getline (cin,pass2);
  1851.         if (pass1.compare(pass2) != 0){
  1852.             cout << "You should insert the same password twice" << endl;
  1853.             redo=1;
  1854.         }
  1855.         else{
  1856.             User[i]->change_password(pass1);
  1857.         }
  1858.     }while(redo);
  1859.     write_users(User);  //arxeio susthmatos save
  1860.     current_user = User[i];
  1861.     management_input(current_user,User,history,bethistory,Root);
  1862. }
  1863. void Trader::Settle(vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid)
  1864.     {   cout<<"Dwse to id ths epiloghs stoixhmatismou p 8es na 8ewrh8ei ws nikh"<<endl;
  1865.     string choice;
  1866.     getline(cin,choice);
  1867.     if(isdigit(choice[0]))
  1868.     {   stringstream buffer(choice);
  1869.         int i;
  1870.         buffer >> i;
  1871.         i--;
  1872.         string id=nodeid->voidd(i);
  1873.         root* temp;
  1874.         temp=nodeid->visiblenode(i);
  1875.         string token;
  1876.         double price;
  1877.         price=temp->get_price2();
  1878.         for(int l=0;l<bethistory.size();l++)
  1879.         {   if(!(id.compare(bethistory[l]->node_id)))
  1880.             {   if(bethistory[l]->result=='-')
  1881.                 {   bethistory[l]->result='W';
  1882.                     for(int j=0;j<User.size();j++)
  1883.                     {   if(bethistory[l]->user_id==User[j]->get_id())
  1884.                         {   User[j]->add_balance(bethistory[l]->stake*price-(bethistory[l]->stake*price*5.0/100.0));
  1885.                         }
  1886.                     }
  1887.                 }
  1888.                 else
  1889.                 {   cout<<"Already changed"<<endl;
  1890.                     break;
  1891.                 }
  1892.             }
  1893.         }
  1894.         string lose_id;
  1895.         lose_id.assign(id);
  1896.         lose_id.erase(lose_id.size()-1);
  1897.         lose_id.erase(lose_id.size()-1);
  1898.         for(int l=0;l<bethistory.size();l++)
  1899.         {   if(bethistory[l]->node_id!=id && bethistory[l]->node_id.find(lose_id)!=bethistory[l]->node_id.npos && bethistory[l]->result=='-')
  1900.             {   bethistory[l]->result='L';
  1901.             }
  1902.         }
  1903.         //enhmerwsh arxeiwn xrhstwn kai bet
  1904.         write_users(User);
  1905.         write_bet(bethistory);
  1906.     }
  1907.     else
  1908.     {   cout<<"Operation aborted wrong input"<<endl;
  1909.     }
  1910. }
  1911.  
  1912.  
  1913. void Trader::Void(vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid)
  1914.     {   cout<<"Dwse to id ths epiloghs stoixhmatismou p 8es na akurw8ei"<<endl;
  1915.     string choice;
  1916.     getline(cin,choice);
  1917.     if(isdigit(choice[0]))
  1918.     {   stringstream buffer(choice);
  1919.         int i;
  1920.         buffer >> i;
  1921.         i--;
  1922.         string id=nodeid->voidd(i);
  1923.         for(int l=0;l<bethistory.size();l++)
  1924.         {   if(!(id.compare(bethistory[l]->node_id)))
  1925.             {   if(bethistory[l]->result=='-')
  1926.                 {   bethistory[l]->result='V';
  1927.                     for(int j=0;j<User.size();j++)
  1928.                     {   if(bethistory[l]->user_id==User[j]->get_id())
  1929.                         {   User[j]->add_balance(bethistory[l]->stake);
  1930.                         }
  1931.                     }
  1932.                 }
  1933.                 else
  1934.                 {   cout<<"Already voided"<<endl;
  1935.                     break;
  1936.                 }
  1937.             }
  1938.         }
  1939.         //enhmerwsh arxeiwn xrhstwn kai bet
  1940.         write_users(User);
  1941.         write_bet(bethistory);
  1942.     }
  1943.     else
  1944.     {   cout<<"Operation aborted wrong input"<<endl;
  1945.     }
  1946. }
  1947. void login_user(vector<Users*> User,Users* current_user,vector<History*> &history,vector<Bethistory*> &bethistory,vector<root*> Root){
  1948.     cout << "Welcome to KAPPA BET!" << endl;
  1949.     cout << "Please type username and password to login to your account!" << endl;
  1950.     cout << "If you don't have an account ,press (Enter) or type guest:guest to login as guest" << endl;
  1951.     int anagnwr=-1;
  1952.     int guest=0;
  1953.     int redo;
  1954.     do{
  1955.         redo=0;
  1956.         cout << "username: " ;
  1957.         string name;
  1958.         string rightpass;
  1959.         getline(cin,name);
  1960.         if (name.size()==0)
  1961.             name.assign("\n");
  1962.         if((name.compare("guest:guest") == 0) || name.compare("\n")==0){
  1963.             guest = 1;
  1964.             break;
  1965.         }
  1966.         for(int i=0;i<User.size();i++){
  1967.             if(name.compare(User[i]->get_username()) == 0){
  1968.                 rightpass.assign(User[i]->get_password());
  1969.                 anagnwr=i;
  1970.             }
  1971.         }
  1972.         string provpass;
  1973.         cout << "password: ";
  1974.         getline(cin,provpass);
  1975.         if(provpass.size()==0)
  1976.             provpass.assign("\n");
  1977.         if(provpass.compare(rightpass) == 0){
  1978.             redo=0;
  1979.         }
  1980.         else{
  1981.             cout << "Wrong Credentials! Please Retry!" << endl;
  1982.             redo=1;
  1983.         }
  1984.     }while(redo);
  1985.     if(guest == 0){
  1986.         char locked = 'L';
  1987.         if(locked == User[anagnwr]->get_status()[0]){
  1988.             cout << "Your account has been locked due to: ";
  1989.             for(int i=2;i<User[anagnwr]->get_status().size();i++){
  1990.                 cout << User[anagnwr]->get_status()[i];
  1991.             }
  1992.             exit(1);
  1993.         }  
  1994.     }
  1995.     //eisodos xrhsth sto arxiko menu analoga me to user.type h an einai guest
  1996.     if(guest == 1){
  1997.         Users* temp = new Guest();
  1998.         //gurnaw
  1999.         current_user = temp;
  2000.        
  2001.     }
  2002.     else{
  2003.         current_user = User[anagnwr];
  2004.     }
  2005.     write_users(User);
  2006.     management_input(current_user,User,history,bethistory,Root);
  2007. }
  2008.  
  2009. int main(int argc, char** argv) {
  2010.     cout.precision(2);
  2011.     vector<Users*> User;
  2012.     vector<History*> history;
  2013.     vector<Bethistory*> bethistory;
  2014.     vector<root*> Root;
  2015.     Root.push_back(new root());
  2016.     read_history(history);
  2017.     read_users(User);
  2018.     read_hierarchy(Root[0]);
  2019.     read_bet(bethistory);
  2020.     Users* currentUser;
  2021.     if (argc == 1){
  2022.         //xwris parameters
  2023.         login_user(User, currentUser , history , bethistory , Root);
  2024.     }
  2025.     else if(argc == 2){
  2026.         //mia parametros
  2027.         string parameter(argv[1]);
  2028.         capitalow(&parameter);
  2029.         if(strcmp(parameter.c_str(),"-r") == 0){
  2030.             //register a user
  2031.             register_user(User,currentUser,history,bethistory,Root);
  2032.         }
  2033.     }
  2034.     return 0;
  2035. }
Add Comment
Please, Sign In to add comment