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 <sstream>
- using namespace std;
- int betid=1;
- class root{
- protected: //watch out//
- string name;
- vector <root*> nodes;
- public:
- root(string n="root"):name(n){
- }
- string get_name(){
- return name;
- }
- };
- class category : public root{
- public:
- static int ID;
- category(string n):root(n){
- ID++;
- }
- ~category(){ID--;}
- };
- class subcategory : public category{
- public:
- static int ID;
- subcategory(string n):category(n){
- ID++;
- }
- ~subcategory(){ID--;}
- };
- class event : public subcategory{
- string date;
- string time;
- public:
- static int ID;
- event(string n,string d,string t):subcategory(n),date(d),time(t){
- ID++;
- }
- ~event(){ID--;}
- string get_date(){
- return date;
- }
- string get_time(){
- return time;
- }
- };
- class selection : public root{
- string price;
- public:
- static int ID;
- selection(string n,string p):root(n),price(p){
- ID++;
- }
- ~selection(){ID--;}
- string get_price(){
- return price;
- }
- };
- class market : public root{
- public:
- static int ID;
- market(string n):root(n){
- ID++;
- }
- ~market(){ID--;}
- };
- //-initialization-//
- int selection::ID = 0;
- int market::ID = 0;
- int event::ID = 0;
- int subcategory::ID = 0;
- int category::ID = 0;
- //-finish-//
- class History
- { public:
- vector <string> username;
- vector <string> operation;
- vector <string> rename;
- vector <string> target;
- vector <double> money;
- };
- class Bethistory
- { public:
- vector<int> bet_id;
- vector<int> user_id;
- vector<string> node_id;
- vector<double> stake;
- vector<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(class History history,string operation,string target,string rename,string username,double x)
- { history.operation.push_back(operation);
- history.money.push_back(x);
- history.target.push_back(target);
- history.rename.push_back(rename);
- history.username.push_back(username);
- }
- 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()
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void freebets()
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void account()
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void save()
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void logs()
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void users()
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void visibility()
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void rename()
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void New()
- { 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()
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void search()
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void place()
- { cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- virtual void lock()
- { 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,class History history)
- { if(flag==1)
- { string str;
- while(1)
- { int flag2=0;
- 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,"URename"," "," ",ID.username,0.0);
- }
- else
- cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- void password(class History history)
- { if(flag==1)
- { string str,str1;
- while(1)
- { cout<< "Dwse ton neo kwdiko"<<endl;
- cin >> str;
- cout<< "Epanalabe"<<endl;
- 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(class Bethistory bethistory)
- { if(flag==1)
- { for (int i=bethistory.bet_id.size()-1;i>=0;i--)
- { if (bethistory.user_id[i]==ID.user_id)
- { cout<<"Bet to "<<bethistory.node_id[i]<< " "<< bethistory.stake[i]<< endl;
- }
- }
- }
- else
- cout<< "Den exete prosbash se authn thn entolh"<<endl;
- }
- void deposit(class 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(class 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(class Bethistory bethistory,class History history)
- { string choice;
- string bet;
- cout<<"Upoloipo portofoliou: "<<ID.balance<<endl;
- cout<<"Dwse epilogh"<<endl;
- 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)
- { cin >> bet;
- if(bet[0]>='a' && bet[0]<x)
- { int l=bet[0]-'a';
- bethistory.bet_id.push_back(betid++);
- bethistory.node_id.push_back(" ");//node id;
- bethistory.result.push_back('-');
- bethistory.user_id.push_back(ID.user_id);
- bethistory.stake.push_back(ID.freebets[l]);
- ID.freebets.erase(ID.freebets.begin()+l);
- }
- else
- { double bett;
- while (1)
- { bett=atoi( 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;
- cin >> bet;
- continue;
- }
- else if(bett<=ID.balance)
- { ID.balance-=bett;
- bethistory.bet_id.push_back(betid++);
- bethistory.node_id.push_back(" ");//node id;
- bethistory.result.push_back('-');
- bethistory.user_id.push_back(ID.user_id);
- bethistory.stake.push_back(bett);
- historyfun(history,"bet","id"," ",ID.username,bett);
- break;
- }
- }
- }
- }
- }
- }
- private:
- int flag;
- };
- class Trader:public Users
- { public:
- void bets(class Bethistory bethistory,class History history)
- { int l=0;
- for (int i=bethistory.bet_id.size()-1;i>=0;i--)
- { if (l++==20)
- break;
- cout << bethistory.bet_id[i]<< '\t' <<bethistory.user_id[i]<< '\t' <<bethistory.node_id[i]<< '\t' <<bethistory.stake[i]<< '\t' <<bethistory.result[i]<<endl;
- }
- historyfun(history,"Bets"," "," ",ID.username,0);
- }
- void freebets(vector<Users*> &User,class History history)
- { string name;
- double x;
- int flag=0,i;
- while(1)
- { cin >> name;
- for(i=0;i<User.size();i++)
- { if(!User[i]->ID.username.compare(name))
- { flag=1;
- break;
- }
- }
- if(flag==1)
- break;
- }
- cin >> x;
- User[i]->ID.freebets.push_back(x);
- historyfun(history,"Freebet",User[i]->ID.username," ",ID.username,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(class Bethistory bethistory,class History history)
- { int l=0;
- for (int i=bethistory.bet_id.size()-1;i>=0;i--)
- { if (l++==20)
- break;
- cout << bethistory.bet_id[i]<< '\t' <<bethistory.user_id[i]<< '\t' <<bethistory.node_id[i]<< '\t' <<bethistory.stake[i]<< '\t' <<bethistory.result[i]<<endl;
- }
- historyfun(history,"Bets"," "," ",ID.username,0);
- }
- void freebets(vector<Users*> &User,class History history)
- { string name;
- double x;
- int flag=0,i;
- while(1)
- { cin >> name;
- for(i=0;i<User.size();i++)
- { if(!User[i]->ID.username.compare(name))
- { flag=1;
- break;
- }
- }
- if(flag==1)
- break;
- }
- cin >> x;
- User[i]->ID.freebets.push_back(x);
- historyfun(history,"Freebet",User[i]->ID.username," ",ID.username,x);
- }
- void save()
- { //save
- }
- void logs(class History history)
- { int l=0;
- for (int i=history.username.size()-1;i>=0;i--)
- { if (l++==25)
- break;
- cout<<history.username[i]<<'\t'<<history.operation[i]<<'\t'<<history.target[i]<<'\t'<<history.rename[i]<<'\t'<<history.money[i]<<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()
- { //allagh visibility
- }
- void rename()
- { //allagh onomastos kombou
- }
- void New()
- { //dhmiourgias neou kombou
- }
- void copy()
- { //dhmiourgia antigrafou
- }
- void Delete()
- { //diagrafh kombou
- }
- void view(vector <Users*> &User)
- { if (flag==1)
- { 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;
- cin >> name;
- for(int i=0;i<User.size();i++)
- { if(User[i]->ID.username.find(name)!=User[i]->ID.username.size())
- { 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,class History history)
- { if (flag==1)
- { string name;
- int flag2=0,i;
- 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;
- cin >> name;
- 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,name);
- break;
- }
- else if(User[i]->ID.status[0]=='L')
- { flag2=1;
- cin >> name;
- User[i]->ID.status.replace(User[i]->ID.status.begin(),User[i]->ID.status.end(),name);
- break;
- }
- }
- }
- if (flag)
- { 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;
- };
- /*
- ofstream file;
- static int id_user=1;
- file.open("users.csv",ios::app);
- file << id_user << "|" << user << "|" << full << "|" << pass << "|" << type << "|" << status << "|" << balance << "|" << freebets << endl;
- id_user ++;
- file.close();
- */
- 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 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
- Users temp;
- 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);
- 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);
- }
- User.push_back(&temp);
- }
- //etoimo to User
- file.close();
- }
- void write_bet(Bethistory bethis){
- 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<bethis.bet_id.size() ;i++){
- file << bethis.bet_id[i]<< "|" << bethis.user_id[i] << "|" << bethis.node_id[i] << "|" << bethis.stake[i] <<"|" << bethis.result[i] <<endl;
- }
- file.close();
- }
- void audit_init(){
- ofstream file;
- file.open("audit.log",ios::out);
- file << "username | operation | money | target | rename";
- file.close();
- }
- void audit(History history){
- ofstream file;
- file.open("audit.log",ios::app); //de 3anagrafontai ta panta apla prosti8etai eggrafh sto arxeio
- int i=history.username.size()-1; //last element of vector
- file << history.username[i] << "|" << history.operation[i] << "|" << history.money[i] << "|" << history .target[i] << "|" << history.rename[i] << endl;
- file.close();
- }
- int main(int argc, char** argv) {
- vector<Users*> User;
- History history;
- Bethistory bethistory;
- audit_init();
- /*
- 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);
- */
- /*
- bethistory.bet_id.push_back(10) ;
- bethistory.node_id.push_back("1.1.2.3");
- bethistory.result.push_back('W');
- bethistory.stake.push_back(10.5);
- bethistory.user_id.push_back(1);
- bethistory.bet_id.push_back(2) ;
- bethistory.node_id.push_back("2.2.2.3");
- bethistory.result.push_back('L');
- bethistory.stake.push_back(1.5);
- bethistory.user_id.push_back(2);
- write_bet(bethistory);
- */
- read_users(User);
- write_users(User);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement