Advertisement
Guest User

Untitled

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