/* This function fills up the array (up to max_accts) and returns the actual number of accounts read in (referred to as num_accts). */ int read_accts(Bank& bank, int max_accts) { int i = 0; //ifstream infile("C:\\Users\\Smart PC\\Desktop\\Assignment 3 (3110)\\myinput.txt"); ifstream infile("myinput"); string whiteSpace; getline(infile, whiteSpace); // check is file can be opened if (infile) { // read only first max_accts accounts, // in order to avoid overflow for (i = 0; i<max_accts; i++) { string firstName; string lastName; string ssn; string accountType; int accountNumber; int status; double balance; int transactions; infile >> firstName; // check is end of file reached if (!infile.eof()) { infile >> lastName; infile >> ssn; infile >> accountNumber; infile >> accountType; infile >> balance; infile >> status; infile >> transactions; bank.addAccount(firstName, lastName, ssn, accountNumber, accountType, balance, status); int index = bank.findAccount(accountNumber); Account* acc = bank.getAccount(index); for(int i=0; i<transactions; i++) { string transactionType; double amount; infile >> transactionType; infile >> amount; if (acc) acc->addTransaction(Transaction(transactionType, amount)); } } else { break; } }
int main(void) { int choice = 0; double amt = 0.0; Bank wsecu; while(choice != 7) { system("cls"); wsecu.displayMenu(); choice = wsecu.getMenuChoice(); switch(choice) { case 1: _flushall(); wsecu.addAccount(); break; case 2: _flushall(); wsecu.modifyAccount(); break; case 3: _flushall(); cout << "Enter amount to deposit: "; cin >> amt; wsecu.deposit(amt); break; case 4: _flushall(); cout << "Enter the amount to withdraw: "; cin >> amt; wsecu.withdrawal(amt); break; case 5: _flushall(); wsecu.displayAccount(); break; case 6: _flushall(); wsecu.deleteAccount(); break; default: break; } } wsecu.~Bank(); cout << "Thankyou for using the bank" << endl; return 0; }
int main(){ Bank *myBank; myBank = new Bank("Zinger unlimited"); cout << "-------------------------------------------------"<<endl; cout << " TEST: STATIC members "<<endl; cout << "-------------------------------------------------"<<endl; myBank->addAccount("Anton Hofmann", 100.0); myBank->addAccount("Beta Hofmann", 200.0); myBank->addAccount("Gamma Hofmann", 300.0); cout << myBank->toString() << endl; cout << "--- Delete Account: Anton Hofmann and add Account: Omega Hofmann ---" << endl; cout << "Look at the account number!!!"<<endl; myBank->delAccount("Anton Hofmann"); myBank->addAccount("Omega Hofmann", 900.0); cout << myBank->toString() << endl; cout << endl; cout << "-------------------------------------------------"<<endl; cout << " TEST: FRIEND class "<<endl; cout << "-------------------------------------------------"<<endl; cout << " ONLY class bank can create new Account-objects" <<endl; int accountNr= myBank->addAccount("Anton Hofmann", 100.0); myBank->getAccount(accountNr).deposit(9000.0); cout << myBank->toString() << endl; cout << endl; cout << "-------------------------------------------------"<<endl; cout << " TEST: Prepare "<<endl; cout << "-------------------------------------------------"<<endl; cout << "... 1. double d= myBank->getMaxAccount().getAmount(); "<<endl; double d = myBank->getMaxAccount().getAmount(); cout << "... Maximal amount = " << d << endl <<endl; cout << "... 2. double d= myBank->getMaxAccount().getAmount(); "<<endl; d= myBank->getStandardDeviation(); cout << "... Standard Deviation = " << d << endl << endl; cout << "... 3. myBank->delAccount(myBank->getAverageAmount()); "<<endl; cout << "... delete all Account having less then the average amount"<<endl; cout << "... Average Amount= " << myBank->getAverageAmount() << endl<<endl; myBank->delAccount(myBank->getAverageAmount()); cout << myBank->toString() << endl; cout << endl; d= myBank->getStandardDeviation(); cout << "Standard Deviation = " << d << endl << endl; delete myBank; return 0; }
void* console_thread(void* arg) { BankSocketThread* bankSocketThread = (BankSocketThread*) arg; Bank* bank = bankSocketThread->bank; //Let's generate our keys for(unsigned int i = 1; i <= 50; ++i) { byte* key = new byte[CryptoPP::AES::DEFAULT_KEYLENGTH]; generateRandomKey(to_string((int)i),key, CryptoPP::AES::DEFAULT_KEYLENGTH); bank->keys.push_back(key); bank->keysInUse.push_back(false); } //Create Accounts Account* new_account = new Account(); //Alice new_account->createAccount(std::string("alice"), 1, std::string("123456"), bank->appSalt); new_account->Deposit(100); bank->addAccount(new_account); //Bob new_account = new Account(); new_account->createAccount(std::string("bob"), 2, std::string("234567"), bank->appSalt); new_account->Deposit(50); bank->addAccount(new_account); //Eve new_account = new Account(); new_account->createAccount(std::string("eve"), 3, std::string("345678"), bank->appSalt); new_account->Deposit(0); bank->addAccount(new_account); char buf[80]; while(1) { printf("bank> "); fgets(buf, 79, stdin); buf[strlen(buf)-1] = '\0'; //trim off trailing newline std::vector<std::string> tokens; split(buf,' ',tokens); if(tokens.size() <= 0) { printf("Invalid input\n"); continue; } if(tokens[0] == "balance") { if(tokens.size() != 2) { printf("Invalid input\n"); continue; } Account* current_account = bank->getAccountByName(tokens[1]); if(!current_account) { printf("Invalid account\n"); continue; } printf("Balance: %.2Lf\n", current_account->getBalance()); continue; } if(tokens[0] == "deposit") { if(tokens.size() != 3) { printf("Invalid input\n"); continue; } long double amount = atof(tokens[2].c_str()); if(amount <= 0) { printf("Invalid amount\n"); continue; } Account* current_account = bank->getAccountByName(tokens[1]); if(!current_account) { printf("Invalid account\n"); continue; } if(current_account->Deposit(amount)) { long double cur_balance = current_account->getBalance(); printf("Money deposited!\nNew balance: %.2Lf\n", cur_balance); } else { printf("Error depositing money!\n"); } continue; } } }