Advertisement
Guest User

Untitled

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