Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <stdlib.h>
- #include <string.h>
- #include <fstream>
- using namespace std;
- int betid=1;
- class root{
- protected:
- string name;
- vector <root*> nodes;
- string ID;
- int visibility;
- public:
- root(string n="Location",string id=" "):visibility(1)
- { name.assign(n);
- ID.assign(id);
- }
- void change_name(string n)
- { name.replace(name.begin(),name.end(),n);
- }
- int change_visibility()
- { cout << "You cannot change the visibility of root"<<endl;
- return 0;
- }
- string path()
- { return ID;
- }
- string get_name()
- { return name;
- }
- void change(root* node)
- { int l;
- for (int i=0;i<nodes.size();i++)
- { if(!(node->get_name().compare(nodes[i]->get_name())))
- { l=i;
- break;
- }
- }
- nodes.push_back(nodes[l]);
- nodes.erase(nodes.begin() + l);
- }
- };
- class category : public root{
- public:
- string ID;
- category(string n,string id):root(n,id)
- {
- }
- int change_visibility()
- { visibility!=visibility;
- for(int i=0;i<nodes.size();i++)
- { nodes[i]->change_visibility();
- }
- return 1;
- }
- };
- class subcategory : public root{
- public:
- subcategory(string n,string id):root(n,id)
- {
- }
- int change_visibility()
- { visibility!=visibility;
- for(int i=0;i<nodes.size();i++)
- { nodes[i]->change_visibility();
- }
- return 1;
- }
- };
- class event : public root{
- string date;
- string time;
- public:
- event(string n,string id , string d,string t):root(n,id)
- { date.assign(d);
- time.assign(t);
- }
- int change_visibility()
- { visibility!=visibility;
- for(int i=0;i<nodes.size();i++)
- { nodes[i]->change_visibility();
- }
- return 1;
- }
- string get_date(){
- return date;
- }
- string get_time(){
- return time;
- }
- };
- class selection : public root{
- string price;
- public:
- selection(string n,string id,string p):root(n,id)
- { price.assign(p);
- }
- string get_price(){
- return price;
- }
- int change_visibility()
- { visibility!=visibility;
- for(int i=0;i<nodes.size();i++)
- { nodes[i]->change_visibility();
- }
- return 1;
- }
- };
- class market : public root{
- public:
- market(string n,string id):root(n,id)
- {
- }
- int change_visibility()
- { visibility!=visibility;
- for(int i=0;i<nodes.size();i++)
- { nodes[i]->change_visibility();
- }
- return 1;
- }
- };
- struct History
- { string username;
- string operation;
- string rename;
- string target;
- double money;
- };
- struct Bethistory
- { int bet_id;
- int user_id;
- string node_id;
- double stake;
- char result;
- };
- class elements
- { public:
- int user_id;
- string username;
- string fullname;
- string password;
- int type;
- string status;
- double balance;
- vector<double> freebets;
- };
- void historyfun(vector<History*> &history,string operation,string target,string rename,string username,double x)
- { history.push_back(new History);
- int i=history.size()-1;
- history[i]->operation.assign(operation);
- history[i]->money=x;
- history[i]->target.assign(target);
- history[i]->rename.assign(rename);
- history[i]->username.assign(username);
- }
- void bethistoryfun(vector<Bethistory*> &bethistory,int bet_id,int user_id,string node_id,double stake,char result)
- { bethistory.push_back(new Bethistory);
- int i=bethistory.size()-1;
- bethistory[i]->bet_id=bet_id;
- bethistory[i]->user_id=user_id;
- bethistory[i]->node_id.assign(node_id);
- bethistory[i]->stake=stake;
- bethistory[i]->result=result;
- }
- class Users
- { public:
- class elements ID;
- virtual void print()
- {
- }
- virtual void exprint()
- { print();
- }
- void home()
- { //epistrofh arxikh selida
- }
- void toggle()
- { //enallafh timwn
- }
- virtual void bets(vector<Bethistory*> &bethistory,vector<History*> &history)
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void freebets(vector<Users*> &User,vector<History*> &history)
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void account(vector<History*> &history)
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void save()
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void logs(vector<History*> &history)
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void users()
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void rename(vector<Users*> &User,vector<History*> &history)
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void New(vector <History*> history,root *nodeid)
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void copy()
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void Delete()
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void view(vector <Users*> &User)
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void search(vector <Users*> &User)
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void place(vector<Bethistory*> &bethistory,vector<History*> &history,string nodeid)
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void lock(vector<Users*> &User,vector<History*> &history)
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void password(vector<History*> &history)
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void deposit (vector<History*> &history)
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void Void()
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void Settle()
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void visibility(vector <History*> history, root* parent,root* nodeid)
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- };
- class Guest:public Users
- { public:
- void print()
- { 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;
- }
- };
- class Punter:public Users
- { public:
- void print()
- { 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;
- }
- void exprint()
- { print();
- cout<<"P(Place),gia enapo8esh stoixhmatos"<<endl;
- }
- void rename(vector<Users*> &User,vector<History*> &history)
- { if(flag==1)
- { string str;
- while(1)
- { int flag2=0;
- getline(cin,str);
- for(int i=0;i<User.size();i++)
- { if (!User[i]->ID.username.compare(str))
- { flag2=1;
- cout<<"To username xrhshmopoieitai hdh"<<endl;
- break;
- }
- }
- if(flag2==0)
- break;
- }
- ID.username.replace(ID.username.begin(),ID.username.end(),str);
- historyfun(history,"Rename"," "," ",ID.username,0.0);
- }
- else
- cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- void password(vector<History*> &history)
- { if(flag==1)
- { string str,str1;
- while(1)
- { cout<< "Dwse ton neo kwdiko"<<endl;
- getline(cin,str);
- cout<< "Epanalabe"<<endl;
- getline(cin,str1);
- if (!str.compare(str1))
- { ID.password.replace(ID.password.begin(),ID.password.end(),str);
- historyfun(history,"Password"," "," ",ID.username,0.0);
- break;
- }
- }
- }
- else
- cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- void bets(vector<Bethistory*> &bethistory,vector<History*> &history)
- { if(flag==1)
- { for (int i=0;i<bethistory.size();i++)
- { if (bethistory[i]->user_id==ID.user_id)
- { cout<<"Bet to "<<bethistory[i]->node_id<< " "<< bethistory[i]->stake<< endl;
- }
- }
- historyfun(history,"Bet"," "," ",ID.username,0.0);
- }
- else
- cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- void deposit(vector<History*> &history)
- { if(flag==1)
- { double x;
- cin >> x;
- ID.balance+=x;
- cout << "To neo sas poso sto logariasmo sas einai" << ID.balance<<endl;
- historyfun(history,"Deposit"," "," ",ID.username,x);
- }
- else
- cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- void account(vector<History*> &history)
- { cout<<"Paixths: " << ID.username<<endl<<"Dia8esimo upoloipo: "<< ID.balance<<endl<<"Dia8esima kouponia:";
- for(int i=0;i<ID.freebets.size();i++)
- { if(i!=ID.freebets.size())
- cout<<ID.freebets[i]<<",";
- else
- cout<<ID.freebets[i]<<endl;
- }
- 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;
- flag=1;
- historyfun(history,"Account"," "," ",ID.username,0.0);
- }
- void place(vector<Bethistory*> &bethistory,vector<History*> &history,string nodeid)
- { string choice;
- string bet;
- cout<<"Upoloipo portofoliou: "<<ID.balance<<endl;
- cout<<"Dwse epilogh"<<endl;
- getline(cin,choice) ;
- if(choice.compare("cancel"));
- { char x='a';
- for(int i=0;i<ID.freebets.size();i++)
- { cout<<x++<<"."<<ID.freebets[i]<<endl;
- }
- cout << "Dwse poso stoixhmatos"<<endl;
- while (1)
- { getline(cin,bet);
- if(bet[0]>='a' && bet[0]<x)
- { int l=bet[0]-'a';
- bethistoryfun(bethistory,betid++,ID.user_id," ",ID.freebets[l],'-');
- ID.freebets.erase(ID.freebets.begin()+l);
- }
- else
- { double bett=atof( bet.c_str());
- if(bett>ID.balance && ID.balance==0)
- { cout<<"Mhdeniko upoloipo parakalw gemise to portofoli s apo to menou diaxeirhshs"<<endl;
- break;
- }
- else if(bett>ID.balance)
- { cout<< "Dwse mikrotero poso"<<endl;
- getline(cin,bet);
- continue;
- }
- else if(bett<=ID.balance)
- { ID.balance-=bett;
- bethistoryfun(bethistory,betid++,ID.user_id," ",bett,'-');
- historyfun(history,"bet",nodeid," ",ID.username,bett);
- break;
- }
- }
- }
- }
- }
- private:
- int flag;
- };
- class Trader:public Users
- { public:
- void bets(vector<Bethistory*> &bethistory,vector<History*> &history)
- { int l=0;
- cout<< "bet_id | user_id | node_id | stake | result " << endl;
- for (int i=0;i<bethistory.size();i++)
- { if (l++==20)
- break;
- cout << bethistory[i]->bet_id<< '\t' <<bethistory[i]->user_id<< '\t' <<bethistory[i]->node_id<< '\t' <<bethistory[i]->stake<< '\t' <<bethistory[i]->result<<endl;
- }
- }
- void freebets(vector<Users*> &User,vector<History*> &history)
- { string name;
- double x;
- int flag=0,i;
- while(1)
- { getline(cin,name);
- for(i=0;i<User.size();i++)
- { if(!User[i]->ID.username.compare(name))
- { flag=1;
- break;
- }
- }
- if(flag==1)
- break;
- }
- if(flag==1)
- { cin >> x;
- User[i]->ID.freebets.push_back(x);
- }
- }
- void Void()
- {
- }
- void Settle()
- {
- }
- void print()
- { 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;
- }
- void exprint()
- { print();
- cout<<"V(Void),gia na akurw8ei mia epilogh"<<endl<<"S(Settle),gia dieu8ethsh ths agoras"<<endl;
- }
- };
- class Director:public Users
- { public:
- void bets(vector<Bethistory*> &bethistory,vector<History*> &history)
- { int l=0;
- cout<< "bet_id | user_id | node_id | stake | result " << endl ;
- for (int i=0;i<bethistory.size();i++)
- { if (l++==20)
- break;
- cout << bethistory[i]->bet_id<< '\t' <<bethistory[i]->user_id<< '\t' <<bethistory[i]->node_id<< '\t' <<bethistory[i]->stake<< '\t' <<bethistory[i]->result<<endl;
- }
- historyfun(history,"Bets"," "," ",ID.username,0);
- }
- void freebets(vector<Users*> &User,vector<History*> &history)
- { string name;
- double x;
- int flag=0,i;
- while(1)
- { getline(cin,name);
- for(i=0;i<User.size();i++)
- { if(!User[i]->ID.username.compare(name))
- { flag=1;
- break;
- }
- }
- if(flag==1)
- break;
- }
- if(flag==1)
- { cin >> x;
- User[i]->ID.freebets.push_back(x);
- }
- }
- void save()
- { //save
- }
- void logs(vector<History*> &history)
- { int l=0;
- for (int i=0;i<history.size();i++)
- { if (l++==25)
- break;
- cout<<history[i]->username<<'\t'<<history[i]->operation<<'\t'<<history[i]->target<<'\t'<<history[i]->rename<<'\t'<<history[i]->money<<endl;
- }
- }
- void users()
- { cout<<"Epiloges:"<<endl<<"V(View),gia emfanish xrhstwn pinaka xrhstwn"<<endl<<"S(Search),gia anazhthsh xrhsth"<<endl<<"L(Lock,gia enallagh katastashs apokleismou"<<endl;
- flag=1;
- }
- void visibility(vector <History*> history, root* parent,root* nodeid)
- { parent->change(nodeid);
- }
- void rename(vector<Users*> &User,vector<History*> &history,root* nodeid)
- { string rename;
- getline(cin,rename);
- nodeid->change_name(rename);
- historyfun(history,"Rename",nodeid->path(),rename,ID.username,0.0);
- }
- void New(vector <History*> history,root *nodeid)
- {
- }
- void copy()
- { //dhmiourgia antigrafou
- }
- void Delete()
- { //diagrafh kombou
- }
- void view(vector <Users*> &User)
- { if (flag==1)
- { cout << "user_id | username | fullname | password | type | status | balance | freebets" << endl ;
- for (int i=0;i<User.size();i++)
- { 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';
- for (int l=0;l<User[i]->ID.freebets.size();l++)
- { cout<< User[i]->ID.freebets[l];
- if(l!=User[i]->ID.freebets.size()-1)
- cout<<",";
- else
- cout << endl;
- }
- }
- }
- else
- cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- void search(vector <Users*> &User)
- { if (flag==1)
- { string name;
- getline(cin,name);
- for(int i=0;i<User.size();i++)
- { if(User[i]->ID.username.find(name)!=User[i]->ID.username.npos)
- { 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';
- for (int l=0;l<User[i]->ID.freebets.size();l++)
- { cout<< User[i]->ID.freebets[l];
- if(l!=User[i]->ID.freebets.size()-1)
- cout<<",";
- else
- cout << endl;
- }
- }
- }
- }
- else
- cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- void lock(vector<Users*> &User,vector<History*> &history)
- { if (flag==1)
- { string name;
- string name3;
- int flag2=0,i;
- getline(cin,name);
- for(i=0;i<User.size();i++)
- {
- if(!User[i]->ID.username.compare(name) && User[i]->ID.type!=3)
- { if(User[i]->ID.status[0]!='L')
- { flag2=1;
- cout<<"Anefere logo"<<endl;
- getline(cin, name3);
- string name2="L,";
- User[i]->ID.status.replace(User[i]->ID.status.begin(),User[i]->ID.status.end(),name2);
- User[i]->ID.status.insert(2,name3);
- break;
- }
- else if(User[i]->ID.status[0]=='L')
- { flag2=1;
- cout<<"Anefere logo"<<endl;
- getline(cin, name3);
- User[i]->ID.status.replace(User[i]->ID.status.begin(),User[i]->ID.status.end(),name3);
- break;
- }
- }
- }
- if (flag2)
- { historyfun(history,"Lock",User[i]->ID.username,User[i]->ID.status,ID.username,0);
- }
- }
- else
- cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- void print()
- { 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;
- }
- void exprint()
- { print();
- 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;
- }
- private:
- int flag;
- };
- void write_users(vector<Users*>& User){
- remove("users.csv");
- ofstream file;
- file.open("users.csv",ios::out);
- file << "user_id | username | fullname | password | type | status | balance | freebets" << endl ;
- int i,j;
- for(i=0;i<User.size();i++){
- file << User[i]->ID.user_id << "|" << User[i]->ID.username << "|" << User[i]->ID.fullname << "|";
- file << User[i]->ID.password << "|" << User[i]->ID.type << "|" << User[i]->ID.status << "|" << User[i]->ID.balance << "|";
- for(j=0;j<User[i]->ID.freebets.size();j++){
- file << User[i]->ID.freebets[j];
- if (j<User[i]->ID.freebets.size()-1){
- file << ",";
- }
- }
- file << endl;
- }
- file.close();
- }
- void write_history(vector <History*> &history){
- remove("audit.log");
- ofstream file;
- file.open("audit.log",ios::out);
- file << "username | operation | money | target | rename";
- for(int i=0;i<history.size();i++){
- file << history[i]->username << "|" << history[i]->operation << "|" << history[i]->money << "|" << history[i]->target << "|" << history[i]->rename[i] << endl;
- }
- file.close();
- }
- void write_bet(vector <Bethistory*> &bethistory){
- remove("bets.csv");
- ofstream file;
- file.open("bets.csv",ios::out);
- file << "bet_id | user_id | node_id | stake | result " << endl ;
- for(int i=0;i<bethistory.size() ;i++){
- file << bethistory[i]->bet_id<< "|" << bethistory[i]->user_id << "|" << bethistory[i]->node_id << "|" << bethistory[i]->stake <<"|" << bethistory[i]->result <<endl;
- }
- file.close();
- }
- void read_users(vector<Users*> &User){
- ifstream file;
- file.open("users.csv",ios::in);
- if(file.fail()){
- cerr << "Error openning file" << endl;
- exit(1);
- }
- string line;
- getline(file,line);
- //pairnw to prwto line to arxeiasto me ta userid username ktl kai de to xrhsimopoiw
- while(getline(file,line)){
- //exw twra to line pou me | exei ola ta stoixeia
- const char s[2]="|";
- char* token;
- Users temp;
- //converting string to char*
- char *str = new char[line.length() + 1];
- strcpy(str, line.c_str());
- //
- token = strtok(str,s);
- temp.ID.user_id = atoi(token); //(kanw to char* int)
- token = strtok(NULL, s);
- temp.ID.username = token;
- token = strtok(NULL, s);
- temp.ID.fullname = token;
- token = strtok(NULL, s);
- temp.ID.password = token;
- token = strtok(NULL, s);
- temp.ID.type = atoi(token); //kanw to char* int
- token = strtok(NULL, s);
- temp.ID.status =token;
- token = strtok(NULL, s);
- temp.ID.balance = atof(token); //kanw char* float
- token = strtok(NULL, s);
- //twra to token einai san ena char* kai prepei pali na to kopsw me delimeter to ,
- char* token2;
- const char d[2]=",";
- token2=strtok(token,d);
- while(token2 != NULL){
- temp.ID.freebets.push_back(atof(token2)); //char* to float
- token2 = strtok(NULL, d);
- }
- if(temp.ID.type==1){
- User.push_back(new Punter());
- }
- else if(temp.ID.type==2){
- User.push_back(new Trader());
- }
- else{
- User.push_back(new Director());
- }
- int i=User.size()-1;
- User[i]->ID.user_id=temp.ID.user_id;
- User[i]->ID.username.assign(temp.ID.username);
- User[i]->ID.fullname.assign(temp.ID.fullname);
- User[i]->ID.password.assign(temp.ID.password);
- User[i]->ID.type=temp.ID.type;
- User[i]->ID.status.assign(temp.ID.status);
- User[i]->ID.balance=temp.ID.balance;
- for(int l=0;l<temp.ID.freebets.size();l++)
- { User[i]->ID.freebets.push_back(temp.ID.freebets[l]);
- }
- }
- //etoimo to User
- file.close();
- }
- void read_history(vector <History*> &history){
- ifstream file;
- file.open("audit.log",ios::in);
- if(file.fail()){
- cerr << "Error openning file" << endl;
- exit(1);
- }
- string line;
- getline(file,line);
- while(getline(file,line)){
- const char s[2]="|";
- char* token;
- History temp;
- //converting string to char*
- char *str = new char[line.length() + 1];
- strcpy(str, line.c_str());
- //
- token = strtok(str,s);
- temp.username = token;
- token = strtok(NULL, s);
- temp.operation = token;
- token = strtok(NULL, s);
- temp.money = atof(token);
- token = strtok(NULL, s);
- temp.target =token;
- token = strtok(NULL, s);
- temp.rename =token;
- //
- history.push_back(new History());
- int i = history.size()-1;
- //
- history[i]->username.assign(temp.username);
- history[i]->operation.assign(temp.operation);
- history[i]->target.assign(temp.target);
- history[i]->rename.assign(temp.rename);
- history[i]->money = temp.money;
- //
- }
- file.close();
- }
- void read_bet(vector <Bethistory*> &bethistory){
- ifstream file;
- file.open("bets.csv",ios::in);
- if(file.fail()){
- cerr << "Error openning file" << endl;
- exit(1);
- }
- string line;
- getline(file,line);
- while(getline(file,line)){
- const char s[2]="|";
- char* token;
- Bethistory temp;
- //converting string to char*
- char *str = new char[line.length() + 1];
- strcpy(str, line.c_str());
- //
- token = strtok(str,s);
- temp.bet_id = atoi(token);
- token = strtok(NULL, s);
- temp.user_id = atoi(token);
- token = strtok(NULL, s);
- temp.node_id = token;
- token = strtok(NULL, s);
- temp.stake = atof(token);
- token = strtok(NULL, s);
- temp.result = token[0];
- token = strtok(NULL, s);
- //
- bethistory.push_back(new Bethistory());
- int i = bethistory.size()-1;
- //
- bethistory[i]->bet_id = temp.bet_id;
- bethistory[i]->user_id = temp.user_id;
- bethistory[i]->node_id.assign(temp.node_id);
- bethistory[i]->stake = temp.stake;
- bethistory[i]->result= temp.result;
- //
- }
- file.close();
- }
- int main(int argc, char** argv) {
- vector<Users*> User;
- vector<History*> history;
- vector<Bethistory*> bethistory;
- /*
- Users mark;
- mark.ID.user_id = 1;
- mark.ID.username = "Nikos";
- mark.ID.fullname = "Tsougkrana";
- mark.ID.password = "12345656";
- mark.ID.type = 3;
- mark.ID.status ="SMTH";
- mark.ID.balance = 1234.556;
- mark.ID.freebets.push_back(10.5 );
- mark.ID.freebets.push_back(70.5 );
- mark.ID.freebets.push_back(120.5 );
- User.push_back(&mark);
- Users nik;
- nik.ID.user_id = 2;
- nik.ID.username = "kombra";
- nik.ID.fullname = "anakloda";
- nik.ID.password = ";;45656";
- nik.ID.type = 1;
- nik.ID.status ="SMiTH";
- nik.ID.balance = 4.3;
- nik.ID.freebets.push_back(20.5 );
- nik.ID.freebets.push_back(7.5 );
- nik.ID.freebets.push_back(10.5 );
- User.push_back(&nik);
- write_users(User);
- bethistoryfun(bethistory,10,1,"1.1.2.3",10.5,'W');
- write_bet(bethistory);
- */
- read_users(User);
- write_users(User);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement