Advertisement
Guest User

Untitled

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