Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 58.20 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.     NID.insert(NID.end(),'.');    
  546.     ostringstream convert;
  547.     convert << nodes.size()+1;  
  548.     string temp3=convert.str();  
  549.     NID.insert(NID.size(),temp3);
  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.     NID.insert(NID.end(),'.');    
  563.     ostringstream convert;
  564.     convert << nodes.size()+1;  
  565.     string temp3=convert.str();  
  566.     NID.insert(NID.size(),temp3);
  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.     NID.insert(NID.end(),'.');    
  574.     ostringstream convert;
  575.     convert << nodes.size()+1;  
  576.     string temp3=convert.str();  
  577.     NID.insert(NID.size(),temp3);
  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. class elements
  653. {   public:
  654.         int user_id;
  655.         string username;
  656.         string fullname;
  657.         string password;
  658.         int type;
  659.         string status;
  660.         double balance;
  661.         vector<double> freebets;
  662.  
  663. };
  664.  
  665. void historyfun(vector<History*> &history,string operation,string target,string rename,string username,double x)
  666. {   history.push_back(new History);
  667.     int i=history.size()-1;
  668.     history[i]->operation.assign(operation);
  669.     history[i]->money=x;
  670.     history[i]->target.assign(target);
  671.     history[i]->rename.assign(rename);
  672.     history[i]->username.assign(username);
  673.      
  674. }
  675.  
  676. void bethistoryfun(vector<Bethistory*> &bethistory,int bet_id,int user_id,string node_id,double stake,char result)
  677. {   bethistory.push_back(new Bethistory);
  678.     int i=bethistory.size()-1;
  679.     bethistory[i]->bet_id=bet_id;
  680.     bethistory[i]->user_id=user_id;
  681.     bethistory[i]->node_id.assign(node_id);
  682.     bethistory[i]->stake=stake;
  683.     bethistory[i]->result=result;
  684. }
  685. class Users
  686. {   public:
  687.         class elements ID;
  688.         virtual void print()
  689.         {  
  690.         }
  691.         virtual void guide(root* &nodeid,string entoli)
  692.         {   int i;
  693.             stringstream buffer(entoli);
  694.             buffer>>i;
  695.             i--;
  696.             if(i<nodeid->Size())
  697.             {   nodeid=nodeid->visiblenode(i);
  698.             }
  699.             else
  700.             {   cout<<"Invalid input"<<endl;
  701.             }
  702.         }
  703.         virtual void exprint()
  704.         {   print();
  705.         }
  706.         virtual void show(root* current_node)
  707.         {   current_node->vshow();
  708.         }
  709.         void home(vector <root*> &path,root* current_node)
  710.         {   for(int i=path.size()-1;i>0;i--)
  711.             {   path.erase(path.begin()+i);
  712.             }
  713.             current_node=path[0];
  714.         }
  715.         void toggle()
  716.         {   ctoggle= !ctoggle;
  717.         }
  718.         virtual void bets(vector<Bethistory*> &bethistory,vector<History*> &history)
  719.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  720.         }
  721.         virtual void freebets(vector<Users*> &User,vector<History*> &history)
  722.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  723.         }
  724.         virtual void account(vector<History*> &history)
  725.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  726.         }
  727.         virtual int save(root* root,vector<Users*> &User,vector<History*> &history,vector <Bethistory*> &bethistory)
  728.         {   return 0;
  729.         }
  730.         virtual int logs(vector<History*> &history)
  731.         {   return 0;
  732.         }
  733.         virtual void users()
  734.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  735.         }
  736.         virtual void Rename(vector<Users*> &User,vector<History*> &history,root* nodeid)
  737.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  738.         }
  739.         virtual void New(root *nodeid)
  740.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  741.         }
  742.         virtual void Copy(root* nodeid)
  743.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  744.         }
  745.         virtual int Delete(root* nodeid)
  746.         {   return 0;
  747.         }
  748.         virtual int view(vector <Users*> &User)
  749.         {   return 0;
  750.         }
  751.         virtual void search(vector <Users*> &User)
  752.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  753.         }
  754.         virtual void place(vector<Bethistory*> &bethistory,vector<History*> &history,string nodeid)
  755.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  756.         }
  757.         virtual void lock(vector<Users*> &User)
  758.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  759.         }
  760.         virtual void password(vector<History*> &history)
  761.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  762.         }
  763.         virtual void deposit (vector<History*> &history)
  764.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  765.         }
  766.         virtual void Void(vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid)
  767.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  768.         }
  769.         virtual void Settle(vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid)
  770.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  771.         }
  772.         virtual void visibility(root* nodeid)
  773.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  774.         }
  775. };
  776.  
  777. class Guest:public Users
  778. {   public:
  779.         void print()
  780.         {   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;
  781.         }
  782. };
  783. class Punter:public Users
  784. {   public:
  785.         void print()
  786.         {   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;
  787.         }
  788.         void exprint()
  789.         {   print();
  790.             cout<<"P(Place),gia enapo8esh stoixhmatos"<<endl;
  791.         }
  792.         void Rename(vector<Users*> &User,vector<History*> &history,root* nodeid)
  793.         {   if(flag==1)
  794.             {   string str;
  795.                 while(1)
  796.                 {   int flag2=0;
  797.                      getline(cin,str);
  798.                     for(int i=0;i<User.size();i++)
  799.                     {   if (!User[i]->ID.username.compare(str))
  800.                         {   flag2=1;
  801.                             cout<<"To username xrhshmopoieitai hdh"<<endl;
  802.                             break;
  803.                         }
  804.                     }
  805.                     if(flag2==0)
  806.                         break;
  807.                 }
  808.                 ID.username.replace(ID.username.begin(),ID.username.end(),str);
  809.                 historyfun(history,"Rename","-","-",ID.username,0.0);
  810.             }
  811.             else
  812.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  813.             flag=0;
  814.         }
  815.         void password(vector<History*> &history)
  816.         {   if(flag==1)
  817.             {   string str,str1;
  818.                 while(1)
  819.                 {   cout<< "Dwse ton neo kwdiko"<<endl;
  820.                     getline(cin,str);
  821.                     cout<< "Epanalabe"<<endl;
  822.                     getline(cin,str1);
  823.                     if (!str.compare(str1))
  824.                     {   ID.password.replace(ID.password.begin(),ID.password.end(),str);
  825.                         historyfun(history,"Password","-","-",ID.username,0.0);
  826.                         break;
  827.                     }
  828.                 }
  829.  
  830.             }
  831.             else
  832.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  833.             flag=0;
  834.  
  835.         }
  836.         void bets(vector<Bethistory*> &bethistory,vector<History*> &history)
  837.         {   if(flag==1)
  838.             {   for (int i=0;i<bethistory.size();i++)
  839.                 {   if (bethistory[i]->user_id==ID.user_id)
  840.                     {   cout<<"Bet to "<<bethistory[i]->node_id<< " "<< bethistory[i]->stake<< endl;
  841.  
  842.                     }
  843.                 }
  844.                 historyfun(history,"Bet","-","-",ID.username,0.0);
  845.             }
  846.             else
  847.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  848.  
  849.         }
  850.         void deposit(vector<History*> &history)
  851.         {   if(flag==1)
  852.             {   double x;
  853.                 cin >> x;
  854.                 ID.balance+=x;
  855.                 cout << "To neo sas poso sto logariasmo sas einai" << ID.balance<<endl;
  856.                 historyfun(history,"Deposit","-","-",ID.username,x);
  857.             }
  858.             else
  859.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  860.             flag=0;
  861.  
  862.         }
  863.         void account(vector<History*> &history)
  864.         {   cout<<"Paixths: " << ID.username<<endl<<"Dia8esimo upoloipo: "<< ID.balance<<endl<<"Dia8esima kouponia:";
  865.             for(int i=0;i<ID.freebets.size();i++)
  866.             {   if(i!=ID.freebets.size())
  867.                     cout<<ID.freebets[i]<<",";
  868.                 else
  869.                     cout<<ID.freebets[i]<<endl;
  870.             }
  871.             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;
  872.             flag=1;
  873.             historyfun(history,"Account","-","-",ID.username,0.0);
  874.         }
  875.         void place(vector<Bethistory*> &bethistory,vector<History*> &history,string nodeid)
  876.         {   string choice;
  877.             string bet;
  878.             cout<<"Upoloipo portofoliou: "<<ID.balance<<endl;
  879.             cout<<"Dwse id h cancel gia akurwsh"<<endl;
  880.             getline(cin,choice);
  881.             if(choice.compare("cancel"));
  882.             {   stringstream buffer(choice);
  883.                 int i;
  884.                 buffer >> i;
  885.                 i--;
  886.                 ostringstream buffer2;
  887.                 buffer2<<i+1;
  888.                 choice.replace(choice.begin(),choice.end(),buffer2.str());
  889.                 nodeid.append(choice);
  890.                 nodeid.insert(nodeid.end(),'.');
  891.                 char x='a';
  892.                 for(int i=0;i<ID.freebets.size();i++)
  893.                 {   cout<<x++<<"."<<ID.freebets[i]<<endl;
  894.                 }
  895.                 cout << "Dwse poso stoixhmatos"<<endl;
  896.                 while (1)
  897.                 {   getline(cin,bet);
  898.                     if(bet[0]>='a' && bet[0]<x)
  899.                     {   int l=bet[0]-'a';
  900.                         bethistoryfun(bethistory,betid++,ID.user_id,nodeid,ID.freebets[l],'-');
  901.                         ID.freebets.erase(ID.freebets.begin()+l);
  902.                         break;
  903.                     }
  904.                     else if(isdigit(bet[0]))
  905.                     {   double bett=atof( bet.c_str());
  906.                         if(bett>ID.balance && ID.balance==0)
  907.                         {   cout<<"Mhdeniko upoloipo parakalw gemise to portofoli s apo to menou diaxeirhshs"<<endl;
  908.                             break;
  909.                         }
  910.                         else if(bett>ID.balance)
  911.                         {   cout<< "Dwse mikrotero poso"<<endl;
  912.                             continue;
  913.                         }
  914.                         else if(bett<=ID.balance)
  915.                         {   ID.balance-=bett;
  916.                             bethistoryfun(bethistory,betid++,ID.user_id,nodeid,bett,'-');
  917.                             historyfun(history,"bet",nodeid,"-",ID.username,bett);
  918.                             break;
  919.                         }
  920.                     }
  921.                     else
  922.                     {   cout<<"La8os epilogh"<<endl;
  923.                         break;
  924.                     }
  925.                 }
  926.  
  927.             }
  928.             flag=0;
  929.         }
  930.     private:
  931.         int flag;
  932. };
  933. class Trader:public Users
  934. {   public:
  935.         void bets(vector<Bethistory*> &bethistory,vector<History*> &history)
  936.         {   int l=0;
  937.             cout<< "bet_id | user_id | node_id | stake | result " << endl;
  938.             for (int i=0;i<bethistory.size();i++)
  939.             {   if (l++==20)
  940.                     break;
  941.                 cout << bethistory[i]->bet_id<< '\t' <<bethistory[i]->user_id<< '\t' <<bethistory[i]->node_id<< '\t' <<bethistory[i]->stake<< '\t' <<bethistory[i]->result<<endl;
  942.             }
  943.         }
  944.         void freebets(vector<Users*> &User,vector<History*> &history)
  945.         {   string name;
  946.             double x;
  947.             int flag=0,i;
  948.             while(1)
  949.             {   cout<<"Dwse onoma xrhsth"<<endl;
  950.                 getline(cin,name);
  951.                 for(i=0;i<User.size();i++)
  952.                 {   if(!User[i]->ID.username.compare(name))
  953.                     {   flag=1;
  954.                         break;
  955.                     }
  956.                 }
  957.                 if(flag==1)
  958.                     break;
  959.  
  960.             }
  961.             if(flag==1)
  962.             {   cout<<"Dwse poso kouponiou"<<endl;
  963.                 cin >> x;
  964.                 getline(cin,name);
  965.                 User[i]->ID.freebets.push_back(x);
  966.             }
  967.  
  968.         }
  969.         void Void(vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid);
  970.         void Settle(vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid);
  971.         void print()
  972.         {   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;
  973.         }
  974.         void exprint()
  975.         {   print();
  976.             cout<<"V(Void),gia na akurw8ei mia epilogh"<<endl<<"S(Settle),gia dieu8ethsh ths agoras"<<endl;
  977.         }
  978.  
  979. };
  980. class Director:public Users
  981. {   public:
  982.         void guide(root* &nodeid,string entoli)
  983.         {   int i;
  984.             stringstream buffer(entoli);
  985.             buffer>>i;
  986.             i--;
  987.             if(i<nodeid->Size())
  988.             {   nodeid=nodeid->notvisiblenode(i);
  989.             }
  990.             else
  991.             {   cout<<"Invalid input"<<endl;
  992.             }
  993.         }
  994.         void show(root* current_node)
  995.         {   current_node->show();
  996.         }
  997.         void bets(vector<Bethistory*> &bethistory,vector<History*> &history)
  998.         {   int l=0;
  999.             cout<< "bet_id | user_id | node_id | stake | result " << endl ;
  1000.             for (int i=0;i<bethistory.size();i++)
  1001.             {   if (l++==20)
  1002.                     break;
  1003.                 cout << bethistory[i]->bet_id<< '\t' <<bethistory[i]->user_id<< '\t' <<bethistory[i]->node_id<< '\t' <<bethistory[i]->stake<< '\t' <<bethistory[i]->result<<endl;
  1004.             }
  1005.             historyfun(history,"Bets","-","-",ID.username,0);
  1006.             flag=0;
  1007.         }
  1008.         void freebets(vector<Users*> &User,vector<History*> &history)
  1009.         {   string name;
  1010.             double x;
  1011.             int flag=0,i;
  1012.             while(1)
  1013.             {   cout<<"Dwse onoma xrhsth"<<endl;
  1014.                 getline(cin,name);
  1015.                 for(i=0;i<User.size();i++)
  1016.                 {   if(!User[i]->ID.username.compare(name))
  1017.                     {   flag=1;
  1018.                         break;
  1019.                     }
  1020.                 }
  1021.                 if(flag==1)
  1022.                     break;
  1023.  
  1024.             }
  1025.             if(flag==1)
  1026.             {   cout<<"Dwse poso kouponiou"<<endl;
  1027.                 cin >> x;
  1028.                 getline(cin,name);
  1029.                 User[i]->ID.freebets.push_back(x);
  1030.             }
  1031.  
  1032.         }
  1033.         int save(root* root,vector<Users*> &User,vector<History*> &history,vector <Bethistory*> &bethistory);
  1034.         int logs(vector<History*> &history)
  1035.         {   int l=0;
  1036.             for (int i=0;i<history.size();i++)
  1037.             {   if (l++==25)
  1038.                     break;
  1039.                 cout<<history[i]->username<<'\t'<<history[i]->operation<<'\t'<<history[i]->target<<'\t'<<history[i]->rename<<'\t'<<history[i]->money<<endl;
  1040.             }
  1041.             flag=0;
  1042.             return 1;
  1043.         }
  1044.         void users()
  1045.         {   cout<<"Epiloges:"<<endl<<"V(View),gia emfanish xrhstwn pinaka xrhstwn"<<endl<<"S(Search),gia anazhthsh xrhsth"<<endl<<"L(Lock,gia enallagh katastashs apokleismou"<<endl;
  1046.             flag=1;
  1047.         }
  1048.         void visibility(root* nodeid)
  1049.         {   nodeid->change_visibility();
  1050.             flag=0;
  1051.         }
  1052.         void Rename(vector<Users*> &User,vector<History*> &history,root* nodeid)
  1053.         {   nodeid->show();
  1054.             string choice;
  1055.             cout<<"Dwse id h cancel/abort gia akurwsh"<<endl;
  1056.             getline(cin,choice);
  1057.             if(isdigit(choice[0]))
  1058.             {   stringstream buffer(choice);
  1059.                 int i;
  1060.                 buffer >> i;
  1061.                 i--;
  1062.                 root* temp=nodeid->notvisiblenode(i);
  1063.                 cout<<"Dwse neo onoma h abort/cancel gia akurwsh"<<endl;
  1064.                 string rename;
  1065.                 getline(cin,rename);
  1066.                 string temp2;
  1067.                 temp2.assign(rename);
  1068.                 capitalow(&temp2);
  1069.                 if(temp2!="cancel"&& temp2!="abort" && temp2!="a" && temp2!="c")
  1070.                 {   temp->change_name(rename);
  1071.                 }
  1072.                 else
  1073.                     cout<<"Procedure aborted"<<endl;
  1074.             }
  1075.             else
  1076.             {   cout<<"Procedure aborted"<<endl;
  1077.             }
  1078.             flag=0;
  1079.         }
  1080.         void New(root *nodeid)
  1081.         {   nodeid->show();
  1082.             cout<<"Dwse neo onoma kombou h cancel/abort gia akurwsh"<<endl;
  1083.             string choice;
  1084.             getline(cin,choice);
  1085.             string temp=choice;
  1086.             capitalow(&temp);
  1087.             if(temp!="cancel"&& temp!="abort" && temp!="a" && temp!="c")
  1088.             {   nodeid->push(choice);      
  1089.             }
  1090.             else
  1091.                 cout<<"Procedure aborted"<<endl;
  1092.             flag=0;
  1093.         }
  1094.         void Copy(root* nodeid)
  1095.         {   cout << "Dwse  ID gia na ginei copy h cancel/abort gia akurwsh"<<endl;
  1096.             string choice;
  1097.             getline(cin,choice);
  1098.             if(isdigit(choice[0]))
  1099.             {   stringstream buffer(choice);
  1100.                 int i;
  1101.                 buffer >> i;
  1102.                 i--;
  1103.                 nodeid->copynode(i);
  1104.             }
  1105.             else
  1106.             {   cout<<"Procedure aborted"<<endl;
  1107.             }
  1108.             flag=0;
  1109.         }
  1110.         int Delete(root* nodeid)
  1111.         {   string choice;
  1112.             cout<<"Id kombou gia diagrafh"<<endl;
  1113.             getline (cin,choice);
  1114.             capitalow(&choice);
  1115.             if(isdigit(choice[0]))
  1116.             {   stringstream buffer(choice);
  1117.                 int i;
  1118.                 buffer >> i;
  1119.                 i--;
  1120.                 string choice2;
  1121.                 cout<<"Eisai sigouros? Y gia nai kai N gia oxi"<<endl;
  1122.                 getline(cin,choice2);
  1123.                 if (choice2[0]=='Y' || choice2[0]=='y')
  1124.                     nodeid->deletes(i);
  1125.                 else
  1126.                     cout<<"Aborted"<<endl;
  1127.             }
  1128.             else
  1129.                 cout<<"Aborted"<<endl;
  1130.             flag=0;
  1131.             return 1;
  1132.         }
  1133.         int view(vector <Users*> &User)
  1134.         {   if (flag==1)
  1135.             {   cout << "user_id | username | fullname | password | type | status | balance | freebets" << endl ;
  1136.                 for (int i=0;i<User.size();i++)
  1137.                 {   cout<< User[i]->ID.user_id<<'\t'<<User[i]->ID.username<<'\t'<<User[i]->ID.fullname<<'\t'<<User[i]->ID.password<<'\t'<<User[i]->ID.type<<'\t'<<User[i]->ID.status<<'\t'<<User[i]->ID.balance<<'\t';
  1138.                     for (int l=0;l<User[i]->ID.freebets.size();l++)
  1139.                     {   cout<< User[i]->ID.freebets[l];
  1140.                         if(l!=User[i]->ID.freebets.size()-1)
  1141.                             cout<<",";
  1142.                         else
  1143.                             cout << endl;
  1144.                     }
  1145.                 }
  1146.             }
  1147.             else
  1148.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  1149.             flag=0;
  1150.             return 2;
  1151.         }
  1152.         void search(vector <Users*> &User)
  1153.         {   if (flag==1)
  1154.             {   cout<<"Dwse onoma xrhsth h substring autou"<<endl;
  1155.                 string name;
  1156.                 getline(cin,name);
  1157.                 for(int i=0;i<User.size();i++)
  1158.                 {   if(User[i]->ID.username.find(name)!=User[i]->ID.username.npos)
  1159.                     {   cout<< User[i]->ID.user_id<<'\t'<<User[i]->ID.username<<'\t'<<User[i]->ID.fullname<<'\t'<<User[i]->ID.password<<'\t'<<User[i]->ID.type<<'\t'<<User[i]->ID.status<<'\t'<<User[i]->ID.balance<<'\t';
  1160.                         for (int l=0;l<User[i]->ID.freebets.size();l++)
  1161.                         {   cout<< User[i]->ID.freebets[l];
  1162.                             if(l!=User[i]->ID.freebets.size()-1)
  1163.                                 cout<<",";
  1164.                             else
  1165.                                 cout << endl;
  1166.                         }
  1167.                     }
  1168.                 }
  1169.  
  1170.             }
  1171.             else
  1172.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  1173.             flag=0;
  1174.         }
  1175.         void lock(vector<Users*> &User)
  1176.         {   if (flag==1)
  1177.             {   string name;
  1178.                 string name3;
  1179.                 int flag2=0,i;
  1180.                 cout<<"Dwse onoma"<<endl;
  1181.                 getline(cin,name);
  1182.                 for(i=0;i<User.size();i++)
  1183.                 {  
  1184.                     if(!User[i]->ID.username.compare(name) && User[i]->ID.type!=3)
  1185.                     {   if(User[i]->ID.status[0]!='L')
  1186.                         {   flag2=1;
  1187.                             cout<<"Anefere logo"<<endl;
  1188.                             getline(cin, name3);
  1189.                             string name2="L,";
  1190.                             User[i]->ID.status.replace(User[i]->ID.status.begin(),User[i]->ID.status.end(),name2);
  1191.                             User[i]->ID.status.insert(2,name3);
  1192.                             break;
  1193.                         }
  1194.                         else if(User[i]->ID.status[0]=='L')
  1195.                         {   flag2=1;
  1196.                             cout<<"Anefere logo"<<endl;
  1197.                             getline(cin, name3);
  1198.                             string temp="A,";
  1199.                             temp.append(name3);
  1200.                             User[i]->ID.status.replace(User[i]->ID.status.begin(),User[i]->ID.status.end(),temp);
  1201.                             break;
  1202.                         }
  1203.                     }
  1204.                 }
  1205.             }
  1206.             else
  1207.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  1208.             flag=0;
  1209.         }
  1210.         void print()
  1211.         {   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;
  1212.         }
  1213.         void exprint()
  1214.         {   print();
  1215.               }
  1216.     private:
  1217.         int flag;
  1218. };
  1219. void root::preprint(Users* current_user)
  1220. {   current_user->print();
  1221. }
  1222. int market::preplace(Users* current_user,vector <Bethistory*> &bethistory,vector <History*> &history)
  1223. {   current_user->place(bethistory,history,ID);
  1224.     return 1;
  1225. }
  1226. int market::prevoid(Users* current_user,vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid)
  1227. {   current_user->Void(User,bethistory,nodeid);
  1228.     return 1;
  1229. }
  1230. int market::presettle(Users* current_user,vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid)
  1231. {   current_user->Settle(User,bethistory,nodeid);
  1232.     return 2;
  1233. }
  1234. void market::preprint(Users* current_user)
  1235. {   current_user->exprint();
  1236. }
  1237.  
  1238.  
  1239.  
  1240. void write_users(vector<Users*>& User){
  1241.     remove("users.csv");
  1242.     ofstream file;
  1243.     file.open("users.csv",ios::out);
  1244.     file << "user_id | username | fullname | password | type | status | balance | freebets |" << endl ;
  1245.     int i,j;
  1246.     for(i=0;i<User.size();i++){
  1247.         file << User[i]->ID.user_id << "|" << User[i]->ID.username << "|" << User[i]->ID.fullname << "|";
  1248.         file << User[i]->ID.password << "|" << User[i]->ID.type << "|" << User[i]->ID.status << "|" << User[i]->ID.balance << "|";
  1249.         for(j=0;j<User[i]->ID.freebets.size();j++){
  1250.             file << User[i]->ID.freebets[j];
  1251.             if (j<User[i]->ID.freebets.size()-1){
  1252.                 file << ",";
  1253.             }
  1254.         }
  1255.         file << "|" <<endl;
  1256.     }
  1257.     file.close();
  1258. }
  1259.  
  1260. void write_history(vector <History*> &history){
  1261.     remove("audit.log");
  1262.     ofstream file;
  1263.     file.open("audit.log",ios::out);
  1264.     file << "username | operation | money | target | rename |"<<endl;
  1265.     for(int i=0;i<history.size();i++){
  1266.         file << history[i]->username << "|" << history[i]->operation << "|" << history[i]->money << "|" << history[i]->target << "|" << history[i]->rename << "|" <<endl;
  1267.     }
  1268.     file.close();
  1269. }
  1270.  
  1271. void write_bet(vector <Bethistory*> &bethistory){
  1272.     remove("bets.csv");
  1273.     ofstream file;
  1274.     file.open("bets.csv",ios::out);
  1275.     file << "bet_id | user_id | node_id | stake | result |" << endl ;
  1276.     for(int i=0;i<bethistory.size() ;i++){
  1277.         file << bethistory[i]->bet_id<< "|" << bethistory[i]->user_id << "|" << bethistory[i]->node_id << "|" << bethistory[i]->stake <<"|" << bethistory[i]->result <<"|" <<endl;
  1278.     }
  1279.     file.close();
  1280. }
  1281.  
  1282. void write_hierarchy(root* Root)
  1283. {   remove("hierarchy.dat.txt");
  1284.     ofstream file;
  1285.     file.open("hierarchy.dat.txt",ios::out);
  1286.     Root->write(file);
  1287.     file.close();
  1288. }
  1289.  
  1290. int Director::save(root* root,vector<Users*> &User,vector<History*> &history,vector <Bethistory*> &bethistory)
  1291. {   write_users(User);
  1292.     write_history(history);
  1293.     write_bet(bethistory);
  1294.     write_hierarchy(root);
  1295.     cout<<"Ta arxeia enhmerw8hkan"<<endl;
  1296.     return 1;
  1297. }
  1298.  
  1299.  
  1300. void read_hierarchy(root* Root){
  1301.     vector <root*> hierarchy2;
  1302.     vector <root*> hierarchy3;
  1303.     vector <root*> hierarchy4;
  1304.     vector <root*> hierarchy5;
  1305.     ifstream file;
  1306.     file.open("hierarchy.dat.txt",ios::in);
  1307.     if(file.fail()){
  1308.         cerr << "Error openning file" << endl;
  1309.         exit(1);
  1310.     }
  1311.     string line;
  1312.     while(getline(file,line)){
  1313.         const char s[2]=" ";
  1314.         const char d[2]="\n";
  1315.         char* token;
  1316.         //converting string to char*
  1317.         char *str = new char[line.length() + 1];
  1318.         strcpy(str, line.c_str());
  1319.         //
  1320.         token = strtok(str,s);  
  1321.         string node(token);
  1322.         size_t n = count(node.begin(), node.end(), '.'); // number of dots
  1323.         token = strtok(NULL, d); //oti apomenei meta to node
  1324.        
  1325.         if(n == 1)
  1326.         {   category* temp=new category(token,node);
  1327.             Root->readh(temp);
  1328.             hierarchy2.push_back(temp);
  1329.         }
  1330.         if(n==2){
  1331.             subcategory* temp=new subcategory(token,node);
  1332.             hierarchy2[hierarchy2.size()-1]->readh(temp);
  1333.             hierarchy3.push_back(temp);
  1334.         }
  1335.         if(n == 3){
  1336.             strcpy(str,token); //str = token
  1337.             const char h[2] = "|";
  1338.             char* n;
  1339.             char* date;
  1340.             char* time;
  1341.             n = strtok(str,h);
  1342.             date=strtok(NULL,h); //date
  1343.             time = strtok(NULL,d);
  1344.             event* temp=new event(n,node,date,time);
  1345.             hierarchy3[hierarchy3.size()-1]->readh(temp);
  1346.             hierarchy4.push_back(temp);
  1347.            
  1348.         }
  1349.         if(n == 4){
  1350.             market* temp=new market(token,node);
  1351.             hierarchy4[hierarchy4.size()-1]->readh(temp);
  1352.             hierarchy5.push_back(temp);
  1353.         }
  1354.         if(n == 5){
  1355.             strcpy(str,token); //str = token
  1356.             const char h[2] = "#";
  1357.             char* n;
  1358.             n = strtok(str,h);
  1359.             token = strtok(NULL,h); //price
  1360.             selection* temp=new selection(n,node,token);
  1361.             hierarchy5[hierarchy5.size()-1]->readh(temp);
  1362.         }
  1363.     }
  1364. }
  1365.  
  1366.  
  1367. void read_users(vector<Users*> &User){
  1368.     ifstream file;
  1369.     file.open("users.csv",ios::in);
  1370.     if(file.fail()){
  1371.         cerr << "Error openning file" << endl;
  1372.         exit(1);
  1373.     }
  1374.     string line;
  1375.     getline(file,line);
  1376.     //pairnw to prwto line to arxeiasto me ta userid username ktl kai de to xrhsimopoiw
  1377.     while(getline(file,line)){
  1378.         //exw twra to line pou me | exei ola ta stoixeia
  1379.         const char s[2]="|";
  1380.         char* token;
  1381.         Users temp;
  1382.         //converting string to char*
  1383.         char *str = new char[line.length() + 1];
  1384.         strcpy(str, line.c_str());
  1385.         //
  1386.         token = strtok(str,s);
  1387.         temp.ID.user_id = atoi(token); //(kanw to char* int)
  1388.         token = strtok(NULL, s);
  1389.         temp.ID.username = token;
  1390.         token = strtok(NULL, s);
  1391.         temp.ID.fullname = token;
  1392.         token = strtok(NULL, s);
  1393.         temp.ID.password = token;
  1394.         token = strtok(NULL, s);
  1395.         temp.ID.type = atoi(token); //kanw to char* int
  1396.         token = strtok(NULL, s);
  1397.         temp.ID.status =token;
  1398.         token = strtok(NULL, s);
  1399.         temp.ID.balance = atof(token); //kanw char* float
  1400.         token = strtok(NULL, s);
  1401.         //twra to token einai san ena char* kai prepei pali na to kopsw me delimeter to ,
  1402.         char* token2;
  1403.         const char d[2]=",";
  1404.         token2=strtok(token,d);
  1405.         while(token2 != NULL){
  1406.             temp.ID.freebets.push_back(atof(token2)); //char* to float
  1407.             token2 = strtok(NULL, d);
  1408.         }
  1409.         if(temp.ID.type==1){  
  1410.             User.push_back(new Punter());
  1411.         }
  1412.         else if(temp.ID.type==2){  
  1413.             User.push_back(new Trader());
  1414.         }
  1415.         else{  
  1416.             User.push_back(new Director());
  1417.         }
  1418.         int i=User.size()-1;
  1419.         User[i]->ID.user_id=temp.ID.user_id;
  1420.         User[i]->ID.username.assign(temp.ID.username);
  1421.         User[i]->ID.fullname.assign(temp.ID.fullname);
  1422.         User[i]->ID.password.assign(temp.ID.password);
  1423.         User[i]->ID.type=temp.ID.type;
  1424.         User[i]->ID.status.assign(temp.ID.status);
  1425.         User[i]->ID.balance=temp.ID.balance;
  1426.         for(int l=0;l<temp.ID.freebets.size();l++)
  1427.         {   User[i]->ID.freebets.push_back(temp.ID.freebets[l]);
  1428.         }
  1429.     }
  1430.    
  1431.     //etoimo to User
  1432.     file.close();
  1433. }
  1434.  
  1435. void read_history(vector <History*> &history){
  1436.     ifstream file;
  1437.     file.open("audit.log",ios::in);
  1438.     if(file.fail()){
  1439.         cerr << "Error openning file" << endl;
  1440.         exit(1);
  1441.     }
  1442.     string line;
  1443.     getline(file,line);
  1444.     while(getline(file,line)){
  1445.         const char s[2]="|";
  1446.         char* token;
  1447.         History temp;
  1448.         //converting string to char*
  1449.         char *str = new char[line.length() + 1];
  1450.         strcpy(str, line.c_str());
  1451.         //
  1452.         token = strtok(str,s);
  1453.         temp.username = token;
  1454.         token = strtok(NULL, s);
  1455.         temp.operation = token;
  1456.         token = strtok(NULL, s);
  1457.         temp.money = atof(token);
  1458.         token = strtok(NULL, s);
  1459.         temp.target =token;
  1460.         token = strtok(NULL, s);
  1461.         temp.rename =token;
  1462.         //
  1463.         history.push_back(new History());
  1464.         int i = history.size()-1;
  1465.         //
  1466.         history[i]->username.assign(temp.username);
  1467.         history[i]->operation.assign(temp.operation);
  1468.         history[i]->target.assign(temp.target);
  1469.         history[i]->rename.assign(temp.rename);
  1470.         history[i]->money = temp.money;
  1471.         //
  1472.     }
  1473.     file.close();
  1474. }
  1475.  
  1476. void read_bet(vector <Bethistory*> &bethistory){
  1477.     ifstream file;
  1478.     file.open("bets.csv",ios::in);
  1479.     if(file.fail()){
  1480.         cerr << "Error openning file" << endl;
  1481.         exit(1);
  1482.     }
  1483.     string line;
  1484.     getline(file,line);
  1485.     while(getline(file,line)){
  1486.         const char s[2]="|";
  1487.         char* token;
  1488.         Bethistory temp;
  1489.         //converting string to char*
  1490.         char *str = new char[line.length() + 1];
  1491.         strcpy(str, line.c_str());
  1492.         //
  1493.         token = strtok(str,s);
  1494.         temp.bet_id = atoi(token);
  1495.         token = strtok(NULL, s);
  1496.         temp.user_id = atoi(token);
  1497.         token = strtok(NULL, s);
  1498.         temp.node_id = token;
  1499.         token = strtok(NULL, s);
  1500.         temp.stake = atof(token);
  1501.         token = strtok(NULL, s);
  1502.         temp.result = token[0];
  1503.         token = strtok(NULL, s);
  1504.         //
  1505.         bethistory.push_back(new Bethistory());
  1506.         int i = bethistory.size()-1;
  1507.         //
  1508.         bethistory[i]->bet_id = temp.bet_id;
  1509.         bethistory[i]->user_id = temp.user_id;
  1510.         bethistory[i]->node_id.assign(temp.node_id);
  1511.         bethistory[i]->stake = temp.stake;
  1512.         bethistory[i]->result= temp.result;
  1513.         //
  1514.     }
  1515.     file.close();
  1516. }
  1517.  
  1518. void management_input(Users* currentUser,vector<Users*> &User, vector<History*> &history, vector<Bethistory*> &bethistory, vector<root*> &Root){
  1519.     while(1){
  1520.         root* current_node;
  1521.         int i=Root.size()-1;
  1522.         current_node = Root[i];
  1523.         current_node->preprint(currentUser);
  1524.         for(int l=0;l<Root.size();l++)
  1525.         {   cout<<Root[l]->get_name()<<'/';
  1526.         }
  1527.         cout<<endl;
  1528.         currentUser->show(current_node);
  1529.        
  1530.         string entoli;
  1531.         getline(cin,entoli);
  1532.         if(isdigit(entoli[0])){
  1533.             currentUser->guide(current_node,entoli);
  1534.             if(Root[i]->get_name().compare(current_node->get_name()))
  1535.             {   Root.push_back(current_node);
  1536.             }
  1537.         }
  1538.         else{
  1539.             int check =0;
  1540.             capitalow(&entoli);
  1541.             if(entoli.size() > 1){
  1542.                 check = 1;
  1543.             }
  1544.             char ent;
  1545.             ent=entoli[0]; 
  1546.             if(ent == 'a'){
  1547.                 if(check){
  1548.                     if(entoli.compare("account") == 0){
  1549.                         currentUser->account(history);
  1550.                     }
  1551.                 }
  1552.                 else{
  1553.                     currentUser->account(history);
  1554.                 }
  1555.             }
  1556.             if(ent == 'b'){
  1557.                 if(check){
  1558.                     if(entoli.compare("bets") == 0){
  1559.                         currentUser->bets(bethistory,history);
  1560.                     }
  1561.                 }
  1562.                 else{
  1563.                     currentUser->bets(bethistory,history);
  1564.                 }
  1565.             }
  1566.             if(ent == 'c'){
  1567.                 if(check){
  1568.                     if(entoli.compare("copy") == 0){
  1569.                         currentUser->Copy(current_node);    // copy
  1570.                     }
  1571.                 }
  1572.                 else{
  1573.                     currentUser->Copy(current_node);
  1574.                 }
  1575.             }
  1576.             if(ent == 'd'){
  1577.                 if(check){
  1578.                     if(entoli.compare("delete") == 0){
  1579.                         currentUser->Delete(current_node);
  1580.                     }
  1581.                     else if (entoli.compare("deposit") == 0){
  1582.                         currentUser->deposit(history);
  1583.                     }
  1584.                 }
  1585.                 else{
  1586.                     int i;
  1587.                     i=currentUser->Delete(current_node); //an den ginetai ,deposit
  1588.                     if(i == 0){
  1589.                         currentUser->deposit(history);
  1590.                     }              
  1591.                 }
  1592.             }
  1593.             if(ent == 'f'){
  1594.                 if(check){
  1595.                     if(entoli.compare("freebets") == 0){
  1596.                         currentUser->freebets(User,history);
  1597.                     }
  1598.                 }
  1599.                 else{
  1600.                     currentUser->freebets(User,history);
  1601.                 }
  1602.             }
  1603.             if(ent == 'h'){
  1604.                 if(check){
  1605.                     if(entoli.compare("home") == 0){
  1606.                         currentUser->home(Root,current_node);
  1607.                     }
  1608.                 }
  1609.                 else{
  1610.                     currentUser->home(Root,current_node);
  1611.                 }
  1612.             }
  1613.             if(ent == 't'){
  1614.                 if(check){
  1615.                     if(entoli.compare("toggle") == 0){
  1616.                         currentUser->toggle();
  1617.                     }
  1618.                 }
  1619.                 else{
  1620.                     currentUser->toggle();
  1621.                 }
  1622.             }
  1623.             if(ent == 'x'){
  1624.                 if(check){
  1625.                     if(entoli.compare("exit") == 0){
  1626.                         write_users(User);
  1627.                         write_history(history);
  1628.                         write_bet(bethistory);
  1629.                         write_hierarchy(Root[0]);
  1630.                         exit(2);
  1631.                     }
  1632.                 }
  1633.                 else{
  1634.                     write_users(User);
  1635.                     write_history(history);
  1636.                     write_bet(bethistory);
  1637.                     write_hierarchy(Root[0]);
  1638.                     exit(2);
  1639.                 }
  1640.             }
  1641.             if(ent == 's'){
  1642.                 if(check){
  1643.                     if(entoli.compare("save") == 0){
  1644.                         currentUser->save(current_node,User,history,bethistory);
  1645.                     }
  1646.                     else if(entoli.compare("settle") == 0){
  1647.                         current_node->presettle(currentUser,User,bethistory,current_node);
  1648.                     }
  1649.                     else if(entoli.compare("search") == 0){
  1650.                         currentUser->search(User);
  1651.                     }
  1652.                 }
  1653.                 else{
  1654.                     int i;
  1655.                     i=currentUser->save(current_node,User,history,bethistory);
  1656.                     if(i == 0){
  1657.                         int j;
  1658.                         j=current_node->presettle(currentUser,User,bethistory,current_node);
  1659.                         if(j==0){
  1660.                             currentUser->search(User);
  1661.                         }
  1662.                     }
  1663.                 }
  1664.             }
  1665.             if(ent == 'l'){
  1666.                 if(check){
  1667.                     if(entoli.compare("logs") == 0){
  1668.                         currentUser->logs(history);
  1669.                     }
  1670.                     else if(entoli.compare("lock") == 0){
  1671.                         currentUser->lock(User);
  1672.                     }
  1673.                 }
  1674.                 else{
  1675.                     int i;
  1676.                     i=currentUser->logs(history);
  1677.                     if(i == 0){
  1678.                         currentUser->lock(User);
  1679.                     }
  1680.                 }
  1681.             }
  1682.             if(ent == 'u'){
  1683.                 if(check){
  1684.                     if(entoli.compare("users") == 0){
  1685.                         currentUser->users();
  1686.                     }
  1687.                 }
  1688.                 else{
  1689.                     currentUser->users();
  1690.                 }
  1691.             }
  1692.            
  1693.             if(ent == 'r'){
  1694.                 if(check){
  1695.                     if(entoli.compare("rename") == 0){
  1696.                         currentUser->Rename(User,history,current_node);
  1697.                     }
  1698.                 }
  1699.                 else{
  1700.                     currentUser->Rename(User,history,current_node);
  1701.                 }
  1702.             }
  1703.             if(ent == 'n'){
  1704.                 if(check){
  1705.                     if(entoli.compare("new") == 0){
  1706.                         currentUser->New(current_node);
  1707.                     }
  1708.                 }
  1709.                 else{
  1710.                     currentUser->New(current_node);
  1711.                 }
  1712.             }
  1713.            
  1714.             if(ent == 'p'){
  1715.                 if(check){
  1716.                     if(entoli.compare("place") == 0){
  1717.                         current_node->preplace(currentUser,bethistory,history);
  1718.                     }
  1719.                     else if(entoli.compare("password") == 0){
  1720.                         currentUser->password(history);
  1721.                     }
  1722.                 }
  1723.                 else{
  1724.                     int i;
  1725.                     i=current_node->preplace(currentUser,bethistory,history);
  1726.                     if(i==0){
  1727.                         currentUser->password(history);
  1728.                     }
  1729.                 }
  1730.             }
  1731.             if(ent == 'v'){
  1732.                 if(check){
  1733.                     if(entoli.compare("void") == 0){
  1734.                         current_node->prevoid(currentUser,User,bethistory,current_node);
  1735.                     }
  1736.                     else if(entoli.compare("view") == 0){
  1737.                         currentUser->view(User);
  1738.                     }
  1739.                     else if(entoli.compare("visibility") == 0){
  1740.                         currentUser->visibility(current_node);
  1741.                     }
  1742.                 }
  1743.                 else{
  1744.                     int i;
  1745.                     i=current_node->prevoid(currentUser,User,bethistory,current_node);
  1746.                     if(i==0){
  1747.                         int j;
  1748.                         j=currentUser->view(User);
  1749.                         if(j==0){
  1750.                             currentUser->visibility(current_node);
  1751.                         }
  1752.                     }
  1753.                 }
  1754.             }
  1755.         }
  1756.     }
  1757. }
  1758.  
  1759. void register_user(vector<Users*> &User,Users* current_user,vector<History*> &history,vector<Bethistory*> &bethistory,vector<root*> Root){
  1760.     int redo;
  1761.     string name;
  1762.     do{
  1763.         redo=0;
  1764.         cout << "username: ";
  1765.         getline (cin, name);
  1766.         for(int i=0;i<User.size();i++){
  1767.             if(name.compare(User[i]->ID.username) == 0){
  1768.                 cout << "This name already exists please type a different name!" << endl;
  1769.                 redo = 1;
  1770.             }
  1771.             if(name.compare("\n") == 0 || name.compare("guest:guest")==0){
  1772.                 cout << "forbidden name,please type a different name" << endl;
  1773.                 redo=1;
  1774.             }
  1775.         }
  1776.     }while(redo);
  1777. //
  1778.     User.push_back(new Punter);
  1779.     int i = User.size()-1;
  1780.     User[i]->ID.user_id = i+1;
  1781.     User[i]->ID.username.assign(name);
  1782.     User[i]->ID.fullname.assign(name); // this could be changed later in the account settings
  1783.     User[i]->ID.type = 1;
  1784.     User[i]->ID.status.assign("A");
  1785.     User[i]->ID.balance = 0.0;
  1786.     User[i]->ID.freebets.push_back(0.0); //
  1787.     do{
  1788.         redo=0;
  1789.         cout << "password: ";
  1790.         string pass1;
  1791.         getline (cin,pass1);
  1792.         cout << "Please retype your password:" ;
  1793.         string pass2;
  1794.         getline (cin,pass2);
  1795.         if (pass1.compare(pass2) != 0){
  1796.             cout << "You should insert the same password twice" << endl;
  1797.             redo=1;
  1798.         }
  1799.         else{
  1800.             User[i]->ID.password.assign(pass1);
  1801.         }
  1802.     }while(redo);
  1803.     write_users(User);  //arxeio susthmatos save
  1804.     current_user = User[i];
  1805.     management_input(current_user,User,history,bethistory,Root);
  1806. }
  1807. void Trader::Settle(vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid)
  1808.     {   cout<<"Dwse to id ths epiloghs stoixhmatismou p 8es na 8ewrh8ei ws nikh"<<endl;
  1809.     string choice;
  1810.     getline(cin,choice);
  1811.     if(isdigit(choice[0]))
  1812.     {   stringstream buffer(choice);
  1813.         int i;
  1814.         buffer >> i;
  1815.         i--;
  1816.         string id=nodeid->voidd(i);
  1817.         root* temp;
  1818.         temp=nodeid->visiblenode(i);
  1819.         string token;
  1820.         double price;
  1821.         price=temp->get_price2();
  1822.         for(int l=0;l<bethistory.size();l++)
  1823.         {   if(!(id.compare(bethistory[l]->node_id)))
  1824.             {   if(bethistory[l]->result=='-')
  1825.                 {   bethistory[l]->result='W';
  1826.                     for(int j=0;j<User.size();j++)
  1827.                     {   if(bethistory[l]->user_id==User[j]->ID.user_id)
  1828.                         {   User[j]->ID.balance+=bethistory[l]->stake*price;
  1829.                         }
  1830.                     }
  1831.                 }
  1832.                 else
  1833.                 {   cout<<"Already changed"<<endl;
  1834.                     break;
  1835.                 }
  1836.             }
  1837.         }
  1838.         string lose_id;
  1839.         lose_id.assign(id);
  1840.         lose_id.erase(lose_id.size()-1);
  1841.         lose_id.erase(lose_id.size()-1);
  1842.         for(int l=0;l<bethistory.size();l++)
  1843.         {   if(bethistory[l]->node_id!=id && bethistory[l]->node_id.find(lose_id)!=bethistory[l]->node_id.npos && bethistory[l]->result=='-')
  1844.             {   bethistory[l]->result='L';
  1845.             }
  1846.         }
  1847.         //enhmerwsh arxeiwn xrhstwn kai bet
  1848.         write_users(User);
  1849.         write_bet(bethistory);
  1850.     }
  1851.     else
  1852.     {   cout<<"Operation aborted wrong input"<<endl;
  1853.     }
  1854. }
  1855.  
  1856.  
  1857. void Trader::Void(vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid)
  1858.     {   cout<<"Dwse to id ths epiloghs stoixhmatismou p 8es na akurw8ei"<<endl;
  1859.     string choice;
  1860.     getline(cin,choice);
  1861.     if(isdigit(choice[0]))
  1862.     {   stringstream buffer(choice);
  1863.         int i;
  1864.         buffer >> i;
  1865.         i--;
  1866.         string id=nodeid->voidd(i);
  1867.         for(int l=0;l<bethistory.size();l++)
  1868.         {   if(!(id.compare(bethistory[l]->node_id)))
  1869.             {   if(bethistory[l]->result=='-')
  1870.                 {   bethistory[l]->result='V';
  1871.                     for(int j=0;j<User.size();j++)
  1872.                     {   if(bethistory[l]->user_id==User[j]->ID.user_id)
  1873.                         {   User[j]->ID.balance+=bethistory[l]->stake;
  1874.                         }
  1875.                     }
  1876.                 }
  1877.                 else
  1878.                 {   cout<<"Already voided"<<endl;
  1879.                     break;
  1880.                 }
  1881.             }
  1882.         }
  1883.         //enhmerwsh arxeiwn xrhstwn kai bet
  1884.         write_users(User);
  1885.         write_bet(bethistory);
  1886.     }
  1887.     else
  1888.     {   cout<<"Operation aborted wrong input"<<endl;
  1889.     }
  1890. }
  1891. void login_user(vector<Users*> User,Users* current_user,vector<History*> &history,vector<Bethistory*> &bethistory,vector<root*> Root){
  1892.     cout << "Welcome to KAPPA BET!" << endl;
  1893.     cout << "Please type username and password to login to your account!" << endl;
  1894.     cout << "If you don't have an account ,press (Enter) or type guest:guest to login as guest" << endl;
  1895.     int anagnwr=-1;
  1896.     int guest=0;
  1897.     int redo;
  1898.     do{
  1899.         redo=0;
  1900.         cout << "username: " ;
  1901.         string name;
  1902.         string rightpass;
  1903.         getline(cin,name);
  1904.         if (name.size()==0)
  1905.             name.assign("\n");
  1906.         if((name.compare("guest:guest") == 0) || name.compare("\n")==0){
  1907.             guest = 1;
  1908.             break;
  1909.         }
  1910.         for(int i=0;i<User.size();i++){
  1911.             if(name.compare(User[i]->ID.username) == 0){
  1912.                 rightpass.assign(User[i]->ID.password);
  1913.                 anagnwr=i;
  1914.             }
  1915.         }
  1916.         string provpass;
  1917.         cout << "password: ";
  1918.         getline(cin,provpass);
  1919.         if(provpass.size()==0)
  1920.             provpass.assign("\n");
  1921.         if(provpass.compare(rightpass) == 0){
  1922.             redo=0;
  1923.         }
  1924.         else{
  1925.             cout << "Wrong Credentials! Please Retry!" << endl;
  1926.             redo=1;
  1927.         }
  1928.     }while(redo);
  1929.     if(guest == 0){
  1930.         char locked = 'L';
  1931.         if(locked == User[anagnwr]->ID.status[0]){
  1932.             cout << "Your account has been locked due to: ";
  1933.             for(int i=2;i<User[anagnwr]->ID.status.size();i++){
  1934.                 cout << User[anagnwr]->ID.status[i];
  1935.             }
  1936.             exit(1);
  1937.         }  
  1938.     }
  1939.     //eisodos xrhsth sto arxiko menu analoga me to user.type h an einai guest
  1940.     if(guest == 1){
  1941.         Users* temp = new Guest();
  1942.         //gurnaw
  1943.         current_user = temp;
  1944.        
  1945.     }
  1946.     else{
  1947.         current_user = User[anagnwr];
  1948.     }
  1949.     write_users(User);
  1950.     management_input(current_user,User,history,bethistory,Root);
  1951. }
  1952.  
  1953. int main(int argc, char** argv) {
  1954.     cout.precision(2);
  1955.     vector<Users*> User;
  1956.     vector<History*> history;
  1957.     vector<Bethistory*> bethistory;
  1958.     vector<root*> Root;
  1959.     Root.push_back(new root());
  1960.     read_history(history);
  1961.     read_users(User);
  1962.     read_hierarchy(Root[0]);
  1963.     read_bet(bethistory);
  1964.     Users* currentUser;
  1965.     if (argc == 1){
  1966.         //xwris parameters
  1967.         login_user(User, currentUser , history , bethistory , Root);
  1968.     }
  1969.     else if(argc == 2){
  1970.         //mia parametros
  1971.         string parameter(argv[1]);
  1972.         capitalow(&parameter);
  1973.         if(strcmp(parameter.c_str(),"-r") == 0){
  1974.             //register a user
  1975.             register_user(User,currentUser,history,bethistory,Root);
  1976.         }
  1977.     }
  1978.     return 0;
  1979. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement