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>
- #include <algorithm>
- #include <sstream>
- #include <stdio.h>
- #include <ctype.h>
- using namespace std;
- int betid=1;
- int ctoggle=1;
- class category;
- class subcategory;
- class event;
- class market;
- class selection;
- void capitalize(string *str){
- transform(str->begin(), str->end(), str->begin(), ::tolower);
- }
- 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);
- }
- root* visiblenode(int i)
- { int l=0;
- while(l<i)
- { if(nodes[i]->get_visibility())
- { l++;
- }
- }
- return nodes[l];
- }
- root* notvisiblenode(int i)
- { return nodes[i];
- }
- int get_visibility()
- { return visibility;
- }
- void change_name(string n)
- { name.replace(name.begin(),name.end(),n);
- }
- virtual void change_visibility()
- { cout << "You cannot change the visibility of root"<<endl;
- }
- string path()
- { return ID;
- }
- string get_name()
- { return name;
- }
- virtual string get_price()
- {
- }
- void show()
- { for(int i=0;i<nodes.size();i++)
- nodes[i]->printext();
- }
- virtual void printext()
- { cout<<ID<< " " << name <<endl;
- }
- virtual void push(string choice);
- void readh(category* temp);
- virtual void readh(subcategory* temp)
- {
- }
- virtual void readh(event* temp)
- {
- }
- virtual void readh(market* temp)
- {
- }
- virtual void readh(selection* temp)
- {
- }
- root* rnode(int i)
- { return nodes[i];
- }
- virtual void copynode(int i)
- { string n;
- n.assign("Copied-");
- n.append(nodes[i]->get_name());
- push(n);
- copyn(nodes[i],nodes[nodes.size()-1]);
- }
- virtual void copyn(root* copying,root* copied )
- { for(int i=0;i<copying->nodes.size();i++)
- { string t;
- t.assign("Copied");
- t.append(copying->nodes[i]->get_name());
- copied->push(t);
- copyn(copying->nodes[i],copied->nodes[i]);
- }
- }
- virtual string voidd(int i)
- { root* node;
- node=visiblenode(i);
- return node->path();
- }
- virtual void deletes()
- { for(int i=0;i<nodes.size();i++)
- { nodes[i]->deletes();
- }
- delete this;
- }
- virtual void write(ofstream& file)
- { file << ID << "|" << name << "|"<< endl;
- for(int i=0;i<nodes.size();i++)
- nodes[i]->write(file);
- }
- };
- class category : public root{
- public:
- string ID;
- category(string n,string id):root(n,id)
- {
- }
- void change_visibility()
- { visibility!=visibility;
- for(int i=0;i<nodes.size();i++)
- { nodes[i]->change_visibility();
- }
- }
- void push(string choice);
- void readh(subcategory* temp);
- };
- class subcategory : public root{
- public:
- subcategory(string n,string id):root(n,id)
- {
- }
- void change_visibility()
- { visibility!=visibility;
- for(int i=0;i<nodes.size();i++)
- { nodes[i]->change_visibility();
- }
- }
- void push(string choice);
- void readh(event* temp);
- };
- class event : puablic root{
- string date;
- string time;
- public:
- event(string n,string id , string d,string t):root(n,id)
- { date.assign(d);
- time.assign(t);
- }
- void change_visibility()
- { visibility!=visibility;
- for(int i=0;i<nodes.size();i++)
- { nodes[i]->change_visibility();
- }
- }
- string get_date(){
- return date;
- }
- string get_time(){
- return time;
- }
- void printext()
- { cout<<ID<< " " << name <<" - "<<date<<" "<<time <<endl;
- }
- void push(string choice);
- void readh(market* temp);
- void write(ofstream& file)
- { file << ID << "|" << name << "|" << time << "|" << date << "|" <<endl;
- for(int i=0;i<nodes.size();i++)
- nodes[i]->write(file);
- }
- };
- class selection : public root{
- string price;
- int price2;
- public:
- selection(string n,string id,string p):root(n,id)
- { price.assign(p);
- int t1,t2;
- string temp1;
- char *temp2 = new char[price.length() + 1];
- copy(price.begin(),price.end(),temp2);
- char s[2]="/";
- temp1=strtok(temp2,s);
- stringstream buffer(temp1);
- buffer >> t1;
- stringstream buffer2(temp2);
- buffer2 >> t2;
- price2=(double)t1/(double)t2;
- }
- string get_price(){
- return price;
- }
- void change_visibility()
- { visibility!=visibility;
- for(int i=0;i<nodes.size();i++)
- { nodes[i]->change_visibility();
- }
- }
- virtual void printext()
- { cout<<ID<< " " << name <<"#"<<price<<endl;
- }
- void write(ofstream& file)
- { file << ID << "|" << name << "|" << '#' << price << "|" <<endl;
- for(int i=0;i<nodes.size();i++)
- nodes[i]->write(file);
- }
- };
- class market : public root{
- public:
- market(string n,string id):root(n,id)
- {
- }
- void change_visibility()
- { visibility!=visibility;
- for(int i=0;i<nodes.size();i++)
- { nodes[i]->change_visibility();
- }
- }
- void push(string choice);
- void readh(selection* temp);
- };
- void root::readh(category* temp)
- { nodes.push_back(temp);
- }
- void category::readh(subcategory* temp)
- { nodes.push_back(temp);
- }
- void subcategory::readh(event* temp)
- { nodes.push_back(temp);
- }
- void event::readh(market* temp)
- { nodes.push_back(temp);
- }
- void market::readh(selection* temp)
- { nodes.push_back(temp);
- }
- void root::push(string choice)
- { string NID;
- NID.assign(ID);
- ostringstream convert;
- convert << nodes.size();
- string temp3=convert.str();
- NID.insert(NID.size(),temp3);
- NID.insert(NID.end(),'.');
- root* temp2=new category(choice,NID);
- }
- void category::push(string choice)
- { string NID;
- NID.assign(ID);
- NID.insert(NID.end(),'.');
- ostringstream convert;
- convert << nodes.size();
- string temp3=convert.str();
- NID.insert(NID.size(),temp3);
- root* temp2=new subcategory(choice,NID);
- }
- void subcategory::push(string choice)
- { string NID;
- NID.assign(ID);
- NID.insert(NID.end(),'.');
- ostringstream convert;
- convert << nodes.size();
- string temp3=convert.str();
- NID.insert(NID.size(),temp3);
- string date;
- string time;
- cout<<"Dwse hmeromhnia"<<endl;
- getline(cin,date);
- cout<<"Dwse xrono"<<endl;
- getline(cin,time);
- root* temp2=new event(choice,NID,date,time);
- }
- void event::push(string choice)
- { string NID;
- NID.assign(ID);
- NID.insert(NID.end(),'.');
- ostringstream convert;
- convert << nodes.size();
- string temp3=convert.str();
- NID.insert(NID.size(),temp3);
- root* temp2=new market(choice,NID);
- }
- void market::push(string choice)
- { string NID;
- NID.assign(ID);
- NID.insert(NID.end(),'.');
- ostringstream convert;
- convert << nodes.size();
- string temp3=convert.str();
- NID.insert(NID.size(),temp3);
- cout<<"Dwse price se klasma"<<endl;
- string price;
- getline(cin,price);
- root* temp2=new selection(choice,NID,price);
- }
- 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()
- { ctoggle= !ctoggle;
- }
- 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,root* parent,root* nodeid)
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void New(root* parent,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(vector<Users*> &User,vector<Bethistory*> &bethistory)
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void Settle(vector<Users*> &User,vector<Bethistory*> &bethistory)
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void visibility(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,root* parent,root* nodeid)
- { 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);
- break;
- }
- else if(isdigit(bet[0]))
- { 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;
- continue;
- }
- else if(bett<=ID.balance)
- { ID.balance-=bett;
- bethistoryfun(bethistory,betid++,ID.user_id," ",bett,'-');
- historyfun(history,"bet",nodeid," ",ID.username,bett);
- break;
- }
- }
- else
- { cout<<"La8os epilogh"<<endl;
- 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(vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid)
- { cout<<"Dwse to id ths epiloghs stoixhmatismou p 8es na akurw8ei"<<endl;
- string choice;
- getline(cin,choice);
- if(isdigit(choice[0]))
- { stringstream buffer(choice);
- int i;
- buffer >> i;
- i--;
- string id=nodeid->voidd(i);
- for(int l=0;l<bethistory.size();l++)
- { if(!(id.compare(bethistory[l]->node_id)))
- { if(bethistory[l]->result=='-')
- { bethistory[l]->result='V';
- for(int j=0;j<User.size();j++)
- { if(bethistory[l]->user_id==User[j]->ID.user_id)
- { User[j]->ID.balance+=bethistory[l]->stake;
- }
- }
- }
- else
- { cout<<"Already voided"<<endl;
- break;
- }
- }
- }
- //enhmerwsh arxeiwn xrhstwn kai bet
- }
- else
- { cout<<"Operation aborted wrong input"<<endl;
- }
- }
- void Settle(vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid)
- { cout<<"Dwse to id ths epiloghs stoixhmatismou p 8es na 8ewrh8ei ws nikh"<<endl;
- string choice;
- getline(cin,choice);
- if(isdigit(choice[0]))
- { stringstream buffer(choice);
- int i;
- buffer >> i;
- i--;
- string id=nodeid->voidd(i);
- root* temp;
- temp=nodeid->visiblenode(i);
- string sprice;
- string token;
- double price1,price2,price;
- sprice=temp->get_price();
- char *str = new char[sprice.length() + 1];
- char s[2]="/";
- strcpy(str, sprice.c_str());
- token = strtok(str,s);
- price1=atof(token.c_str());
- price2=atof(str);
- price=(price1/price2) + 1;
- for(int l=0;l<bethistory.size();l++)
- { if(!(id.compare(bethistory[l]->node_id)))
- { if(bethistory[l]->result=='-')
- { bethistory[l]->result='W';
- for(int j=0;j<User.size();j++)
- { if(bethistory[l]->user_id==User[j]->ID.user_id)
- { User[j]->ID.balance+=bethistory[l]->stake*price;
- }
- }
- }
- else
- { cout<<"Already changed"<<endl;
- break;
- }
- }
- }
- string lose_id;
- lose_id.assign(id);
- lose_id.erase(lose_id.size()-1);
- lose_id.erase(lose_id.size()-1);
- for(int l=0;l<bethistory.size();l++)
- { if(bethistory[l]->node_id!=id && bethistory[l]->node_id.find(lose_id)!=bethistory[l]->node_id.npos && bethistory[l]->result=='-')
- { bethistory[l]->result='L';
- }
- }
- //enhmerwsh arxeiwn xrhstwn kai bet
- }
- else
- { cout<<"Operation aborted wrong input"<<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;
- }
- 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(root* root,vector<Users*> &User,vector<History*> &history,vector <Bethistory*> &bethistory);
- 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(root* nodeid)
- { nodeid->change_visibility();
- }
- void rename(vector<Users*> &User,root* nodeid)
- { nodeid->show();
- string choice;
- cout<<"Dwse id h cancel/abort gia akurwsh"<<endl;
- if(isdigit(choice[0]))
- { stringstream buffer(choice);
- int i;
- buffer >> i;
- i--;
- root* temp=nodeid->rnode(i);
- cout<<"Dwse neo onoma h abort/cancel gia akurwsh"<<endl;
- string rename;
- string temp2=rename;
- capitalize(&temp2);
- if(temp2!="cancel"&& temp2!="abort" && temp2!="a" && temp2!="c")
- { temp->change_name(rename);
- }
- else
- cout<<"Procedure aborted"<<endl;
- }
- else
- { cout<<"Procedure aborted"<<endl;
- }
- }
- void New(root *nodeid)
- { nodeid->show();
- cout<<"Dwse neo onoma kombou h cancel/abort gia akurwsh"<<endl;
- string choice;
- getline(cin,choice);
- string temp=choice;
- capitalize(&temp);
- if(temp!="cancel"&& temp!="abort" && temp!="a" && temp!="c")
- { nodeid->push(choice);
- }
- else
- cout<<"Procedure aborted"<<endl;
- }
- virtual void copynode(root* nodeid)
- { cout << "Dwse ID gia na ginei copy h cancel/abort gia akurwsh";
- string choice;
- getline(cin,choice);
- if(isdigit(choice[0]))
- { stringstream buffer(choice);
- int i;
- buffer >> i;
- i--;
- nodeid->copynode(i);
- }
- else
- { cout<<"Procedure aborted"<<endl;
- }
- }
- 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)
- { 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;
- }
- }
- }
- }
- 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 write_hierarchy(root* Root)
- { remove("hierarchy.dat");
- ofstream file;
- file.open("hierarchy.dat",ios::out);
- Root->write(file);
- file.close();
- }
- void Director::save(root* root,vector<Users*> &User,vector<History*> &history,vector <Bethistory*> &bethistory)
- { write_users(User);
- write_history(history);
- write_bet(bethistory);
- write_hierarchy(root);
- }
- void read_hierarchy(root* Root){
- vector <root*> hierarchy2;
- vector <root*> hierarchy3;
- vector <root*> hierarchy4;
- vector <root*> hierarchy5;
- ifstream file;
- file.open("hierarchy.dat",ios::in);
- if(file.fail()){
- cerr << "Error openning file" << endl;
- exit(1);
- }
- string line;
- while(getline(file,line)){
- const char s[2]=" ";
- char* token;
- //converting string to char*
- char *str = new char[line.length() + 1];
- strcpy(str, line.c_str());
- //
- token = strtok(str,s);
- string node(token);
- size_t n = count(node.begin(), node.end(), '.'); // number of dots
- token = strtok(NULL, s); //oti apomenei meta to node
- if(n == 1)
- { category* temp=new category(token,node);
- Root->readh(temp);
- hierarchy2.push_back(temp);
- }
- if(n==2){
- subcategory* temp=new subcategory(token,node);
- hierarchy2[hierarchy2.size()-1]->readh(temp);
- hierarchy3.push_back(temp);
- }
- if(n == 3){
- strcpy(str,token); //str = token
- const char h[2] = "-";
- token = strtok(str,h);
- char* n;
- strcpy(n,token);
- token = strtok(NULL,s); //date
- char* d;
- strcpy(d,token);
- token = strtok(NULL,s);
- event* temp=new event(n,node,d,token);
- hierarchy3[hierarchy3.size()-1]->readh(temp);
- hierarchy4.push_back(temp);
- }
- if(n == 4){
- market* temp=new market(token,node);
- hierarchy4[hierarchy4.size()-1]->readh(temp);
- hierarchy5.push_back(temp);
- }
- if(n == 5){
- strcpy(str,token); //str = token
- const char h[2] = "#";
- token = strtok(str,h);
- string n=token; // name
- token = strtok(NULL,h); //price
- selection* temp=new selection(n,node,token);
- hierarchy5[hierarchy5.size()-1]->readh(temp);
- }
- }
- }
- 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();
- }
- void register_user(vector<Users*> &User,Users& current_user){
- int redo;
- string name;
- do{
- redo=0;
- cout << "username: ";
- getline (cin, name);
- for(int i=0;i<User.size();i++){
- if(name.compare(User[i]->ID.username) == 0){
- cout << "This name already exists please type a different name!" << endl;
- redo = 1;
- }
- if(name.compare("\n") == 0 || name.compare("guest:guest")==0){
- cout << "forbidden name,please type a different name" << endl;
- redo=1;
- }
- }
- }while(redo);
- //
- User.push_back(new Punter);
- int i = User.size()-1;
- User[i]->ID.user_id = i+1;
- User[i]->ID.username.assign(name);
- User[i]->ID.fullname.assign(name); // this could be changed later in the account settings
- User[i]->ID.type = 1;
- User[i]->ID.status.assign("A");
- User[i]->ID.balance = 0.0;
- User[i]->ID.freebets.push_back(0.0); //
- do{
- redo=0;
- cout << "password: ";
- string pass1;
- getline (cin,pass1);
- cout << "Please retype your password:" ;
- string pass2;
- getline (cin,pass2);
- if (pass1.compare(pass2) != 0){
- cout << "You should insert the same password twice" << endl;
- redo=1;
- }
- else{
- User[i]->ID.password.assign(pass1);
- }
- }while(redo);
- write_users(User); //arxeio susthmatos save
- current_user = *User[i];
- User[i]->exprint();
- }
- void login_user(vector<Users*> &User,Users& current_user){
- cout << "Welcome to KAPPA BET!" << endl;
- cout << "Please type username and password to login to your account!" << endl;
- cout << "If you don't have an account ,press (Enter) or type guest:guest to login as guest" << endl;
- int anagnwr=-1;
- int guest=0;
- int redo;
- do{
- redo=0;
- cout << "username: " ;
- string name;
- string rightpass;
- getline(cin,name);
- if (name.size()==0)
- name.assign("\n");
- if((name.compare("guest:guest") == 0) || name.compare("\n")==0){
- guest = 1;
- break;
- }
- for(int i=0;i<User.size();i++){
- if(name.compare(User[i]->ID.username) == 0){
- rightpass.assign(User[i]->ID.password);
- anagnwr=i;
- }
- }
- string provpass;
- cout << "password: ";
- getline(cin,provpass);
- if(provpass.size()==0)
- provpass.assign("\n");
- if(provpass.compare(rightpass) == 0){
- redo=0;
- }
- else{
- cout << "Wrong Credentials! Please Retry!" << endl;
- redo=1;
- }
- }while(redo);
- if(guest == 0){
- char locked = 'L';
- if(locked == User[anagnwr]->ID.status[0]){
- cout << "Your account has been locked due to: ";
- for(int i=2;i<User[anagnwr]->ID.status.size();i++){
- cout << User[anagnwr]->ID.status[i];
- }
- exit(1);
- }
- }
- //eisodos xrhsth sto arxiko menu analoga me to user.type h an einai guest
- if(guest == 1){
- Users* temp = new Guest();
- //gurnaw
- current_user = *temp;
- temp->exprint();
- }
- else{
- current_user = *User[anagnwr];
- User[anagnwr]->exprint();
- }
- write_users(User);
- }
- int main(int argc, char** argv) {
- vector<Users*> User;
- vector<History*> history;
- vector<Bethistory*> bethistory;
- read_users(User);
- Users currentUser;
- if (argc == 1){
- //xwris parameters
- login_user(User,currentUser);
- }
- else if(argc == 2){
- //mia parametros
- string parameter(argv[1]);
- capitalize(¶meter);
- if(strcmp(parameter.c_str(),"-r") == 0){
- //register a user
- register_user(User,currentUser);
- }
- }
- //management input
- bethistoryfun(bethistory,10,1,"1.1.2.3",10.5,'W');
- write_bet(bethistory);
- write_users(User);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement