Advertisement
Guest User

Untitled

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