void Standard::Transfer() {

    string padded_acc_holder_f;
    string padded_acc_holder_t;
    string padded_acc_num_f;
    string padded_acc_num_t;
    string padded_amount;
    string padded_new_balance_f;
    string padded_new_balance_t;
    string acc_holder_t;
    string temp_acc_num_f;
    string temp_acc_num_t;
    string temp_amount;
    stringstream stream;
    float amount;
    float new_balance_f = 0.0;
    float new_balance_t = 0.0;
    int acc_num_f;
    int acc_num_t;

    cout << "\nTransfer transaction selected.\n" << endl;

    cout << "Enter you account number: ";
    cin >> temp_acc_num_f;

    regex re_f("[0-9]{0,5}");
    if (regex_match(temp_acc_num_f, re_f) && temp_acc_num_f.compare("99999") != 0) {
        acc_num_f = stoi(temp_acc_num_f);
    } else {
        cerr << "\n>>> ERROR: The account number entered is invalid.\n" << endl;
        return;
    }

    if (curr_user.GetNum() != acc_num_f) {
        cerr << "\n>>> ERROR: The account number does not match your account.\n" << endl;
        cout << "Current user: "******", Account Number: " << acc_num_f << endl;
        return;
    }

    if (transactions.is_Disabled(curr_user.GetNum())) {
        cerr << "\n>>> ERROR: The account is disabled; you may not send funds.\n" << endl;
        return;
    }

    if (transactions.is_New(curr_user.GetNum())) {
        cerr << "\n>>> ERROR: Newly created accounts may not send funds. Please try again in 24 hours.\n" << endl;
        return;
    }

    cout << "Enter destination account number: ";
    cin >> temp_acc_num_t;

    regex re_t("[0-9]{0,5}");
    if (regex_match(temp_acc_num_t, re_t) && temp_acc_num_t.compare("99999") != 0) {
        acc_num_t = stoi(temp_acc_num_t);
    } else {
        cerr << "\n>>> ERROR: The account number entered is invalid.\n" << endl;
        return;
    }

    if (!transactions.NumExists(acc_num_t)) {
        cerr << "\n >>> ERROR: The destination account number entered is invalid.\n" << endl;
        return;
    }

    if (transactions.is_Disabled(acc_num_t)) {
        cerr << "\n>>> ERROR: Disabled accounts may not receive funds.\n" << endl;
        return;
    }

    cout << "Enter amount to transfer: ";
    cin >> temp_amount;

    if (transactions.is_Amount_Valid(temp_amount)) {
        amount = stof(temp_amount);
    } else {
        cerr << "\n>>> ERROR: The amount entered is invalid.\n" << endl;
        return;
    }

    for (int i = 0; i < users.size(); i++) {
        if (users.at(i).GetNum() == acc_num_t) {
            acc_holder_t = users.at(i).GetName();
        }
    }

    padded_acc_holder_f = curr_user.GetName();
    while (padded_acc_holder_f.length() < 20) {
        padded_acc_holder_f = padded_acc_holder_f + " ";
    }

    padded_acc_holder_t = acc_holder_t;
    while (padded_acc_holder_t.length() < 20) {
        padded_acc_holder_t = padded_acc_holder_t + " ";
    }

    padded_acc_num_f = temp_acc_num_f;
    while (padded_acc_num_f.length() < 5) {
        padded_acc_num_f = "0" + padded_acc_num_f;
    }

    padded_acc_num_t = temp_acc_num_t;
    while (padded_acc_num_t.length() < 5) {
        padded_acc_num_t = "0" + padded_acc_num_t;
    }

    padded_amount = temp_amount;
    while (padded_amount.length() < 8) {
        padded_amount = "0" + padded_amount;
    }

    if ((curr_user.GetBalance() - curr_user.GetDeposited()) < amount) {
        cerr << "\n>>> ERROR: You may not transfer recently deposited funds.\n" << endl;
        return;
    }


    if (curr_user.GetPlan() == 'S') {
        // STUFF HERE
    } else if (curr_user.GetPlan() == 'N') {
        // STUFF HERE
    } else {
        cerr << "\n>>> ERROR: Unable to retrieve transaction payment plan information.\n" << endl;
        return;
    }

    for (int i = 0; i < users.size(); i++) {
        if (users.at(i).GetNum() == acc_num_t) {

            if (amount <= curr_user.GetBalance() && (1000.00 >= amount > 0.0) && (amount + users.at(i).GetBalance()) < 100000.00) {

                /*
                * Done in the Back End
                *
                if (curr_user.GetPlan() == 'S')
                  new_balance_f = curr_user.GetBalance() - amount - 0.05;
                else if (curr_user.GetPlan() == 'N')
                  new_balance_f = curr_user.GetBalance() - amount - 0.10;
                else {
                  cerr << "\n>>> ERROR: Unable to retrieve transaction payment plan information.\n" << endl;
                  return;
                }
                */
                new_balance_f = curr_user.GetBalance() - amount;
                new_balance_t = users.at(i).GetBalance() + amount;
                curr_user.SetBalance(new_balance_f);
                users.at(i).SetBalance(new_balance_t);
                users.at(i).SetDeposited(users.at(i).GetDeposited() + amount);
                break;

            } else {
                cerr << "\n>>> ERROR: The amount entered is invalid.\n" << endl;
                return;
            }
        }
    }

    stream << fixed << setprecision(2) << new_balance_f;
    padded_new_balance_f = stream.str();
    while (padded_new_balance_f.length() < 8) {
        padded_new_balance_f = "0" + padded_new_balance_f;
    }

    cout << "\nFunds have been successfully transfered from account " << padded_acc_num_f << " to account " << padded_acc_num_t << "." << endl;
    cout << "New balance: $" + padded_new_balance_f << endl;

    string transaction_line = "02 " + padded_acc_holder_f + " " + padded_acc_num_f + " " + padded_amount + "   ";
    transaction_file.push_back(transaction_line);
    transaction_line = "02 " + padded_acc_holder_t + " " + padded_acc_num_t + " " + padded_amount + "   ";
    transaction_file.push_back(transaction_line);
    cout << "\nEnter a command.\n" << endl;
}
Exemple #2
0
boot get_xmax(const char *path,const int det)
{
  FILE *f=open_file(combine("%s/data.raw",path).c_str(),"r");
  fread(&nx,sizeof(int),1,f);
  fread(&nx_rew,sizeof(int),1,f);
  fread(&nazione,sizeof(int),1,f);
  fread(&noss,sizeof(int),1,f);
  fread(&npow,sizeof(int),1,f);
  fread(&nboot,sizeof(int),1,f);
  nboot-=1;
  
  x=new double[nazione*nx];
  y=new double[nazione*nx*(nboot+1)*noss*npow];
  
  x_rew=new double[nazione*nx_rew];
  y_rew=new double[nazione*nx_rew*(nboot+1)*noss*npow];
  
  fread(x,sizeof(double),nazione*nx,f);
  fread(y,sizeof(double),nx*(nboot+1)*noss*npow,f);
  fread(x_rew,sizeof(double),nazione*nx_rew,f);
  fread(y_rew,sizeof(double),nx_rew*(nboot+1)*noss*npow,f);

  fclose(f);
  
  bvec da(nx,nboot,njack);
  bvec da_rew(nx_rew,nboot,njack);
  int ipowo=1,io=3;
  for(int is=0;is<nx;is++) da[is].put(y+(nboot+1)*iof(is,io,ipowo));
  for(int ip=0;ip<nx_rew;ip++) da_rew[ip].put(y_rew+(nboot+1)*iof(ip,io,ipowo));

  da*=vol;
  da_rew*=vol;
  
  bvec par_rew=lorentzian_fit(x_rew,da_rew);
  //for(int i=0;i<3;i++) cout<<par[i]<<" "<<par[i].err()/par[i].med()<<endl;
  //for(int i=0;i<3;i++) cout<<par_rew[i]<<" "<<par_rew[i].err()/par_rew[i].med()<<endl;
  
  //filter
  int nrew_filt=0,nfilt=0;
  double tresh=par_rew[0].med()/4;
  double tresh_rew=par_rew[0].med()*3/4;
  for(int i=0;i<da_rew.nel;i++) nrew_filt+=da_rew[i].med() > tresh_rew ? 1 : 0;
  for(int i=0;i<da.nel;i++) nfilt+=da[i].med() > tresh ? 1 : 0;
  double x_f[nfilt];
  double x_rew_f[nrew_filt];
  bvec da_f(nfilt,nboot,njack);
  bvec da_rew_f(nrew_filt,nboot,njack);
  int ifilt=0;
  int irew_filt=0;
  for(int i=0;i<da_rew.nel;i++)
    if(da_rew[i].med()>tresh_rew)
      {
	x_rew_f[irew_filt]=x_rew[i];
	da_rew_f[irew_filt]=da_rew[i];
	//cout<<ifilt<<" "<<x_rew_f[irew_filt]<<" "<<1/da_rew_f[irew_filt]<<endl;
	irew_filt++;
      }
  for(int i=0;i<da.nel;i++)
    if(da[i].med()>tresh)
      {
	x_f[ifilt]=x[i];
	da_f[ifilt]=da[i];
	//cout<<ifilt<<" "<<x_f[ifilt]<<" "<<1/da_f[ifilt]<<endl;
	ifilt++;
      }
  
  cout<<"Det: "<<det<<endl;
  cout<<"NFilt: "<<nfilt<<endl;
  
  bvec par_f=lorentzian_fit(x_f,da_f);
  bvec par_rew_f=lorentzian_fit(x_rew_f,da_rew_f);
  for(int i=0;i<3;i++)
    for(int iboot=0;iboot<nboot;iboot++)
      {
	if(isnan(par_f[i][iboot]))
	  {
	    par_f[i].data[iboot]=par_f[i].data[(iboot-1+nboot)%nboot];
	    //cout<<"par: "<<par_f[i][iboot]<<" "<<par_f[i].err()/par_f[i].med()<<endl;
	  }
	if(isnan(par_rew_f[i][iboot]))
	  {
	    par_rew_f[i].data[iboot]=par_rew_f[i].data[(iboot-1+nboot)%nboot];
	    //cout<<"par_: "<<par_rew_f[i][iboot]<<" "<<par_rew_f[i].err()/par_rew_f[i].med()<<endl;
	  }
      }
  bvec re_f(da_rew_f.nel,nboot,njack);
  bvec re_rew_f(da_rew_f.nel,nboot,njack);
  for(int i=0;i<da_rew_f.nel;i++) re_f[i]=par_f[0]/(1+sqr((x_rew_f[i]-par_f[1])/par_f[2]));
  for(int i=0;i<da_rew_f.nel;i++) re_rew_f[i]=par_rew_f[0]/(1+sqr((x_rew_f[i]-par_rew_f[1])/par_rew_f[2]));

  grace out("%s/fit_susc_%d.xmg",path,det);
  out.set(2,"none","square");
  if(det==0) out.print_graph(x_rew_f,da_rew_f);
  if(det==2) out.print_graph(x_f,da_f);
  //out.print_graph(x_rew,da_rew);
  out.new_set();
  out.set(1,"green");
  if(det==0) out.polygon(x_rew_f,da_rew_f);
  if(det==2) out.polygon(x_f,da_f);
  out.new_set();
  out.set(1,"blue");
  if(det==0) out.polygon(x_rew_f,re_rew_f);
  if(det==2) out.polygon(x_rew_f,re_f);
  
  boot xmax_rew=find_xmax(x_rew_f,da_rew_f);
  //cout<<xmax<<endl;
  
  switch(det)
    {
    case 0:return par_rew_f[1];break;
    case 1:return xmax_rew;break;
    case 2:return par_f[1];break;
    }
  
  cerr<<"Unknown value of 'det'"<<endl;
  exit(0);
  return par_f[1];
}