LocalMoneyBank.cpp
#include
#include
#include
#include
#include
#include
using namespace std;
/**
* @brief Represents a customer that arrives at the bank.
*
*/
class Customer {
public:
// the last name of the customer.
string lastName;
// the arrival time of the customer.
string arrivalTime;
// status of the account. (true if open and false if not open)
bool accountStatus;
// denotes the balance available in the customers account.
int customerAccountBalance;
// Denotes the type of transaction the customer wants to perform.
int transactionType;
// denotes the arrival time of the customer in the bank.
int arrivalTimestamp;
// denotes the amount of money if any transaction occurs.
int moneyInvolved;
// denotes the initial balance
int previousBalance;
public:
/**
* @brief Construct a new Customer object with random values.
*
*/
Customer() {
this->lastName = generateRandomString();
this->arrivalTime = generateRandomTime();
this->accountStatus = (bool)rand() % 2;
this->transactionType = rand() % 4;
if (this->accountStatus == true && this->transactionType) {
this->customerAccountBalance = rand() % 100000000;
} else {
this->customerAccountBalance = 0;
}
this->arrivalTimestamp = getArrivalTimeStamp(arrivalTime);
this->moneyInvolved = 0;
}
/**
* @brief Get the Arrival Time Stamp object
*
* @param arrivalTime denoting the arrival time of the customer.
* @return int that is a timestamp for the currently arrived customer.
*/
int getArrivalTimeStamp(string arrivalTime) {
return stoi(arrivalTime.substr(0, 2)) * 100 +
((float)stoi(arrivalTime.substr(3, 5)) / 6) * 10;
}
/**
* @brief Used to generate random time between 10:00AM and 1:00 PM
*
* @return string that represents the arrival time of the customer.
*/
string generateRandomTime() {
stringstream ss;
string _am = "AM";
string _pm = "PM";
int randomHours = (10 + rand() % 3);
int randomMinutes = rand() % 60;
ss << setw(2) << setfill('0') << randomHours;
ss << ":" << setw(2) << setfill('0') << randomMinutes;
if (randomHours <= 11 && randomMinutes <= 59) {
ss << "AM";
} else {
ss << "PM";
}
return ss.str();
}
/**
* @brief Used to generate a random last name of the customer.
*
* @return string that denotes the last name of the customer.
*/
string generateRandomString() {
int len = 5 + rand() % 10;
static const string alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string tmp_s;
tmp_s.reserve(len);
for (int i = 0; i < len; ++i) {
tmp_s += alphabets[rand() % (alphabets.length() - 1)];
}
return tmp_s;
}
};
/**
* @brief Used by the sort method to compare two customers based on their
* arrivalTimestamp.
*
* @param c1 a customer
* @param c2 a customer
* @return true
* @return false
*/
bool ValueCmp(Customer const &c1, Customer const &c2) {
return c1.arrivalTimestamp < c2.arrivalTimestamp;
}
/**
* @brief used as a...