Advertisement
Guest User

Untitled

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