Advertisement
Guest User

Untitled

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