示例#1
0
int main(void) {
	
	initializeAccount();
	getBalance();
	//Perform first transaction
	
	askCustomer();
	updateAccount(amount);
	getBalance();
	//Perform second transaction
	
	askCustomer();
	updateAccount(amount);
	addGift(5.0);
	getBalance();
	//Perform third transaction
	
	askCustomer();
	updateAccount(amount);
	addGift(2.0);
	getBalance();
	thankYou();
	
	return 0;
}
示例#2
0
int main(int argc, const char * argv[]) {
    // insert code here...

    int transactionCounter = 0;
    initializeAccount();
    getBalance();
    
    // Perform first transaction
    askCustomer();
    updateAccount(amount);
    getBalance();
    
    // Perform second transaction
    askCustomer();
    updateAccount(amount);
    addGift(5.0);
    getBalance();
    
    // Perform third transaction
    askCustomer();
    updateAccount(amount);
    addGift(2.0);
    getBalance();
    thankYou();
    
    return 0;
}
示例#3
0
/**
* Processes the input from the client, given the command, argument, and state
* of the client. 
*
* The 'state' is simply whether or not the client is in a session.
* -1: Client wishes to exit
*  0: Client is connected, but is not in an account session
*  1: Client is connected and is in an account session
*
*/
int process_input(char *buffer, int state, client_t **client){
	
	int i;
	char *parsed = NULL;
	int len = strlen(buffer);
	for(i = 0; i < len; i++){
		if(buffer[i] == '\n'){
			if(i == 0){
				/*If it's just a newline*/
				break;
			}
			parsed = malloc(sizeof(char)*(i+1));
			strncpy(parsed, buffer, i);
			parsed[i] = '\0';
			break;
		}
	}
	if(parsed == NULL){
		printf("Error parsing buffer.\n");
		return state;
	}

	printf("CLIENT> %s\n", parsed);
	

	Node **list = &((*client)->head);

	char *command, *arg;
	char name[MAX_ARG_LEN];
	command = strtok(parsed, " ");
	arg = strtok(NULL, " ");
	memset(name, '\0', sizeof(name));
	if(arg != NULL){
		strcpy(name, arg);
	}


	if(strcmp(parsed, "exit") == 0){
		printf("Client exits!\n");
		if(state == 1){
			printf("Finishing customer session.\n");
			Node *node = findAccount((*client)->current_acc, *list);
			Account *acc = node->account;
			finishAccount(&acc, state);
			free((*client)->current_acc);
		}
		update_client_count(-1);
		free(parsed);
		return -1;
	}else if(strcmp(command, "open") == 0){
		if(state == 1){
			printf("Still in customer session!\n");
			free(parsed);
			return 1;
		}
		int open = openAccount(list, name);
		char *msg = "Account opened for ";
		printf("%s%s.\n", msg, name);
		if(open == -1){
			printf("Error opening account!\n");
			free(parsed);
			return 0;
		}
		free(parsed);
		return 0;
	}else if(strcmp(command, "start") == 0){
		if(state == 0){
			Node *ptr = findAccount(name, *list);
			if(ptr == NULL){
				free(parsed);
				return 0;
			}
			Account *acc = ptr->account;
			int n = startAccount(&acc, list);
			if(n == 0){
				printf("Account is still in use.\n");
				free(parsed);
				return 0;
			}
			char *current = malloc(strlen(name)*sizeof(char));
			strcpy(current, name);
			(*client)->current_acc = current;
			free(parsed);
			return 1;
		}else{
			printf("Still in session!\n");
			free(parsed);
			return 1;
		}
	}else if(strcmp(command, "credit") == 0){
		if(state == 1){
			float new = updateAccount((*client)->current_acc, list, atof(arg));
			printf("Balance of %s is now %.2f.\n", (*client)->current_acc, new);
			free(parsed);
			return 1;
		}else{
示例#4
0
void Ui::start() {
  std::cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
  std::string next = mainMenu();
  std::string username = "";
  Account* account = nullptr;

  while (next != "quit") {
    std::cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";

    if (next == "mainMenu") {
      next = mainMenu();
    }
    else if (next == "accountMenu") {
      next = accountMenu();
    }
    else if (next == "createAccount") {
      username = createAccount();
      next = "mainMenu";
      if (username.length() != 0) {
        next = "loadAccount";
      }
    }
    else if (next == "deleteAccount") {
      deleteAccount();
      next = "mainMenu";
    }
    else if (next == "loadAccount") {
      account = loadAccount(username);
      username = "";
      next = "accountMenu";
      if (account == nullptr) {
        next = "loadAccount";
      }
    }
    else if (next == "updateAccount") {
      updateAccount(account);
      next = "accountMenu";
    }
    else if (next == "getWithdrawals") {
      getWithdrawals(account);
      next = "accountMenu";
    }
    else if (next == "getDeposits") {
      getDeposits(account);
      next = "accountMenu";
    }
    else if (next == "withdraw") {
      withdraw(account);
      next = "accountMenu";
    }
    else if (next == "deposit") {
      deposit(account);
      next = "accountMenu";
    }
    else if (next == "quitAccountMenu") {
      delete account;
      account = nullptr;
      next = "mainMenu";
    }
  }
}
示例#5
0
void performGlobalConsistencyCheck()
{
	printf("\n\n\n@MASTER : Performing Global Consistency Check ...\n\n");


	FILE *fp = fopen(LOCATOR_FILENAME, "r+");
	int a,b,c,d;
	while(fscanf(fp,"%d %d %d %d",&a,&b,&c,&d)==4)
	{
		int other_key = d;

		int other_shmID = shmget((key_t)other_key,MAX_TRANSACTIONS*sizeof(struct transaction_record) + MAX_CLIENTS*sizeof(struct balance_record),0666);
		if(other_shmID==-1) perror("Error in shmget !\n");

		struct transaction_record* other_transac_ptr = shmat(other_shmID,NULL,0);
		struct transaction_record* curr_t;

		printf("Transactions @ ATM%d : \n", a);
		for(curr_t=other_transac_ptr;curr_t->client_accnt_no != -1 && curr_t!=NULL; curr_t++)
		{
					switch(curr_t->type)
					{
						case WITHDRAWAL: 
						{
							printf("	Accnt No. : %d WITHDRAWAL of %d on %s",curr_t->client_accnt_no, curr_t->amount,asctime(localtime(&curr_t->timestamp)));
							updateAccount(curr_t->client_accnt_no,(-1 * curr_t->amount));
							break;
						}
						case DEPOSIT: 
						{
							printf("	Accnt No. : %d DEPOSIT of %d on %s",curr_t->client_accnt_no, curr_t->amount,asctime(localtime(&curr_t->timestamp)));
							updateAccount(curr_t->client_accnt_no,curr_t->amount);
							break;
						}
						default:continue;
					}

			// RE-INITIALIZE the transaction record
			curr_t->client_accnt_no = -1;
				
		}
		int detach = shmdt(other_transac_ptr);
	}
	struct balance_record* local_shm_ptr;

	// COPY THE UPDATED BALANCE TABLE FROM GLOBAL SPACE TO LOCAL IMAGES @ ATMs

	rewind(fp);

	while(fscanf(fp,"%d %d %d %d",&a,&b,&c,&d)==4)
	{
		int other_key = d;

		int other_shmID = shmget((key_t)other_key,MAX_TRANSACTIONS*sizeof(struct transaction_record) + MAX_CLIENTS*sizeof(struct balance_record),0666);
		if(other_shmID==-1) perror("Error in shmget !\n");

		struct transaction_record* other_transac_ptr = shmat(other_shmID,NULL,0);
		local_shm_ptr =(struct balance_record*) (other_transac_ptr + MAX_TRANSACTIONS);

		copyGlobaltoLocalImage(local_shm_ptr);

		int detach = shmdt(other_transac_ptr);

	}

	fclose(fp);

}
示例#6
0
void ContactListModel::Private::realAddContact(PsiContact *contact)
{
    ContactListItem *root = static_cast<ContactListItem*>(q->root());;
    if (accountsEnabled) {
        PsiAccount *account = contact->account();
        ContactListItem *accountItem = root->findAccount(account);

        if (!accountItem) {
            accountItem = new ContactListItem(q, ContactListItem::Type::AccountType);
            accountItem->setAccount(account);
            accountItem->setExpanded(!collapsed.contains(accountItem->internalName()));

            connect(account, SIGNAL(accountDestroyed()), SLOT(onAccountDestroyed()));
            connect(account, SIGNAL(updatedAccount()), SLOT(updateAccount()));

            root->appendChild(accountItem);
        }
        root = accountItem;
    }

    if (!contact->isSelf() && groupsEnabled) {
        ContactListItem::SpecialGroupType specialGroupType = specialGroupFor(contact);
        QStringList groups = specialGroupType == ContactListItem::SpecialGroupType::NoneSpecialGroupType ? contact->groups() : QStringList{QString()};

        for (const QString &groupName: groups) {

            ContactListItem *groupItem = nullptr;
            if (specialGroupType == ContactListItem::SpecialGroupType::NoneSpecialGroupType)
                groupItem = root->findGroup(groupName);
            else
                groupItem = root->findGroup(specialGroupType);

            // No duplicates
            if (groupItem && groupItem->findContact(contact)) {
                continue;
            }

            ContactListItem *item = new ContactListItem(q, ContactListItem::Type::ContactType);
            item->setContact(contact);

            if (!groupItem) {
                groupItem = new ContactListItem(q, ContactListItem::Type::GroupType, specialGroupType);
                if (specialGroupType == ContactListItem::SpecialGroupType::NoneSpecialGroupType)
                    groupItem->setName(groupName);

                root->appendChild(groupItem);
                groupItem->setExpanded(!collapsed.contains(groupItem->internalName()));
                groupItem->setHidden(hidden.contains(groupItem->internalName()));
            }
            groupItem->appendChild(item);

            monitoredContacts.insertMulti(contact, q->toModelIndex(item));
        }
    }
    else {
        ContactListItem *item = new ContactListItem(q, ContactListItem::Type::ContactType);
        item->setContact(contact);
        root->appendChild(item);
        monitoredContacts.insertMulti(contact, q->toModelIndex(item));
    }

    connect(contact, SIGNAL(destroyed(PsiContact*)), SLOT(removeContact(PsiContact*)));
    connect(contact, SIGNAL(groupsChanged()), SLOT(contactGroupsChanged()));
    connect(contact, SIGNAL(updated()), SLOT(contactUpdated()));
    connect(contact, SIGNAL(alert()), SLOT(contactUpdated()));
    connect(contact, SIGNAL(anim()), SLOT(contactUpdated()));
}
void MoodBoxServer::updateAccount(Callback callback, UserAccount userAccount, bool hasUserPicture, QByteArray userPicture, QString contentType)
{
    updateAccount(callback, QVariant(), userAccount, hasUserPicture, userPicture, contentType);
}