Advertisement
Guest User

Untitled

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