C++ main.cc file #include #include #include #include "bank.h" int main() { // =================== YOUR CODE HERE =================== // 1. Create a Bank object, name it anything you'd like :) // ======================================================= // =================== YOUR CODE HERE =================== // 2. Create 3 new accounts in your bank. // * The 1st account should belong to "Tuffy", with // a balance of $121.00 // * The 2nd account should belong to "Frank", with // a balance of $1234.56 // * The 3nd account should belong to "Oreo", with // a balance of $140.12 // ======================================================= // =================== YOUR CODE HERE =================== // 3. Deactivate Tuffy's account. // ======================================================= // =================== YOUR CODE HERE =================== // 4. Call DisplayBalances to print out all *active* // account balances. // ======================================================= } bank.h file #include #include #include #include #include #include #include "account.h" class Bank { public: // ======================= YOUR CODE HERE ======================= // Write the Bank class here. Refer to the README for the member // variables, constructors, and member functions needed. // // Note: mark functions that do not modify the member variables // as const, by writing `const` after the parameter list. // Pass objects by const reference when appropriate. // Remember that std::string is an object! // =============================================================== private: // We provided this helper function to you to randomly generate // a new Bank Account ID to be used in CreateAccount. int GenerateAccountId() const { return std::rand() % 9000 + 1000; // [1000, 9999] } }; bank.cc file #include "bank.h" // ========================= YOUR CODE HERE ========================= // This implementation file (bank.cc) is where you should implement // the member functions declared in the header (bank.h), only // if you didn't implement them inline within bank.h. // // Remember to specify the name of the class with :: in this format: // MyClassName::MyFunction() { // ... // } // to tell the compiler that each function belongs to the Bank class. // =================================================================== account.h file #include class Account { public: Account(const std::string& name, double balance) : account_holder_(name), balance_(balance) {} const std::string& GetAccountHolder() const { return account_holder_; } double GetBalance() const { return balance_; } private: std::string account_holder_; double balance_; }; Sample Output: Frank: $1234.56 Oreo: $140.12
C++
main.cc file
#include <iostream>
#include <map>
#include <vector>
#include "bank.h"
int main() {
// =================== YOUR CODE HERE ===================
// 1. Create a Bank object, name it anything you'd like :)
// =======================================================
// =================== YOUR CODE HERE ===================
// 2. Create 3 new accounts in your bank.
// * The 1st account should belong to "Tuffy", with
// a balance of $121.00
// * The 2nd account should belong to "Frank", with
// a balance of $1234.56
// * The 3nd account should belong to "Oreo", with
// a balance of $140.12
// =======================================================
// =================== YOUR CODE HERE ===================
// 3. Deactivate Tuffy's account.
// =======================================================
// =================== YOUR CODE HERE ===================
// 4. Call DisplayBalances to print out all *active*
// account balances.
// =======================================================
}
bank.h file
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <map>
#include <memory>
#include <string>
#include "account.h"
class Bank {
public:
// ======================= YOUR CODE HERE =======================
// Write the Bank class here. Refer to the README for the member
// variables, constructors, and member functions needed.
//
// Note: mark functions that do not modify the member variables
// as const, by writing `const` after the parameter list.
// Pass objects by const reference when appropriate.
// Remember that std::string is an object!
// ===============================================================
private:
// We provided this helper function to you to randomly generate
// a new Bank Account ID to be used in CreateAccount.
int GenerateAccountId() const {
return std::rand() % 9000 + 1000; // [1000, 9999]
}
};
bank.cc file
#include "bank.h"
// ========================= YOUR CODE HERE =========================
// This implementation file (bank.cc) is where you should implement
// the member functions declared in the header (bank.h), only
// if you didn't implement them inline within bank.h.
//
// Remember to specify the name of the class with :: in this format:
// <return type> MyClassName::MyFunction() {
// ...
// }
// to tell the compiler that each function belongs to the Bank class.
// ===================================================================
account.h file
#include <string>
class Account {
public:
Account(const std::string& name, double balance)
: account_holder_(name), balance_(balance) {}
const std::string& GetAccountHolder() const {
return account_holder_;
}
double GetBalance() const {
return balance_;
}
private:
std::string account_holder_;
double balance_;
};
Sample Output:
Frank: $1234.56
Oreo: $140.12
![Insecure Bank Accounts
For this exercise you will create a Bank class that represents a bank that doesn't care about privacy. This bank allows anyone to create an
account, delete an account, and view all the accounts registered with the bank and their associated balances.
We've provided the Account class for you already. An Account represents an individual's bank account - which stores the name of the
account holder and the current balance in US dollars.
Bank Class
The Bank class stores all the accounts that have been created with this bank. It allows people to create and delete accounts with the bank,
get the total accounts that the bank currently has, and display every account holder's total balance in US Dollars.
Member Variables
Create the following private member variables:
1. bank_name__ - a string representing the name of this bank.
2. accounts - a map whose key is an int representing the account ID, and whose value is the Account object representing the account
associated with that ID.
Constructor
Create one non-default constructor, which accepts a const reference to a string, which specifies the name of this bank.
Accessor Functions
Create two accessor functions for the two member variables. Please use these names for your accessors: Get BankName() and
GetAccounts (). Use const references where appropriate (i.e. to avoid expensive copies when returning large objects!)
Create Account
Create a member function Create Account, which accepts a const string reference representing the name of the account holder, and a
double for the initial balance of the account. Create Account should use these inputs to create a new Account object. Use the provided
GenerateAccountId() function to create a random ID between [1000, 9999] and use that as the new account's ID, and store the mapping
from that ID to the Account object into the accounts_ map.
Total Accounts
Create a member function TotalAccounts, which accepts no input and returns the total number of accounts in the map.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F7b779863-aa72-4537-9750-69366ddc9e6e%2F84e18f9f-10f2-4444-9f5e-c04086d89d20%2Fzptrf8r_processed.png&w=3840&q=75)


Trending now
This is a popular solution!
Step by step
Solved in 6 steps with 5 images









