Advertisement
Guest User

Untitled

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