Advertisement
Guest User

Untitled

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