int main(int argc, char **argv)
{
  int accounts_number = atoi(argv[1]);
  int operations_number = atoi(argv[2]);
  int transaction_amount = atoi(argv[3]);
  shmid = atoi(argv[4]);

  accounts = (account *) malloc(sizeof(account));
  account *shared_data = (account *) malloc(sizeof(account));

  shared_data = (account*)shmat(shmid, NULL, 0);
  if ( shared_data == (void *) -1) {
      perror("shmat");
      exit(1);
  }
  for(i = 0; i < accounts_number; i++)
  {
    accounts[i] = shared_data[i] ;
  }
  shmdt(shared_data);

  for(i = 0; i < operations_number; i++)
  {
    int account_choose_debit_number = random_account_choose(accounts_number, accounts_number+1);
    debit(account_choose_debit_number, transaction_amount, shmid);
  }

}
//Show Menu
void SavingAccount::showMenu()
{
	char choice;
	do
    {
        system("cls");
        cout<<"+========================================+"<<endl;
        cout<<"|       Saving Account  Management       |"<<endl;
        cout<<"+========================================+"<<endl;
        cout<<"| 1. View Balance                        |"<<endl;
        cout<<"| 2. View Interest Amount                |"<<endl;
        cout<<"| 3. Credit                              |"<<endl;
        cout<<"| 4. Debit                               |"<<endl;
        cout<<"| 0. Exit to main menu                   |"<<endl;
		cout<<"+----------------------------------------+"<<endl;
        cout<<"| Your selection(0->2): ";
        fflush(stdin);
        cin>>choice;
        
        if(choice=='0') break;
        switch(choice)
        {
	        case '1':
				viewBalance();
	            break;
	        case '2':
	            calculateInterest();
	            break;
	        case '3':
	            credit();
	            break;
	        case '4':
	            debit();
	            break;
	        default:
				cout<<"Wrong choice!"<<endl;
	        	system("pause");
	        	break;
        }
    }while(1);
}
Example #3
0
bool executeCommand(sqlite3 *db, const char *command)
{
    char **params;
    int paramsCount;
    int i;

    int from, to;
    double sum;

    (void)db;   // unused


    // parse command
    paramsCount = countWords(command);
    params = malloc(sizeof(char*) * paramsCount);
    for (i=0; i<paramsCount; i++)
        params[i] = getWord(command, i);            

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_HELP)))
        commandHelp();

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_1)))
        command1();

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_2)))
        command2();

    if ((paramsCount >= 4) && (!strcmp(params[0], COMMAND_TRANSF)))
    {
        sscanf(params[1], "%i", &from);
        sscanf(params[3], "%lf", &sum);
        sscanf(params[2], "%i", &to);
        //transfer(db, from, to, sum);
        if (sum < 0 ) return false;
        debit(db, from, sum);
        credit(db, to, sum);
    }

    if ((paramsCount >= 3) && (!strcmp(params[0], COMMAND_DEB)))
    {
        sscanf(params[1], "%i", &from);
        sscanf(params[2], "%lf", &sum);
        if (sum < 0 ) return false;
        debit(db, from, sum);
    }

    if ((paramsCount >= 3) && (!strcmp(params[0], COMMAND_CRED)))
    {
        sscanf(params[1], "%i", &to);
        sscanf(params[2], "%lf", &sum);
        if (sum < 0) return false;
        credit(db, to, sum);
    }

    if ((paramsCount >= 2) && (!strcmp(params[0], COMMAND_CHCK)))
    {
        sscanf(params[1], "%i", &to);
        checkAccount(db, to);
    }

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_UNDO)))
        undo(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_ADD)))
        createNewCustomer(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_DEL)))
        deleteCustomer(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_DELACC)))
        deleteAccount(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_ADDACC)))
        addAccount(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_COMMIT)))
        commit(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_SHOW)))
        showAll(db);

    if ((paramsCount >= 1) && (!strcmp(params[0], COMMAND_LOGGER)))
        logger(db);

    for (i=0; i<paramsCount; i++)
        free(params[i]);
    free(params);

    return true;
}
Example #4
0
void transfer(sqlite3 *db, int acc_from, int acc_to, double sum)
{
    debit(db, acc_from, sum);
    credit(db, acc_to, sum);
    //credit(db, acc_to, sum);
}