Advertisement
Guest User

Untitled

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