Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 28.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <fstream>
  6. using namespace std;
  7. int betid=1;
  8.  
  9. class root{
  10. protected:
  11.     string name;
  12.     vector <root*> nodes;
  13.     string ID;
  14.     int visibility;
  15. public:
  16.     root(string n="Location",string id=" "):visibility(1)
  17.     {   name.assign(n);
  18.         ID.assign(id);
  19.     }
  20.     void change_name(string n)
  21.     {   name.replace(name.begin(),name.end(),n);
  22.     }
  23.     int change_visibility()
  24.     {   cout << "You cannot change the visibility of root"<<endl;
  25.         return 0;
  26.     }
  27.     string path()
  28.     {   return ID;
  29.     }
  30.     string get_name()
  31.     {   return name;
  32.     }
  33.     void change(root* node)
  34.     {   int l;
  35.         for (int i=0;i<nodes.size();i++)
  36.         {   if(!(node->get_name().compare(nodes[i]->get_name())))
  37.             {   l=i;
  38.                 break;
  39.             }
  40.         }
  41.         nodes.push_back(nodes[l]);
  42.         nodes.erase(nodes.begin() + l);
  43.     }
  44. };
  45.  
  46. class category : public root{
  47. public:
  48.     string ID;
  49.     category(string n,string id):root(n,id)
  50.     {  
  51.     }
  52.     int change_visibility()
  53.     {   visibility!=visibility;
  54.         for(int i=0;i<nodes.size();i++)
  55.         {   nodes[i]->change_visibility();
  56.         }
  57.         return 1;
  58.     }
  59.  
  60. };
  61.  
  62. class subcategory : public root{
  63. public:
  64.     subcategory(string n,string id):root(n,id)
  65.     {
  66.     }
  67.     int change_visibility()
  68.     {   visibility!=visibility;
  69.         for(int i=0;i<nodes.size();i++)
  70.         {   nodes[i]->change_visibility();
  71.         }
  72.         return 1;
  73.     }
  74.  
  75. };
  76.  
  77. class event : public root{
  78.     string date;
  79.     string time;
  80. public:
  81.     event(string n,string id , string d,string t):root(n,id)
  82.     {   date.assign(d);
  83.         time.assign(t);
  84.     }
  85.     int change_visibility()
  86.     {   visibility!=visibility;
  87.         for(int i=0;i<nodes.size();i++)
  88.         {   nodes[i]->change_visibility();
  89.         }
  90.         return 1;
  91.     }
  92.     string get_date(){
  93.         return date;
  94.     }
  95.     string get_time(){
  96.         return time;
  97.     }
  98.  
  99. };
  100.  
  101. class selection : public root{
  102.     string price;
  103. public:
  104.     selection(string n,string id,string p):root(n,id)
  105.     {   price.assign(p);
  106.     }
  107.     string get_price(){
  108.         return price;
  109.     }
  110.     int change_visibility()
  111.     {   visibility!=visibility;
  112.         for(int i=0;i<nodes.size();i++)
  113.         {   nodes[i]->change_visibility();
  114.         }
  115.         return 1;
  116.     }
  117.  
  118. };
  119.  
  120. class market : public root{
  121. public:
  122.     market(string n,string id):root(n,id)
  123.     {
  124.     }
  125.     int change_visibility()
  126.     {   visibility!=visibility;
  127.         for(int i=0;i<nodes.size();i++)
  128.         {   nodes[i]->change_visibility();
  129.         }
  130.         return 1;
  131.     }
  132.      
  133. };
  134.  
  135. struct History
  136. {   string username;
  137.     string operation;
  138.     string rename;
  139.     string target;
  140.     double   money;
  141. };
  142. struct Bethistory
  143. {   int bet_id;
  144.     int user_id;
  145.     string node_id;
  146.     double stake;
  147.     char result;
  148. };
  149. class elements
  150. {   public:
  151.         int user_id;
  152.         string username;
  153.         string fullname;
  154.         string password;
  155.         int type;
  156.         string status;
  157.         double balance;
  158.         vector<double> freebets;
  159.  
  160. };
  161.  
  162. void historyfun(vector<History*> &history,string operation,string target,string rename,string username,double x)
  163. {   history.push_back(new History);
  164.     int i=history.size()-1;
  165.     history[i]->operation.assign(operation);
  166.     history[i]->money=x;
  167.     history[i]->target.assign(target);
  168.     history[i]->rename.assign(rename);
  169.     history[i]->username.assign(username);
  170.      
  171. }
  172.  
  173. void bethistoryfun(vector<Bethistory*> &bethistory,int bet_id,int user_id,string node_id,double stake,char result)
  174. {   bethistory.push_back(new Bethistory);
  175.     int i=bethistory.size()-1;
  176.     bethistory[i]->bet_id=bet_id;
  177.     bethistory[i]->user_id=user_id;
  178.     bethistory[i]->node_id.assign(node_id);
  179.     bethistory[i]->stake=stake;
  180.     bethistory[i]->result=result;
  181. }
  182. class Users
  183. {   public:
  184.         class elements ID;
  185.         virtual void print()
  186.         {
  187.         }
  188.         virtual void exprint()
  189.         {   print();
  190.         }
  191.         void home()
  192.         {   //epistrofh arxikh selida
  193.         }
  194.         void toggle()
  195.         {   //enallafh timwn
  196.         }
  197.         virtual void bets(vector<Bethistory*> &bethistory,vector<History*> &history)
  198.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  199.         }
  200.         virtual void freebets(vector<Users*> &User,vector<History*> &history)
  201.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  202.         }
  203.         virtual void account(vector<History*> &history)
  204.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  205.         }
  206.         virtual void save()
  207.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  208.         }
  209.         virtual void logs(vector<History*> &history)
  210.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  211.         }
  212.         virtual void users()
  213.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  214.         }
  215.         virtual void rename(vector<Users*> &User,vector<History*> &history)
  216.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  217.         }
  218.         virtual void New(vector <History*> history,root *nodeid)
  219.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  220.         }
  221.         virtual void copy()
  222.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  223.         }
  224.         virtual void Delete()
  225.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  226.         }
  227.         virtual void view(vector <Users*> &User)
  228.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  229.         }
  230.         virtual void search(vector <Users*> &User)
  231.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  232.         }
  233.         virtual void place(vector<Bethistory*> &bethistory,vector<History*> &history,string nodeid)
  234.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  235.         }
  236.         virtual void lock(vector<Users*> &User,vector<History*> &history)
  237.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  238.         }
  239.         virtual void password(vector<History*> &history)
  240.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  241.         }
  242.         virtual void deposit (vector<History*> &history)
  243.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  244.         }
  245.         virtual void Void()
  246.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  247.         }
  248.         virtual void Settle()
  249.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  250.         }
  251.         virtual void visibility(vector <History*> history, root* parent,root* nodeid)
  252.         {   cout<< "Den exete prosbash se authn thn entolh"<<endl;
  253.         }
  254. };
  255.  
  256. class Guest:public Users
  257. {   public:
  258.         void print()
  259.         {   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;
  260.         }
  261. };
  262. class Punter:public Users
  263. {   public:
  264.         void print()
  265.         {   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;
  266.         }
  267.         void exprint()
  268.         {   print();
  269.             cout<<"P(Place),gia enapo8esh stoixhmatos"<<endl;
  270.         }
  271.         void rename(vector<Users*> &User,vector<History*> &history)
  272.         {   if(flag==1)
  273.             {   string str;
  274.                 while(1)
  275.                 {   int flag2=0;
  276.                      getline(cin,str);
  277.                     for(int i=0;i<User.size();i++)
  278.                     {   if (!User[i]->ID.username.compare(str))
  279.                         {   flag2=1;
  280.                             cout<<"To username xrhshmopoieitai hdh"<<endl;
  281.                             break;
  282.                         }
  283.                     }
  284.                     if(flag2==0)
  285.                         break;
  286.                 }
  287.                 ID.username.replace(ID.username.begin(),ID.username.end(),str);
  288.                 historyfun(history,"Rename"," "," ",ID.username,0.0);
  289.             }
  290.             else
  291.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  292.  
  293.         }
  294.         void password(vector<History*> &history)
  295.         {   if(flag==1)
  296.             {   string str,str1;
  297.                 while(1)
  298.                 {   cout<< "Dwse ton neo kwdiko"<<endl;
  299.                     getline(cin,str);
  300.                     cout<< "Epanalabe"<<endl;
  301.                     getline(cin,str1);
  302.                     if (!str.compare(str1))
  303.                     {   ID.password.replace(ID.password.begin(),ID.password.end(),str);
  304.                         historyfun(history,"Password"," "," ",ID.username,0.0);
  305.                         break;
  306.                     }
  307.                 }
  308.  
  309.             }
  310.             else
  311.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  312.  
  313.         }
  314.         void bets(vector<Bethistory*> &bethistory,vector<History*> &history)
  315.         {   if(flag==1)
  316.             {   for (int i=0;i<bethistory.size();i++)
  317.                 {   if (bethistory[i]->user_id==ID.user_id)
  318.                     {   cout<<"Bet to "<<bethistory[i]->node_id<< " "<< bethistory[i]->stake<< endl;
  319.  
  320.                     }
  321.                 }
  322.                 historyfun(history,"Bet"," "," ",ID.username,0.0);
  323.             }
  324.             else
  325.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  326.  
  327.         }
  328.         void deposit(vector<History*> &history)
  329.         {   if(flag==1)
  330.             {   double x;
  331.                 cin >> x;
  332.                 ID.balance+=x;
  333.                 cout << "To neo sas poso sto logariasmo sas einai" << ID.balance<<endl;
  334.                 historyfun(history,"Deposit"," "," ",ID.username,x);
  335.             }
  336.             else
  337.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  338.  
  339.         }
  340.         void account(vector<History*> &history)
  341.         {   cout<<"Paixths: " << ID.username<<endl<<"Dia8esimo upoloipo: "<< ID.balance<<endl<<"Dia8esima kouponia:";
  342.             for(int i=0;i<ID.freebets.size();i++)
  343.             {   if(i!=ID.freebets.size())
  344.                     cout<<ID.freebets[i]<<",";
  345.                 else
  346.                     cout<<ID.freebets[i]<<endl;
  347.             }
  348.             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;
  349.             flag=1;
  350.             historyfun(history,"Account"," "," ",ID.username,0.0);
  351.         }
  352.         void place(vector<Bethistory*> &bethistory,vector<History*> &history,string nodeid)
  353.         {   string choice;
  354.             string bet;
  355.             cout<<"Upoloipo portofoliou: "<<ID.balance<<endl;
  356.             cout<<"Dwse epilogh"<<endl;
  357.             getline(cin,choice) ;
  358.             if(choice.compare("cancel"));
  359.             {   char x='a';
  360.                 for(int i=0;i<ID.freebets.size();i++)
  361.                 {   cout<<x++<<"."<<ID.freebets[i]<<endl;
  362.                 }
  363.                 cout << "Dwse poso stoixhmatos"<<endl;
  364.                 while (1)
  365.                 {   getline(cin,bet);
  366.                     if(bet[0]>='a' && bet[0]<x)
  367.                     {   int l=bet[0]-'a';
  368.                         bethistoryfun(bethistory,betid++,ID.user_id," ",ID.freebets[l],'-');
  369.                         ID.freebets.erase(ID.freebets.begin()+l);
  370.                     }
  371.                     else
  372.                     {   double bett=atof( bet.c_str());
  373.                         if(bett>ID.balance && ID.balance==0)
  374.                         {   cout<<"Mhdeniko upoloipo parakalw gemise to portofoli s apo to menou diaxeirhshs"<<endl;
  375.                             break;
  376.                         }
  377.                         else if(bett>ID.balance)
  378.                         {   cout<< "Dwse mikrotero poso"<<endl;
  379.                             getline(cin,bet);
  380.                             continue;
  381.                         }
  382.                         else if(bett<=ID.balance)
  383.                         {   ID.balance-=bett;
  384.                             bethistoryfun(bethistory,betid++,ID.user_id," ",bett,'-');
  385.                             historyfun(history,"bet",nodeid," ",ID.username,bett);
  386.                             break;
  387.                         }
  388.                     }
  389.                 }
  390.  
  391.             }
  392.         }
  393.     private:
  394.         int flag;
  395. };
  396. class Trader:public Users
  397. {   public:
  398.         void bets(vector<Bethistory*> &bethistory,vector<History*> &history)
  399.         {   int l=0;
  400.             cout<< "bet_id | user_id | node_id | stake | result " << endl;
  401.             for (int i=0;i<bethistory.size();i++)
  402.             {   if (l++==20)
  403.                     break;
  404.                 cout << bethistory[i]->bet_id<< '\t' <<bethistory[i]->user_id<< '\t' <<bethistory[i]->node_id<< '\t' <<bethistory[i]->stake<< '\t' <<bethistory[i]->result<<endl;
  405.             }
  406.         }
  407.         void freebets(vector<Users*> &User,vector<History*> &history)
  408.         {   string name;
  409.             double x;
  410.             int flag=0,i;
  411.             while(1)
  412.             {   getline(cin,name);
  413.                 for(i=0;i<User.size();i++)
  414.                 {   if(!User[i]->ID.username.compare(name))
  415.                     {   flag=1;
  416.                         break;
  417.                     }
  418.                 }
  419.                 if(flag==1)
  420.                     break;
  421.  
  422.             }
  423.             if(flag==1)
  424.             {   cin >> x;
  425.                 User[i]->ID.freebets.push_back(x);
  426.             }
  427.  
  428.         }
  429.         void Void()
  430.         {
  431.         }
  432.         void Settle()
  433.         {
  434.         }
  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<<"B(Bets),gia emfanish 20 teleutaiwn stoixhmatwn"<<endl<<"F(Freebets),gia apodosh kouponiou se xrhsth"<<endl;
  437.         }
  438.         void exprint()
  439.         {   print();
  440.             cout<<"V(Void),gia na akurw8ei mia epilogh"<<endl<<"S(Settle),gia dieu8ethsh ths agoras"<<endl;
  441.         }
  442.  
  443. };
  444. class Director:public Users
  445. {   public:
  446.         void bets(vector<Bethistory*> &bethistory,vector<History*> &history)
  447.         {   int l=0;
  448.             cout<< "bet_id | user_id | node_id | stake | result " << endl ;
  449.             for (int i=0;i<bethistory.size();i++)
  450.             {   if (l++==20)
  451.                     break;
  452.                 cout << bethistory[i]->bet_id<< '\t' <<bethistory[i]->user_id<< '\t' <<bethistory[i]->node_id<< '\t' <<bethistory[i]->stake<< '\t' <<bethistory[i]->result<<endl;
  453.             }
  454.             historyfun(history,"Bets"," "," ",ID.username,0);
  455.         }
  456.         void freebets(vector<Users*> &User,vector<History*> &history)
  457.         {   string name;
  458.             double x;
  459.             int flag=0,i;
  460.             while(1)
  461.             {   getline(cin,name);
  462.                 for(i=0;i<User.size();i++)
  463.                 {   if(!User[i]->ID.username.compare(name))
  464.                     {   flag=1;
  465.                         break;
  466.                     }
  467.                 }
  468.                 if(flag==1)
  469.                     break;
  470.  
  471.             }
  472.             if(flag==1)
  473.             {   cin >> x;
  474.                 User[i]->ID.freebets.push_back(x);
  475.             }
  476.  
  477.         }
  478.         void save()
  479.         {   //save
  480.         }
  481.         void logs(vector<History*> &history)
  482.         {   int l=0;
  483.             for (int i=0;i<history.size();i++)
  484.             {   if (l++==25)
  485.                     break;
  486.                 cout<<history[i]->username<<'\t'<<history[i]->operation<<'\t'<<history[i]->target<<'\t'<<history[i]->rename<<'\t'<<history[i]->money<<endl;
  487.             }
  488.         }
  489.         void users()
  490.         {   cout<<"Epiloges:"<<endl<<"V(View),gia emfanish xrhstwn pinaka xrhstwn"<<endl<<"S(Search),gia anazhthsh xrhsth"<<endl<<"L(Lock,gia enallagh katastashs apokleismou"<<endl;
  491.             flag=1;
  492.         }
  493.         void visibility(vector <History*> history, root* parent,root* nodeid)
  494.         {   parent->change(nodeid);
  495.         }
  496.         void rename(vector<Users*> &User,vector<History*> &history,root* nodeid)
  497.         {   string rename;
  498.             getline(cin,rename);
  499.             nodeid->change_name(rename);
  500.             historyfun(history,"Rename",nodeid->path(),rename,ID.username,0.0);
  501.         }
  502.         void New(vector <History*> history,root *nodeid)
  503.         {  
  504.         }
  505.         void copy()
  506.         {   //dhmiourgia antigrafou
  507.         }
  508.         void Delete()
  509.         {   //diagrafh kombou
  510.         }
  511.         void view(vector <Users*> &User)
  512.         {   if (flag==1)
  513.             {   cout << "user_id | username | fullname | password | type | status | balance | freebets" << endl ;
  514.                 for (int i=0;i<User.size();i++)
  515.                 {   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';
  516.                     for (int l=0;l<User[i]->ID.freebets.size();l++)
  517.                     {   cout<< User[i]->ID.freebets[l];
  518.                         if(l!=User[i]->ID.freebets.size()-1)
  519.                             cout<<",";
  520.                         else
  521.                             cout << endl;
  522.                     }
  523.                 }
  524.             }
  525.             else
  526.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  527.         }
  528.         void search(vector <Users*> &User)
  529.         {   if (flag==1)
  530.             {   string name;
  531.                 getline(cin,name);
  532.                 for(int i=0;i<User.size();i++)
  533.                 {   if(User[i]->ID.username.find(name)!=User[i]->ID.username.npos)
  534.                     {   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';
  535.                         for (int l=0;l<User[i]->ID.freebets.size();l++)
  536.                         {   cout<< User[i]->ID.freebets[l];
  537.                             if(l!=User[i]->ID.freebets.size()-1)
  538.                                 cout<<",";
  539.                             else
  540.                                 cout << endl;
  541.                         }
  542.                     }
  543.                 }
  544.  
  545.             }
  546.             else
  547.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  548.  
  549.         }
  550.         void lock(vector<Users*> &User,vector<History*> &history)
  551.         {   if (flag==1)
  552.             {   string name;
  553.                 string name3;
  554.                 int flag2=0,i;
  555.                 getline(cin,name);
  556.                 for(i=0;i<User.size();i++)
  557.                 {  
  558.                     if(!User[i]->ID.username.compare(name) && User[i]->ID.type!=3)
  559.                     {   if(User[i]->ID.status[0]!='L')
  560.                         {   flag2=1;
  561.                             cout<<"Anefere logo"<<endl;
  562.                             getline(cin, name3);
  563.                             string name2="L,";
  564.                             User[i]->ID.status.replace(User[i]->ID.status.begin(),User[i]->ID.status.end(),name2);
  565.                             User[i]->ID.status.insert(2,name3);
  566.                             break;
  567.                         }
  568.                         else if(User[i]->ID.status[0]=='L')
  569.                         {   flag2=1;
  570.                             cout<<"Anefere logo"<<endl;
  571.                             getline(cin, name3);
  572.                             User[i]->ID.status.replace(User[i]->ID.status.begin(),User[i]->ID.status.end(),name3);
  573.                             break;
  574.                         }
  575.                     }
  576.                 }
  577.                 if (flag2)
  578.                 {   historyfun(history,"Lock",User[i]->ID.username,User[i]->ID.status,ID.username,0);
  579.                 }
  580.  
  581.             }
  582.             else
  583.                 cout<< "Den exete prosbash se authn thn entolh"<<endl;
  584.  
  585.         }
  586.         void print()
  587.         {   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;
  588.         }
  589.         void exprint()
  590.         {   print();
  591.             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;
  592.         }
  593.     private:
  594.         int flag;
  595. };
  596.  
  597. void write_users(vector<Users*>& User){
  598.     remove("users.csv");
  599.     ofstream file;
  600.     file.open("users.csv",ios::out);
  601.     file << "user_id | username | fullname | password | type | status | balance | freebets" << endl ;
  602.     int i,j;
  603.     for(i=0;i<User.size();i++){
  604.         file << User[i]->ID.user_id << "|" << User[i]->ID.username << "|" << User[i]->ID.fullname << "|";
  605.         file << User[i]->ID.password << "|" << User[i]->ID.type << "|" << User[i]->ID.status << "|" << User[i]->ID.balance << "|";
  606.         for(j=0;j<User[i]->ID.freebets.size();j++){
  607.             file << User[i]->ID.freebets[j];
  608.             if (j<User[i]->ID.freebets.size()-1){
  609.                 file << ",";
  610.             }
  611.         }
  612.         file << endl;
  613.     }
  614.     file.close();
  615. }
  616.  
  617. void write_history(vector <History*> &history){
  618.     remove("audit.log");
  619.     ofstream file;
  620.     file.open("audit.log",ios::out);
  621.     file << "username | operation | money | target | rename";
  622.     for(int i=0;i<history.size();i++){
  623.         file << history[i]->username << "|" << history[i]->operation << "|" << history[i]->money << "|" << history[i]->target << "|" << history[i]->rename[i] << endl;
  624.     }
  625.     file.close();
  626. }
  627.  
  628. void write_bet(vector <Bethistory*> &bethistory){
  629.     remove("bets.csv");
  630.     ofstream file;
  631.     file.open("bets.csv",ios::out);
  632.     file << "bet_id | user_id | node_id | stake | result " << endl ;
  633.     for(int i=0;i<bethistory.size() ;i++){
  634.         file << bethistory[i]->bet_id<< "|" << bethistory[i]->user_id << "|" << bethistory[i]->node_id << "|" << bethistory[i]->stake <<"|" << bethistory[i]->result <<endl;
  635.     }
  636.     file.close();
  637. }
  638.  
  639. void read_users(vector<Users*> &User){
  640.     ifstream file;
  641.     file.open("users.csv",ios::in);
  642.     if(file.fail()){
  643.         cerr << "Error openning file" << endl;
  644.         exit(1);
  645.     }
  646.     string line;
  647.     getline(file,line);
  648.     //pairnw to prwto line to arxeiasto me ta userid username ktl kai de to xrhsimopoiw
  649.     while(getline(file,line)){
  650.         //exw twra to line pou me | exei ola ta stoixeia
  651.         const char s[2]="|";
  652.         char* token;
  653.         Users temp;
  654.         //converting string to char*
  655.         char *str = new char[line.length() + 1];
  656.         strcpy(str, line.c_str());
  657.         //
  658.         token = strtok(str,s);
  659.         temp.ID.user_id = atoi(token); //(kanw to char* int)
  660.         token = strtok(NULL, s);
  661.         temp.ID.username = token;
  662.         token = strtok(NULL, s);
  663.         temp.ID.fullname = token;
  664.         token = strtok(NULL, s);
  665.         temp.ID.password = token;
  666.         token = strtok(NULL, s);
  667.         temp.ID.type = atoi(token); //kanw to char* int
  668.         token = strtok(NULL, s);
  669.         temp.ID.status =token;
  670.         token = strtok(NULL, s);
  671.         temp.ID.balance = atof(token); //kanw char* float
  672.         token = strtok(NULL, s);
  673.         //twra to token einai san ena char* kai prepei pali na to kopsw me delimeter to ,
  674.         char* token2;
  675.         const char d[2]=",";
  676.         token2=strtok(token,d);
  677.         while(token2 != NULL){
  678.             temp.ID.freebets.push_back(atof(token2)); //char* to float
  679.             token2 = strtok(NULL, d);
  680.         }
  681.         if(temp.ID.type==1){  
  682.             User.push_back(new Punter());
  683.         }
  684.         else if(temp.ID.type==2){  
  685.             User.push_back(new Trader());
  686.         }
  687.         else{  
  688.             User.push_back(new Director());
  689.         }
  690.         int i=User.size()-1;
  691.         User[i]->ID.user_id=temp.ID.user_id;
  692.         User[i]->ID.username.assign(temp.ID.username);
  693.         User[i]->ID.fullname.assign(temp.ID.fullname);
  694.         User[i]->ID.password.assign(temp.ID.password);
  695.         User[i]->ID.type=temp.ID.type;
  696.         User[i]->ID.status.assign(temp.ID.status);
  697.         User[i]->ID.balance=temp.ID.balance;
  698.         for(int l=0;l<temp.ID.freebets.size();l++)
  699.         {   User[i]->ID.freebets.push_back(temp.ID.freebets[l]);
  700.         }
  701.     }
  702.     //etoimo to User
  703.     file.close();
  704. }
  705.  
  706. void read_history(vector <History*> &history){
  707.     ifstream file;
  708.     file.open("audit.log",ios::in);
  709.     if(file.fail()){
  710.         cerr << "Error openning file" << endl;
  711.         exit(1);
  712.     }
  713.     string line;
  714.     getline(file,line);
  715.     while(getline(file,line)){
  716.         const char s[2]="|";
  717.         char* token;
  718.         History temp;
  719.         //converting string to char*
  720.         char *str = new char[line.length() + 1];
  721.         strcpy(str, line.c_str());
  722.         //
  723.         token = strtok(str,s);
  724.         temp.username = token;
  725.         token = strtok(NULL, s);
  726.         temp.operation = token;
  727.         token = strtok(NULL, s);
  728.         temp.money = atof(token);
  729.         token = strtok(NULL, s);
  730.         temp.target =token;
  731.         token = strtok(NULL, s);
  732.         temp.rename =token;
  733.         //
  734.         history.push_back(new History());
  735.         int i = history.size()-1;
  736.         //
  737.         history[i]->username.assign(temp.username);
  738.         history[i]->operation.assign(temp.operation);
  739.         history[i]->target.assign(temp.target);
  740.         history[i]->rename.assign(temp.rename);
  741.         history[i]->money = temp.money;
  742.         //
  743.     }
  744.     file.close();
  745. }
  746.  
  747. void read_bet(vector <Bethistory*> &bethistory){
  748.     ifstream file;
  749.     file.open("bets.csv",ios::in);
  750.     if(file.fail()){
  751.         cerr << "Error openning file" << endl;
  752.         exit(1);
  753.     }
  754.     string line;
  755.     getline(file,line);
  756.     while(getline(file,line)){
  757.         const char s[2]="|";
  758.         char* token;
  759.         Bethistory temp;
  760.         //converting string to char*
  761.         char *str = new char[line.length() + 1];
  762.         strcpy(str, line.c_str());
  763.         //
  764.         token = strtok(str,s);
  765.         temp.bet_id = atoi(token);
  766.         token = strtok(NULL, s);
  767.         temp.user_id = atoi(token);
  768.         token = strtok(NULL, s);
  769.         temp.node_id = token;
  770.         token = strtok(NULL, s);
  771.         temp.stake = atof(token);
  772.         token = strtok(NULL, s);
  773.         temp.result = token[0];
  774.         token = strtok(NULL, s);
  775.         //
  776.         bethistory.push_back(new Bethistory());
  777.         int i = bethistory.size()-1;
  778.         //
  779.         bethistory[i]->bet_id = temp.bet_id;
  780.         bethistory[i]->user_id = temp.user_id;
  781.         bethistory[i]->node_id.assign(temp.node_id);
  782.         bethistory[i]->stake = temp.stake;
  783.         bethistory[i]->result= temp.result;
  784.         //
  785.     }
  786.     file.close();
  787. }
  788.  
  789. int main(int argc, char** argv) {
  790.     vector<Users*> User;
  791.     vector<History*> history;
  792.     vector<Bethistory*> bethistory;
  793.     /*
  794.     Users mark;
  795.     mark.ID.user_id = 1;
  796.     mark.ID.username = "Nikos";
  797.     mark.ID.fullname = "Tsougkrana";
  798.     mark.ID.password = "12345656";
  799.     mark.ID.type = 3;
  800.     mark.ID.status ="SMTH";
  801.     mark.ID.balance = 1234.556;
  802.     mark.ID.freebets.push_back(10.5 );
  803.     mark.ID.freebets.push_back(70.5 );
  804.     mark.ID.freebets.push_back(120.5 );
  805.     User.push_back(&mark);
  806.      
  807.     Users nik;
  808.     nik.ID.user_id = 2;
  809.     nik.ID.username = "kombra";
  810.     nik.ID.fullname = "anakloda";
  811.     nik.ID.password = ";;45656";
  812.     nik.ID.type = 1;
  813.     nik.ID.status ="SMiTH";
  814.     nik.ID.balance = 4.3;
  815.     nik.ID.freebets.push_back(20.5 );
  816.     nik.ID.freebets.push_back(7.5 );
  817.     nik.ID.freebets.push_back(10.5 );
  818.     User.push_back(&nik);
  819.    
  820.     write_users(User);
  821.    
  822.     bethistoryfun(bethistory,10,1,"1.1.2.3",10.5,'W');
  823.     write_bet(bethistory);
  824.     */
  825.     read_users(User);
  826.     write_users(User);    
  827.     return 0;
  828. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement