Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 52.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <fstream>
  6. #include <algorithm>
  7. #include <sstream>
  8. #include <stdio.h>
  9. #include <ctype.h>
  10. using namespace std;
  11. int betid=1;
  12. int ctoggle=1;
  13. 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 void preplace(Users& current_user,vector <Bethistory*> bethistory,vector <History*> history)
  163.     {   cout<<"Den exeis prosbash se authn thn entolh apo auton ton kombo" <<endl;
  164.     }
  165.     virtual void prevoid(Users& current_user,vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid)
  166.     {   cout<<"Den exeis prosbash se authn thn entolh apo auton ton kombo" <<endl;
  167.     }
  168.     virtual void presettle(Users& current_user,vector <Users*> &User,vector <Bethistory*> &bethistory,root* nodeid)
  169.     {   cout<<"Den exeis prosbash se authn thn entolh apo auton ton kombo" <<endl;
  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.     void preplace(Users& current_user,vector <Bethistory*> bethistory,vector <History*> history);
  364.     void prevoid(Users& current_user,vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid);
  365.     void 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 void save(root* root,vector<Users*> &User,vector<History*> &history,vector <Bethistory*> &bethistory)
  594.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  595.         }
  596.         virtual void logs(vector<History*> &history)
  597.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  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 void Delete(root* nodeid,int i)
  612.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  613.         }
  614.         virtual void view(vector <Users*> &User)
  615.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  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.         void save(root* root,vector<Users*> &User,vector<History*> &history,vector <Bethistory*> &bethistory);
  958.         void 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.         }
  967.         void users()
  968.         {   cout<<"Epiloges:"<<endl<<"V(View),gia emfanish xrhstwn pinaka xrhstwn"<<endl<<"S(Search),gia anazhthsh xrhsth"<<endl<<"L(Lock,gia enallagh katastashs apokleismou"<<endl;
  969.             flag=1;
  970.         }
  971.         void visibility(root* nodeid)
  972.         {   nodeid->change_visibility();
  973.             flag=0;
  974.         }
  975.         void Rename(vector<Users*> &User,vector<History*> &history,root* nodeid)
  976.         {   nodeid->show();
  977.             string choice;
  978.             cout<<"Dwse id h cancel/abort gia akurwsh"<<endl;
  979.             if(isdigit(choice[0]))
  980.             {   stringstream buffer(choice);
  981.                 int i;
  982.                 buffer >> i;
  983.                 i--;
  984.                 root* temp=nodeid->notvisiblenode(i);
  985.                 cout<<"Dwse neo onoma h abort/cancel gia akurwsh"<<endl;
  986.                 string rename;
  987.                 string temp2=rename;
  988.                 capitalow(&temp2);
  989.                 if(temp2!="cancel"&& temp2!="abort" && temp2!="a" && temp2!="c")
  990.                 {   temp->change_name(rename);
  991.                 }
  992.                 else
  993.                     cout<<"Procedure aborted"<<endl;
  994.             }
  995.             else
  996.             {   cout<<"Procedure aborted"<<endl;
  997.             }
  998.             flag=0;
  999.         }
  1000.         void New(root *nodeid)
  1001.         {   nodeid->show();
  1002.             cout<<"Dwse neo onoma kombou h cancel/abort gia akurwsh"<<endl;
  1003.             string choice;
  1004.             getline(cin,choice);
  1005.             string temp=choice;
  1006.             capitalow(&temp);
  1007.             if(temp!="cancel"&& temp!="abort" && temp!="a" && temp!="c")
  1008.             {   nodeid->push(choice);      
  1009.             }
  1010.             else
  1011.                 cout<<"Procedure aborted"<<endl;
  1012.             flag=0;
  1013.         }
  1014.         virtual void Copy(root* nodeid)
  1015.         {   cout << "Dwse  ID gia na ginei copy h cancel/abort gia akurwsh";
  1016.             string choice;
  1017.             getline(cin,choice);
  1018.             if(isdigit(choice[0]))
  1019.             {   stringstream buffer(choice);
  1020.                 int i;
  1021.                 buffer >> i;
  1022.                 i--;
  1023.                 nodeid->copynode(i);
  1024.             }
  1025.             else
  1026.             {   cout<<"Procedure aborted"<<endl;
  1027.             }
  1028.             flag=0;
  1029.         }
  1030.         void Delete(root* nodeid,int i)
  1031.         {   i--;
  1032.             nodeid->deletes(i);
  1033.             flag=0;
  1034.         }
  1035.         void view(vector <Users*> &User)
  1036.         {   if (flag==1)
  1037.             {   cout << "user_id | username | fullname | password | type | status | balance | freebets" << endl ;
  1038.                 for (int i=0;i<User.size();i++)
  1039.                 {   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';
  1040.                     for (int l=0;l<User[i]->ID.freebets.size();l++)
  1041.                     {   cout<< User[i]->ID.freebets[l];
  1042.                         if(l!=User[i]->ID.freebets.size()-1)
  1043.                             cout<<",";
  1044.                         else
  1045.                             cout << endl;
  1046.                     }
  1047.                 }
  1048.             }
  1049.             else
  1050.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  1051.             flag=0;
  1052.         }
  1053.         void search(vector <Users*> &User)
  1054.         {   if (flag==1)
  1055.             {   string name;
  1056.                 getline(cin,name);
  1057.                 for(int i=0;i<User.size();i++)
  1058.                 {   if(User[i]->ID.username.find(name)!=User[i]->ID.username.npos)
  1059.                     {   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';
  1060.                         for (int l=0;l<User[i]->ID.freebets.size();l++)
  1061.                         {   cout<< User[i]->ID.freebets[l];
  1062.                             if(l!=User[i]->ID.freebets.size()-1)
  1063.                                 cout<<",";
  1064.                             else
  1065.                                 cout << endl;
  1066.                         }
  1067.                     }
  1068.                 }
  1069.  
  1070.             }
  1071.             else
  1072.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  1073.             flag=0;
  1074.         }
  1075.         void lock(vector<Users*> &User)
  1076.         {   if (flag==1)
  1077.             {   string name;
  1078.                 string name3;
  1079.                 int flag2=0,i;
  1080.                 getline(cin,name);
  1081.                 for(i=0;i<User.size();i++)
  1082.                 {  
  1083.                     if(!User[i]->ID.username.compare(name) && User[i]->ID.type!=3)
  1084.                     {   if(User[i]->ID.status[0]!='L')
  1085.                         {   flag2=1;
  1086.                             cout<<"Anefere logo"<<endl;
  1087.                             getline(cin, name3);
  1088.                             string name2="L,";
  1089.                             User[i]->ID.status.replace(User[i]->ID.status.begin(),User[i]->ID.status.end(),name2);
  1090.                             User[i]->ID.status.insert(2,name3);
  1091.                             break;
  1092.                         }
  1093.                         else if(User[i]->ID.status[0]=='L')
  1094.                         {   flag2=1;
  1095.                             cout<<"Anefere logo"<<endl;
  1096.                             getline(cin, name3);
  1097.                             User[i]->ID.status.replace(User[i]->ID.status.begin(),User[i]->ID.status.end(),name3);
  1098.                             break;
  1099.                         }
  1100.                     }
  1101.                 }
  1102.             }
  1103.             else
  1104.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  1105.             flag=0;
  1106.         }
  1107.         void print()
  1108.         {   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;
  1109.         }
  1110.         void exprint()
  1111.         {   print();
  1112.               }
  1113.     private:
  1114.         int flag;
  1115. };
  1116. void root::preprint(Users& current_user)
  1117. {   current_user.print();
  1118. }
  1119. void market::preplace(Users& current_user,vector <Bethistory*> bethistory,vector <History*> history)
  1120. {   current_user.place(bethistory,history,ID);
  1121. }
  1122. void market::prevoid(Users& current_user,vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid)
  1123. {   current_user.Void(User,bethistory,nodeid);
  1124. }
  1125. void market::presettle(Users& current_user,vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid)
  1126. {   current_user.Settle(User,bethistory,nodeid);
  1127. }
  1128. void market::preprint(Users& current_user)
  1129. {   current_user.exprint();
  1130. }
  1131.  
  1132.  
  1133.  
  1134. void write_users(vector<Users*>& User){
  1135.     remove("users.csv");
  1136.     ofstream file;
  1137.     file.open("users.csv",ios::out);
  1138.     file << "user_id | username | fullname | password | type | status | balance | freebets" << endl ;
  1139.     int i,j;
  1140.     for(i=0;i<User.size();i++){
  1141.         file << User[i]->ID.user_id << "|" << User[i]->ID.username << "|" << User[i]->ID.fullname << "|";
  1142.         file << User[i]->ID.password << "|" << User[i]->ID.type << "|" << User[i]->ID.status << "|" << User[i]->ID.balance << "|";
  1143.         for(j=0;j<User[i]->ID.freebets.size();j++){
  1144.             file << User[i]->ID.freebets[j];
  1145.             if (j<User[i]->ID.freebets.size()-1){
  1146.                 file << ",";
  1147.             }
  1148.         }
  1149.         file << endl;
  1150.     }
  1151.     file.close();
  1152. }
  1153.  
  1154. void write_history(vector <History*> &history){
  1155.     remove("audit.log");
  1156.     ofstream file;
  1157.     file.open("audit.log",ios::out);
  1158.     file << "username | operation | money | target | rename";
  1159.     for(int i=0;i<history.size();i++){
  1160.         file << history[i]->username << "|" << history[i]->operation << "|" << history[i]->money << "|" << history[i]->target << "|" << history[i]->rename[i] << endl;
  1161.     }
  1162.     file.close();
  1163. }
  1164.  
  1165. void write_bet(vector <Bethistory*> &bethistory){
  1166.     remove("bets.csv");
  1167.     ofstream file;
  1168.     file.open("bets.csv",ios::out);
  1169.     file << "bet_id | user_id | node_id | stake | result " << endl ;
  1170.     for(int i=0;i<bethistory.size() ;i++){
  1171.         file << bethistory[i]->bet_id<< "|" << bethistory[i]->user_id << "|" << bethistory[i]->node_id << "|" << bethistory[i]->stake <<"|" << bethistory[i]->result <<endl;
  1172.     }
  1173.     file.close();
  1174. }
  1175.  
  1176. void write_hierarchy(root* Root)
  1177. {   remove("hierarchy.dat.txt");
  1178.     ofstream file;
  1179.     file.open("hierarchy.dat.txt",ios::out);
  1180.     Root->write(file);
  1181.     file.close();
  1182. }
  1183.  
  1184. void Director::save(root* root,vector<Users*> &User,vector<History*> &history,vector <Bethistory*> &bethistory)
  1185. {   write_users(User);
  1186.     write_history(history);
  1187.     write_bet(bethistory);
  1188.     write_hierarchy(root);
  1189. }
  1190.  
  1191.  
  1192. void read_hierarchy(root* Root){
  1193.     vector <root*> hierarchy2;
  1194.     vector <root*> hierarchy3;
  1195.     vector <root*> hierarchy4;
  1196.     vector <root*> hierarchy5;
  1197.     ifstream file;
  1198.     file.open("hierarchy.dat.txt",ios::in);
  1199.     if(file.fail()){
  1200.         cerr << "Error openning file" << endl;
  1201.         exit(1);
  1202.     }
  1203.     string line;
  1204.     while(getline(file,line)){
  1205.         const char s[2]=" ";
  1206.         const char d[2]="\n";
  1207.         char* token;
  1208.         //converting string to char*
  1209.         char *str = new char[line.length() + 1];
  1210.         strcpy(str, line.c_str());
  1211.         //
  1212.         token = strtok(str,s);  
  1213.         string node(token);
  1214.         size_t n = count(node.begin(), node.end(), '.'); // number of dots
  1215.         token = strtok(NULL, d); //oti apomenei meta to node
  1216.        
  1217.         if(n == 1)
  1218.         {   category* temp=new category(token,node);
  1219.             Root->readh(temp);
  1220.             hierarchy2.push_back(temp);
  1221.         }
  1222.         if(n==2){
  1223.             subcategory* temp=new subcategory(token,node);
  1224.             hierarchy2[hierarchy2.size()-1]->readh(temp);
  1225.             hierarchy3.push_back(temp);
  1226.         }
  1227.         if(n == 3){
  1228.             strcpy(str,token); //str = token
  1229.             const char h[3] = " -";
  1230.             char* n;
  1231.             char* date;
  1232.             char* time;
  1233.             n = strtok(str,h);
  1234.             date=strtok(NULL,s); //date
  1235.             time = strtok(NULL,d);
  1236.             event* temp=new event(n,node,date,time);
  1237.             hierarchy3[hierarchy3.size()-1]->readh(temp);
  1238.             hierarchy4.push_back(temp);
  1239.            
  1240.         }
  1241.         if(n == 4){
  1242.             market* temp=new market(token,node);
  1243.             hierarchy4[hierarchy4.size()-1]->readh(temp);
  1244.             hierarchy5.push_back(temp);
  1245.         }
  1246.         if(n == 5){
  1247.             strcpy(str,token); //str = token
  1248.             const char h[2] = "#";
  1249.             char* n;
  1250.             n = strtok(str,h);
  1251.             token = strtok(NULL,h); //price
  1252.             selection* temp=new selection(n,node,token);
  1253.             hierarchy5[hierarchy5.size()-1]->readh(temp);
  1254.         }
  1255.     }
  1256. }
  1257.  
  1258.  
  1259. void read_users(vector<Users*> &User){
  1260.     ifstream file;
  1261.     file.open("users.csv",ios::in);
  1262.     if(file.fail()){
  1263.         cerr << "Error openning file" << endl;
  1264.         exit(1);
  1265.     }
  1266.     string line;
  1267.     getline(file,line);
  1268.     //pairnw to prwto line to arxeiasto me ta userid username ktl kai de to xrhsimopoiw
  1269.     while(getline(file,line)){
  1270.         //exw twra to line pou me | exei ola ta stoixeia
  1271.         const char s[2]="|";
  1272.         char* token;
  1273.         Users temp;
  1274.         //converting string to char*
  1275.         char *str = new char[line.length() + 1];
  1276.         strcpy(str, line.c_str());
  1277.         //
  1278.         token = strtok(str,s);
  1279.         temp.ID.user_id = atoi(token); //(kanw to char* int)
  1280.         token = strtok(NULL, s);
  1281.         temp.ID.username = token;
  1282.         token = strtok(NULL, s);
  1283.         temp.ID.fullname = token;
  1284.         token = strtok(NULL, s);
  1285.         temp.ID.password = token;
  1286.         token = strtok(NULL, s);
  1287.         temp.ID.type = atoi(token); //kanw to char* int
  1288.         token = strtok(NULL, s);
  1289.         temp.ID.status =token;
  1290.         token = strtok(NULL, s);
  1291.         temp.ID.balance = atof(token); //kanw char* float
  1292.         token = strtok(NULL, s);
  1293.         //twra to token einai san ena char* kai prepei pali na to kopsw me delimeter to ,
  1294.         char* token2;
  1295.         const char d[2]=",";
  1296.         token2=strtok(token,d);
  1297.         while(token2 != NULL){
  1298.             temp.ID.freebets.push_back(atof(token2)); //char* to float
  1299.             token2 = strtok(NULL, d);
  1300.         }
  1301.         if(temp.ID.type==1){  
  1302.             User.push_back(new Punter());
  1303.         }
  1304.         else if(temp.ID.type==2){  
  1305.             User.push_back(new Trader());
  1306.         }
  1307.         else{  
  1308.             User.push_back(new Director());
  1309.         }
  1310.         int i=User.size()-1;
  1311.         User[i]->ID.user_id=temp.ID.user_id;
  1312.         User[i]->ID.username.assign(temp.ID.username);
  1313.         User[i]->ID.fullname.assign(temp.ID.fullname);
  1314.         User[i]->ID.password.assign(temp.ID.password);
  1315.         User[i]->ID.type=temp.ID.type;
  1316.         User[i]->ID.status.assign(temp.ID.status);
  1317.         User[i]->ID.balance=temp.ID.balance;
  1318.         for(int l=0;l<temp.ID.freebets.size();l++)
  1319.         {   User[i]->ID.freebets.push_back(temp.ID.freebets[l]);
  1320.         }
  1321.     }
  1322.    
  1323.     //etoimo to User
  1324.     file.close();
  1325. }
  1326.  
  1327. void read_history(vector <History*> &history){
  1328.     ifstream file;
  1329.     file.open("audit.log",ios::in);
  1330.     if(file.fail()){
  1331.         cerr << "Error openning file" << endl;
  1332.         exit(1);
  1333.     }
  1334.     string line;
  1335.     getline(file,line);
  1336.     while(getline(file,line)){
  1337.         const char s[2]="|";
  1338.         char* token;
  1339.         History temp;
  1340.         //converting string to char*
  1341.         char *str = new char[line.length() + 1];
  1342.         strcpy(str, line.c_str());
  1343.         //
  1344.         token = strtok(str,s);
  1345.         temp.username = token;
  1346.         token = strtok(NULL, s);
  1347.         temp.operation = token;
  1348.         token = strtok(NULL, s);
  1349.         temp.money = atof(token);
  1350.         token = strtok(NULL, s);
  1351.         temp.target =token;
  1352.         token = strtok(NULL, s);
  1353.         temp.rename =token;
  1354.         //
  1355.         history.push_back(new History());
  1356.         int i = history.size()-1;
  1357.         //
  1358.         history[i]->username.assign(temp.username);
  1359.         history[i]->operation.assign(temp.operation);
  1360.         history[i]->target.assign(temp.target);
  1361.         history[i]->rename.assign(temp.rename);
  1362.         history[i]->money = temp.money;
  1363.         //
  1364.     }
  1365.     file.close();
  1366. }
  1367.  
  1368. void read_bet(vector <Bethistory*> &bethistory){
  1369.     ifstream file;
  1370.     file.open("bets.csv",ios::in);
  1371.     if(file.fail()){
  1372.         cerr << "Error openning file" << endl;
  1373.         exit(1);
  1374.     }
  1375.     string line;
  1376.     getline(file,line);
  1377.     while(getline(file,line)){
  1378.         const char s[2]="|";
  1379.         char* token;
  1380.         Bethistory temp;
  1381.         //converting string to char*
  1382.         char *str = new char[line.length() + 1];
  1383.         strcpy(str, line.c_str());
  1384.         //
  1385.         token = strtok(str,s);
  1386.         temp.bet_id = atoi(token);
  1387.         token = strtok(NULL, s);
  1388.         temp.user_id = atoi(token);
  1389.         token = strtok(NULL, s);
  1390.         temp.node_id = token;
  1391.         token = strtok(NULL, s);
  1392.         temp.stake = atof(token);
  1393.         token = strtok(NULL, s);
  1394.         temp.result = token[0];
  1395.         token = strtok(NULL, s);
  1396.         //
  1397.         bethistory.push_back(new Bethistory());
  1398.         int i = bethistory.size()-1;
  1399.         //
  1400.         bethistory[i]->bet_id = temp.bet_id;
  1401.         bethistory[i]->user_id = temp.user_id;
  1402.         bethistory[i]->node_id.assign(temp.node_id);
  1403.         bethistory[i]->stake = temp.stake;
  1404.         bethistory[i]->result= temp.result;
  1405.         //
  1406.     }
  1407.     file.close();
  1408. }
  1409.  
  1410. void management_input(Users &currentUser,vector<Users*> &User, vector<History*> &history, vector<Bethistory*> &bethistory, vector<root*> &Root){
  1411.     //ari8mo san inpout 1 isdigit plohghsh kalw plohghsh char sth sunarthsh entolwn px place
  1412.     while(1){
  1413.         root* current_node;
  1414.         int i=Root.size()-1;
  1415.         current_node = Root[i];
  1416.         current_node.preprint();
  1417.         string entoli;
  1418.         getline(cin,entoli);
  1419.         if(isdigit(entoli[0])){
  1420.             //plohghsh(entoli);
  1421.         }
  1422.         else{
  1423.             int check =0;
  1424.             capitalow(&entoli);
  1425.             if(entoli.size() > 1){
  1426.                 check = 1;
  1427.             }
  1428.             char ent;
  1429.             ent=entoli[0]; 
  1430.             if(ent == 'h'){
  1431.                 if(check){
  1432.                     if(entoli.compare("home") == 0){
  1433.                         currentUser.home();
  1434.                     }
  1435.                 }
  1436.                 else{
  1437.                     currentUser.home();
  1438.                 }
  1439.             }
  1440.             if(ent == 't'){
  1441.                 if(check){
  1442.                     if(entoli.compare("toggle") == 0){
  1443.                         currentUser.toggle();
  1444.                     }
  1445.                 }
  1446.                 else{
  1447.                     currentUser.toggle();
  1448.                 }
  1449.             }
  1450.             if(ent == 'x'){
  1451.                 if(check){
  1452.                     if(entoli.compare("exit") == 0){
  1453.                         exit(2);
  1454.                     }
  1455.                 }
  1456.                 else{
  1457.                     exit(2);
  1458.                 }
  1459.             }
  1460.             if(ent == 'b'){
  1461.                 if(check){
  1462.                     if(entoli.compare("bets") == 0){
  1463.                         currentUser.bets(bethistory,history);
  1464.                     }
  1465.                 }
  1466.                 else{
  1467.                     currentUser.bets(bethistory,history);
  1468.                 }
  1469.             }
  1470.             if(ent == 'f'){
  1471.                 if(check){
  1472.                     if(entoli.compare("freebets") == 0){
  1473.                         currentUser.freebets(User,history);
  1474.                     }
  1475.                 }
  1476.                 else{
  1477.                     currentUser.freebets(User,history);
  1478.                 }
  1479.             }
  1480.             if(ent == 'a'){
  1481.                 if(check){
  1482.                     if(entoli.compare("account") == 0){
  1483.                         currentUser.account(history);
  1484.                     }
  1485.                 }
  1486.                 else{
  1487.                     currentUser.account(history);
  1488.                 }
  1489.             }
  1490.             if(ent == 's'){
  1491.                 if(check){
  1492.                     if(entoli.compare("save") == 0){
  1493.                         currentUser.save();
  1494.                     }
  1495.                 }
  1496.                 else{
  1497.                     currentUser.save();
  1498.                 }
  1499.             }
  1500.             if(ent == 'l'){
  1501.                 if(check){
  1502.                     if(entoli.compare("logs") == 0){
  1503.                         currentUser.logs(history);
  1504.                     }
  1505.                 }
  1506.                 else{
  1507.                     currentUser.logs(history);
  1508.                 }
  1509.             }
  1510.             if(ent == 'u'){
  1511.                 if(check){
  1512.                     if(entoli.compare("users") == 0){
  1513.                         currentUser.users();
  1514.                     }
  1515.                 }
  1516.                 else{
  1517.                     currentUser.users();
  1518.                 }
  1519.             }
  1520.             if(ent == 'v'){
  1521.                 if(check){
  1522.                     if(entoli.compare("visibility") == 0){
  1523.                         currentUser.visibility();
  1524.                     }
  1525.                 }
  1526.                 else{
  1527.                     currentUser.visibility();
  1528.                 }
  1529.             }
  1530.             if(ent == 'r'){
  1531.                 if(check){
  1532.                     if(entoli.compare("rename") == 0){
  1533.                         currentUser.rename();
  1534.                     }
  1535.                 }
  1536.                 else{
  1537.                     currentUser.rename();
  1538.                 }
  1539.             }
  1540.             if(ent == 'n'){
  1541.                 if(check){
  1542.                     if(entoli.compare("new") == 0){
  1543.                         currentUser.New();
  1544.                     }
  1545.                 }
  1546.                 else{
  1547.                     currentUser.New();
  1548.                 }
  1549.             }
  1550.             if(ent == 'c'){
  1551.                 if(check){
  1552.                     if(entoli.compare("copy") == 0){
  1553.                         currentUser.copy();     // copy
  1554.                     }
  1555.                 }
  1556.                 else{
  1557.                     currentUser.copy();
  1558.                 }
  1559.             }
  1560.             if(ent == 'd'){
  1561.                 if(check){
  1562.                     if(entoli.compare("delete") == 0){
  1563.                         currentUser.Delete(); // director delete orismata
  1564.                     }
  1565.                 }
  1566.                 else{
  1567.                     currentUser.Delete();
  1568.                 }
  1569.             }
  1570.             if(ent == 'p'){
  1571.                 if(check){
  1572.                     if(entoli.compare("place") == 0){
  1573.                         current_node.preplace();
  1574.                     }
  1575.                 }
  1576.                 else{
  1577.                     current_node.preplace();
  1578.                 }
  1579.             }
  1580.             if(ent == 'v'){
  1581.                 if(check){
  1582.                     if(entoli.compare("void") == 0){
  1583.                         current_node.prevoid();
  1584.                     }
  1585.                 }
  1586.                 else{
  1587.                     current_node.prevoid();
  1588.                 }
  1589.             }
  1590.             if(ent == 's'){
  1591.                 if(check){
  1592.                     if(entoli.compare("settle") == 0){
  1593.                         current_node.presettle();
  1594.                     }
  1595.                 }
  1596.                 else{
  1597.                     current_node.presettle();
  1598.                 }
  1599.             }
  1600.             else {
  1601.                 cout << "Wrong Operation" << endl;
  1602.                 continue;
  1603.             }
  1604.         }
  1605.     }
  1606. }
  1607.  
  1608.  
  1609.  
  1610.  
  1611. void register_user(vector<Users*> &User,Users& current_user){
  1612.     int redo;
  1613.     string name;
  1614.     do{
  1615.         redo=0;
  1616.         cout << "username: ";
  1617.         getline (cin, name);
  1618.         for(int i=0;i<User.size();i++){
  1619.             if(name.compare(User[i]->ID.username) == 0){
  1620.                 cout << "This name already exists please type a different name!" << endl;
  1621.                 redo = 1;
  1622.             }
  1623.             if(name.compare("\n") == 0 || name.compare("guest:guest")==0){
  1624.                 cout << "forbidden name,please type a different name" << endl;
  1625.                 redo=1;
  1626.             }
  1627.         }
  1628.     }while(redo);
  1629. //
  1630.     User.push_back(new Punter);
  1631.     int i = User.size()-1;
  1632.     User[i]->ID.user_id = i+1;
  1633.     User[i]->ID.username.assign(name);
  1634.     User[i]->ID.fullname.assign(name); // this could be changed later in the account settings
  1635.     User[i]->ID.type = 1;
  1636.     User[i]->ID.status.assign("A");
  1637.     User[i]->ID.balance = 0.0;
  1638.     User[i]->ID.freebets.push_back(0.0); //
  1639.     do{
  1640.         redo=0;
  1641.         cout << "password: ";
  1642.         string pass1;
  1643.         getline (cin,pass1);
  1644.         cout << "Please retype your password:" ;
  1645.         string pass2;
  1646.         getline (cin,pass2);
  1647.         if (pass1.compare(pass2) != 0){
  1648.             cout << "You should insert the same password twice" << endl;
  1649.             redo=1;
  1650.         }
  1651.         else{
  1652.             User[i]->ID.password.assign(pass1);
  1653.         }
  1654.     }while(redo);
  1655.     write_users(User);  //arxeio susthmatos save
  1656.     current_user = *User[i];
  1657.     management_input(current_user,User,history,bethistory,Root);
  1658. }
  1659.  
  1660. void login_user(vector<Users*> User,Users& current_user,vector<History*> &history,vector<Bethistory*> &bethistory,vector<root*> Root){
  1661.     cout << "Welcome to KAPPA BET!" << endl;
  1662.     cout << "Please type username and password to login to your account!" << endl;
  1663.     cout << "If you don't have an account ,press (Enter) or type guest:guest to login as guest" << endl;
  1664.     int anagnwr=-1;
  1665.     int guest=0;
  1666.     int redo;
  1667.     do{
  1668.         redo=0;
  1669.         cout << "username: " ;
  1670.         string name;
  1671.         string rightpass;
  1672.         getline(cin,name);
  1673.         if (name.size()==0)
  1674.             name.assign("\n");
  1675.         if((name.compare("guest:guest") == 0) || name.compare("\n")==0){
  1676.             guest = 1;
  1677.             break;
  1678.         }
  1679.         for(int i=0;i<User.size();i++){
  1680.             if(name.compare(User[i]->ID.username) == 0){
  1681.                 rightpass.assign(User[i]->ID.password);
  1682.                 anagnwr=i;
  1683.             }
  1684.         }
  1685.         string provpass;
  1686.         cout << "password: ";
  1687.         getline(cin,provpass);
  1688.         if(provpass.size()==0)
  1689.             provpass.assign("\n");
  1690.         if(provpass.compare(rightpass) == 0){
  1691.             redo=0;
  1692.         }
  1693.         else{
  1694.             cout << "Wrong Credentials! Please Retry!" << endl;
  1695.             redo=1;
  1696.         }
  1697.     }while(redo);
  1698.     if(guest == 0){
  1699.         char locked = 'L';
  1700.         if(locked == User[anagnwr]->ID.status[0]){
  1701.             cout << "Your account has been locked due to: ";
  1702.             for(int i=2;i<User[anagnwr]->ID.status.size();i++){
  1703.                 cout << User[anagnwr]->ID.status[i];
  1704.             }
  1705.             exit(1);
  1706.         }  
  1707.     }
  1708.     //eisodos xrhsth sto arxiko menu analoga me to user.type h an einai guest
  1709.     if(guest == 1){
  1710.         Users* temp = new Guest();
  1711.         //gurnaw
  1712.         current_user = *temp;
  1713.        
  1714.     }
  1715.     else{
  1716.         current_user = *User[anagnwr];
  1717.     }
  1718.     write_users(User);
  1719.     management_input(current_user,User,history,bethistory,Root);
  1720. }
  1721.  
  1722. int main(int argc, char** argv) {
  1723.     vector<Users*> User;
  1724.     vector<History*> history;
  1725.     vector<Bethistory*> bethistory;
  1726.     vector<root*> Root;
  1727.     Root.push_back(new root());
  1728.    
  1729.     read_users(User);
  1730.     read_hierarchy(Root[0]);
  1731.    
  1732.     write_hierarchy(Root[0]);
  1733.    
  1734.     Users currentUser;
  1735.     if (argc == 1){
  1736.         //xwris parameters
  1737.         login_user(User, currentUser , history , bethistory , Root);
  1738.     }
  1739.     else if(argc == 2){
  1740.         //mia parametros
  1741.         string parameter(argv[1]);
  1742.         capitalow(&parameter);
  1743.         if(strcmp(parameter.c_str(),"-r") == 0){
  1744.             //register a user
  1745.             register_user(User,currentUser);
  1746.         }
  1747.     }
  1748.     management_input(currentUser,User,history,bethistory,Root);
  1749.     bethistoryfun(bethistory,10,1,"1.1.2.3",10.5,'W');
  1750.     write_bet(bethistory);
  1751.    
  1752.     write_users(User);  
  1753.     return 0;
  1754. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement