Advertisement
Guest User

Untitled

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