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;
- class Users;
- struct Bethistory;
- struct History;
- void capitalow(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()
- { for(int i=0;i<nodes.size();i++)
- { delete nodes[i];
- }
- nodes.clear();
- delete this;
- }
- root* visiblenode(int i)
- { int l=0;
- while(l<i)
- { if(nodes[i]->get_visibility())
- { l++;
- }
- }
- return nodes[l];
- }
- virtual string get_date()
- {
- }
- virtual string get_time()
- {
- }
- int Size()
- { return nodes.size();
- }
- 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()
- {
- }
- virtual double get_price2()
- {
- }
- 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)
- {
- }
- 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]);
- nodes[nodes.size()-1]->change_visibility();
- }
- virtual void copyn(root* copying,root* copied )
- { copied=copied->cpush(copying,path());
- for(int i=0;i<copying->Size();i++)
- { copyn(copying->nodes[i],copied->nodes[i]);
- }
- }
- virtual string voidd(int i)
- { root* node;
- node=visiblenode(i);
- return node->path();
- }
- virtual void deletes(int i)
- { delete nodes[i];
- nodes.erase(nodes.begin()+i);
- for(int i=0;i<nodes.size();i++)
- { nodes[i]->changeid(ID,i+1);
- }
- }
- void changeid(string ID2,int l)
- { ID.replace(ID.begin(),ID.end(),ID2);
- ostringstream convert;
- convert << l;
- string temp3=convert.str();
- ID.insert(ID.size(),temp3);
- ID.insert(ID.end(),'.');
- for(int i=0;i<nodes.size();i++)
- { nodes[i]->changeid(ID,i+1);
- }
- }
- virtual void write(ofstream& file)
- { for(int i=0;i<nodes.size();i++)
- nodes[i]->write(file);
- }
- virtual root* cpush(root* copying,string)
- {
- }
- virtual root* cpush(category* copying,string)
- {
- }
- virtual root* cpush(subcategory* copying,string)
- {
- }
- virtual root* cpush(event* copying,string)
- {
- }
- virtual root* cpush(market* copying,string)
- {
- }
- virtual root* cpush(selection* copying,string)
- {
- }
- virtual void preplace(Users* current_user,vector <Bethistory*> bethistory,vector <History*> history)
- { cout<<"Den exeis prosbash se authn thn entolh apo auton ton kombo" <<endl;
- }
- virtual void prevoid(Users* current_user,vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid)
- { cout<<"Den exeis prosbash se authn thn entolh apo auton ton kombo" <<endl;
- }
- virtual void presettle(Users* current_user,vector <Users*> &User,vector <Bethistory*> &bethistory,root* nodeid)
- { cout<<"Den exeis prosbash se authn thn entolh apo auton ton kombo" <<endl;
- }
- virtual void preprint(Users* current_user);
- };
- class category : public root{
- public:
- 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);
- root* cpush(category* copying,string);
- void write(ofstream& file)
- {
- file << path() << " " << get_name() << endl;
- for(int i=0;i<nodes.size();i++)
- nodes[i]->write(file);
- }
- };
- 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);
- root* cpush(subcategory* copying,string);
- void copynode(int i);
- void write(ofstream& file)
- { file << path() << " " << get_name() << endl;
- for(int i=0;i<nodes.size();i++)
- nodes[i]->write(file);
- }
- };
- 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);
- }
- 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<< " " << get_name() <<" - "<<date<<" "<<time <<endl;
- }
- void push(string choice);
- void readh(market* temp);
- void write(ofstream& file)
- { file << ID << " " << name << " - " << date << " " << time <<endl;
- for(int i=0;i<nodes.size();i++)
- nodes[i]->write(file);
- }
- root* cpush(event* copying,string);
- };
- void subcategory::copynode(int i)
- { string choice;
- choice.assign("Copied-");
- choice.append(nodes[i]->get_name());
- string NID;
- NID.assign(nodes[i]->path());
- string date,time;
- date.assign(nodes[i]->get_date());
- time.assign(nodes[i]->get_time());
- root* temp2=new event(choice,NID,date,time);
- nodes.push_back(temp2);
- copyn(nodes[i],nodes[nodes.size()-1]);
- nodes[nodes.size()-1]->change_visibility();
- }
- 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 +1;
- }
- string get_price(){
- return price;
- }
- double get_price2()
- { return price2;
- }
- void change_visibility()
- { visibility!=visibility;
- for(int i=0;i<nodes.size();i++)
- { nodes[i]->change_visibility();
- }
- }
- void copynode(int i)
- { cout<<"Not available"<<endl;
- }
- void printext()
- { if(ctoggle==0)
- cout<<ID<< " " << name <<"#"<<price<<endl;
- else
- cout<<ID<< " " << name <<"#"<<price2<<endl;
- }
- void write(ofstream& file)
- { file << ID << " " << name << '#' << price <<endl;
- for(int i=0;i<nodes.size();i++)
- nodes[i]->write(file);
- }
- root* cpush(selection* copying,string);
- };
- 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);
- root* cpush(market* copying,string);
- void write(ofstream& file)
- { file << ID << " " << name << endl;
- for(int i=0;i<nodes.size();i++)
- nodes[i]->write(file);
- }
- virtual void copynode(int i)
- { string choice;
- choice.assign("Copied-");
- choice.append(nodes[i]->get_name());
- string NID;
- NID.assign(nodes[i]->path());
- string price;
- price.assign(nodes[i]->get_price());
- root* temp2=new selection(choice,NID,price);
- nodes.push_back(temp2);
- copyn(nodes[i],nodes[nodes.size()-1]);
- nodes[nodes.size()-1]->change_visibility();
- }
- void preplace(Users& current_user,vector <Bethistory*> bethistory,vector <History*> history);
- void prevoid(Users& current_user,vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid);
- void presettle(Users& current_user,vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid);
- void preprint(Users& current_user);
- };
- 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);
- nodes.push_back(temp2);
- }
- 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);
- nodes.push_back(temp2);
- }
- 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);
- nodes.push_back(temp2);
- }
- 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);
- nodes.push_back(temp2);
- }
- 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);
- nodes.push_back(temp2);
- }
- root* category::cpush(category* copying,string NID)
- { string choice;
- choice.assign("Copied-");
- choice.append(copying->get_name());
- root* temp2=new category(choice,NID);
- return temp2;
- }
- root* subcategory::cpush(subcategory* copying,string NID)
- { string choice;
- choice.assign("Copied-");
- choice.append(copying->get_name());
- root* temp2=new subcategory(choice,NID);
- return temp2;
- }
- root* event::cpush(event* copying,string NID)
- { string choice;
- choice.assign("Copied-");
- choice.append(copying->get_name());
- string date,time;
- date.assign(copying->get_date());
- time.assign(copying->get_time());
- root* temp2=new event(choice,NID,date,time);
- return temp2;
- }
- root* market::cpush(market* copying,string NID)
- { string choice;
- choice.assign("Copied-");
- choice.append(copying->get_name());
- root* temp2=new market(choice,NID);
- return temp2;
- }
- root* selection::cpush(selection* copying,string NID)
- { string choice;
- choice.assign("Copied-");
- choice.append(copying->get_name());
- price.assign(copying->get_price());
- root* temp2=new selection(choice,NID,price);
- return temp2;
- }
- 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(vector <root*> &path,root* current_node)
- { for(int i=path.size()-1;i>0;i--)
- { path.erase(path.begin()+i);
- }
- current_node=path[0];
- }
- 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(root* root,vector<Users*> &User,vector<History*> &history,vector <Bethistory*> &bethistory)
- { 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* nodeid)
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void New(root *nodeid)
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void Copy(root* nodeid)
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void Delete(root* nodeid)
- { 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)
- { 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,root* nodeid)
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void Settle(vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid)
- { 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* 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;
- flag=0;
- }
- 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;
- flag=0;
- }
- 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;
- flag=0;
- }
- 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 id h cancel gia akurwsh"<<endl;
- getline(cin,choice);
- if(choice.compare("cancel"));
- { stringstream buffer(choice);
- int i;
- buffer >> i;
- i--;
- ostringstream buffer2;
- buffer2<<i;
- choice.replace(choice.begin(),choice.end(),buffer2.str());
- nodeid.append(choice);
- nodeid.insert(nodeid.end(),'.');
- 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,nodeid,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,nodeid,bett,'-');
- historyfun(history,"bet",nodeid," ",ID.username,bett);
- break;
- }
- }
- else
- { cout<<"La8os epilogh"<<endl;
- break;
- }
- }
- }
- flag=0;
- }
- 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 token;
- double price;
- price=temp->get_price2();
- 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);
- flag=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);
- }
- flag=0;
- }
- 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;
- }
- flag=0;
- }
- 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();
- flag=0;
- }
- void Rename(vector<Users*> &User,vector<History*> &history,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->notvisiblenode(i);
- cout<<"Dwse neo onoma h abort/cancel gia akurwsh"<<endl;
- string rename;
- string temp2=rename;
- capitalow(&temp2);
- if(temp2!="cancel"&& temp2!="abort" && temp2!="a" && temp2!="c")
- { temp->change_name(rename);
- }
- else
- cout<<"Procedure aborted"<<endl;
- }
- else
- { cout<<"Procedure aborted"<<endl;
- }
- flag=0;
- }
- 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;
- capitalow(&temp);
- if(temp!="cancel"&& temp!="abort" && temp!="a" && temp!="c")
- { nodeid->push(choice);
- }
- else
- cout<<"Procedure aborted"<<endl;
- flag=0;
- }
- void Copy(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;
- }
- flag=0;
- }
- void Delete(root* nodeid)
- { string choice;
- cout<<"Id kombou gia diagrafh"<<endl;
- getline (cin,choice);
- capitalow(&choice);
- if(isdigit(choice[0]))
- { stringstream buffer(choice);
- int i;
- buffer >> i;
- i--;
- string choice2;
- cout<<"Eisai sigouros? Y gia nai kai N gia oxi"<<endl;
- if (choice2[0]=='Y' || choice2[0]=='y')
- nodeid->deletes(i);
- else
- cout<<"Aborted"<<endl;
- }
- else
- cout<<"Aborted"<<endl;
- flag=0;
- }
- 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;
- flag=0;
- }
- 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;
- flag=0;
- }
- 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;
- flag=0;
- }
- 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();
- }
- private:
- int flag;
- };
- void root::preprint(Users* current_user)
- { current_user->print();
- }
- void market::preplace(Users& current_user,vector <Bethistory*> bethistory,vector <History*> history)
- { current_user.place(bethistory,history,ID);
- }
- void market::prevoid(Users& current_user,vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid)
- { current_user.Void(User,bethistory,nodeid);
- }
- void market::presettle(Users& current_user,vector<Users*> &User,vector<Bethistory*> &bethistory,root* nodeid)
- { current_user.Settle(User,bethistory,nodeid);
- }
- void market::preprint(Users& current_user)
- { current_user.exprint();
- }
- 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.txt");
- ofstream file;
- file.open("hierarchy.dat.txt",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.txt",ios::in);
- if(file.fail()){
- cerr << "Error openning file" << endl;
- exit(1);
- }
- string line;
- while(getline(file,line)){
- const char s[2]=" ";
- const char d[2]="\n";
- 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, d); //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[3] = " -";
- char* n;
- char* date;
- char* time;
- n = strtok(str,h);
- date=strtok(NULL,s); //date
- time = strtok(NULL,d);
- event* temp=new event(n,node,date,time);
- 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] = "#";
- char* n;
- n = strtok(str,h);
- 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 management_input(Users* currentUser,vector<Users*> &User, vector<History*> &history, vector<Bethistory*> &bethistory, vector<root*> &Root){
- //ari8mo san inpout 1 isdigit plohghsh kalw plohghsh char sth sunarthsh entolwn px place
- while(1){
- root* current_node;
- int i=Root.size()-1;
- current_node = Root[i];
- current_node->preprint(currentUser);
- string entoli;
- getline(cin,entoli);
- if(isdigit(entoli[0])){
- //plohghsh(entoli);
- }
- else{
- int check =0;
- capitalow(&entoli);
- if(entoli.size() > 1){
- check = 1;
- }
- char ent;
- ent=entoli[0];
- if(ent == 'h'){
- if(check){
- if(entoli.compare("home") == 0){
- currentUser->home(Root,current_node);
- }
- }
- else{
- currentUser->home(Root,current_node);
- }
- }
- if(ent == 't'){
- if(check){
- if(entoli.compare("toggle") == 0){
- currentUser->toggle();
- }
- }
- else{
- currentUser->toggle();
- }
- }
- if(ent == 'x'){
- if(check){
- if(entoli.compare("exit") == 0){
- exit(2);
- }
- }
- else{
- exit(2);
- }
- }
- if(ent == 'b'){
- if(check){
- if(entoli.compare("bets") == 0){
- currentUser->bets(bethistory,history);
- }
- }
- else{
- currentUser->bets(bethistory,history);
- }
- }
- if(ent == 'f'){
- if(check){
- if(entoli.compare("freebets") == 0){
- currentUser->freebets(User,history);
- }
- }
- else{
- currentUser->freebets(User,history);
- }
- }
- if(ent == 'a'){
- if(check){
- if(entoli.compare("account") == 0){
- currentUser->account(history);
- }
- }
- else{
- currentUser->account(history);
- }
- }
- if(ent == 's'){
- if(check){
- if(entoli.compare("save") == 0){
- currentUser->save(current_node,User,history,bethistory);
- }
- }
- else{
- currentUser->save(current_node,User,history,bethistory);
- }
- }
- if(ent == 'l'){
- if(check){
- if(entoli.compare("logs") == 0){
- currentUser->logs(history);
- }
- }
- else{
- currentUser->logs(history);
- }
- }
- if(ent == 'u'){
- if(check){
- if(entoli.compare("users") == 0){
- currentUser->users();
- }
- }
- else{
- currentUser->users();
- }
- }
- if(ent == 'v'){
- if(check){
- if(entoli.compare("visibility") == 0){
- currentUser->visibility(current_node);
- }
- }
- else{
- currentUser->visibility(current_node);
- }
- }
- if(ent == 'r'){
- if(check){
- if(entoli.compare("rename") == 0){
- currentUser->Rename(User,history,current_node);
- }
- }
- else{
- currentUser->Rename(User,history,current_node);
- }
- }
- if(ent == 'n'){
- if(check){
- if(entoli.compare("new") == 0){
- currentUser->New(current_node);
- }
- }
- else{
- currentUser->New(current_node);
- }
- }
- if(ent == 'c'){
- if(check){
- if(entoli.compare("copy") == 0){
- currentUser->Copy(current_node); // copy
- }
- }
- else{
- currentUser->Copy(current_node);
- }
- }
- if(ent == 'd'){
- if(check){
- if(entoli.compare("delete") == 0){
- currentUser->Delete(current_node);
- }
- }
- else{
- currentUser->Delete(current_node);
- }
- }
- if(ent == 'p'){
- if(check){
- if(entoli.compare("place") == 0){
- current_node->preplace(currentUser,bethistory,history);
- }
- }
- else{
- current_node->preplace(currentUser,bethistory,history);
- }
- }
- if(ent == 'v'){
- if(check){
- if(entoli.compare("void") == 0){
- current_node->prevoid(currentUser,User,bethistory,current_node);
- }
- }
- else{
- current_node->prevoid(currentUser,User,bethistory,current_node);
- }
- }
- if(ent == 's'){
- if(check){
- if(entoli.compare("settle") == 0){
- current_node->presettle(currentUser,User,bethistory,current_node);
- }
- }
- else{
- current_node->presettle(currentUser,User,bethistory,current_node);
- }
- }
- if(ent == 'p'){
- if(check){
- if(entoli.compare("password") == 0){
- currentUser->password(history);
- }
- }
- else{
- currentUser->password(history);
- }
- }
- if(ent == 'v'){
- if(check){
- if(entoli.compare("view") == 0){
- currentUser->view(User);
- }
- }
- else{
- currentUser->view(User);
- }
- }
- if(ent == 's'){
- if(check){
- if(entoli.compare("search") == 0){
- currentUser->search(User);
- }
- }
- else{
- currentUser->search(User);
- }
- }
- if(ent == 'l'){
- if(check){
- if(entoli.compare("lock") == 0){
- currentUser->lock(User);
- }
- }
- else{
- currentUser->lock(User);
- }
- }
- if(ent == 'd'){
- if(check){
- if(entoli.compare("deposit") == 0){
- currentUser->deposit(history);
- }
- }
- else{
- currentUser->deposit(history);
- }
- }
- }
- }
- }
- void register_user(vector<Users*> &User,Users* current_user,vector<History*> &history,vector<Bethistory*> &bethistory,vector<root*> Root){
- 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];
- management_input(current_user,User,history,bethistory,Root);
- }
- void login_user(vector<Users*> User,Users* current_user,vector<History*> &history,vector<Bethistory*> &bethistory,vector<root*> Root){
- 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;
- }
- else{
- current_user = User[anagnwr];
- }
- write_users(User);
- management_input(current_user,User,history,bethistory,Root);
- }
- int main(int argc, char** argv) {
- vector<Users*> User;
- vector<History*> history;
- vector<Bethistory*> bethistory;
- vector<root*> Root;
- Root.push_back(new root());
- read_users(User);
- read_hierarchy(Root[0]);
- write_hierarchy(Root[0]);
- Users* currentUser;
- if (argc == 1){
- //xwris parameters
- login_user(User, currentUser , history , bethistory , Root);
- }
- else if(argc == 2){
- //mia parametros
- string parameter(argv[1]);
- capitalow(¶meter);
- if(strcmp(parameter.c_str(),"-r") == 0){
- //register a user
- register_user(User,currentUser,history,bethistory,Root);
- }
- }
- management_input(currentUser,User,history,bethistory,Root);
- 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