Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Let us say you find a consulting opportunity for a regional bank that wants you

ID: 3725451 • Letter: L

Question

Let us say you find a consulting opportunity for a regional bank that wants you to write a class to do maintain monthly account activity of a user's bank account. After a study they have determined that customers do not more that 50 transactions in a month and we will assume that they are never more than 200. They want you to store every transaction in a local array of this class as soon as a transaction happens. Only amount of the transaction is stored (negative for withdrawals and positive for deposits), the date of transaction or any other data is not stored by this class They also want to be able to calculate the largest deposit based on the current entries in this array. You have to write a class that provided following functions void deposit(double amount): /Enters a positive transaction into the array void withdraw(double amount); /Enters a negative transaction into the array double getLargestDeposit0: Wreturns the largest deposit The class must implement an array called "accountActivity". You will determine the capacity of the array needs in your program and what you need to maintain the number of transactions that have occurred so far (You have to make the decision on how many data members you need in addition to the array. No! this problem does not need dynamic memory allocation). Your program will assume that the history is started fresh, every time you execute the program. That is: the first call to deposit(double amount) will make the first entry into the array Please implement a print) function that prints all of the data members of the class in a friendly manner Please make sure that you use "Preformatted" style rather than "Paragraph" for the entire code and ensure it is readable and properly indented

Explanation / Answer


Given below is the code for the question.
Please do rate the answer if it was helpful. Thank you

#include <iostream>
#include <string>
using namespace std;

class account
{
private:
double accountActivity[200];
int numTransactions;
double balance;
public:
account()
{
numTransactions = 0;
balance = 0;
}
  
void deposit(double amount)
{
if(numTransactions < 200)
{
accountActivity[numTransactions] = amount;
numTransactions++;
balance += amount;
}
}
  
void withdraw(double amount)
{
if(balance < amount)
cout << "Insufficient balance" << endl;
else
{
if(amount >= 0 && numTransactions < 200)
{
accountActivity[numTransactions] = - amount;
numTransactions++;
balance -= amount;
}
}
}
  
  
double getLargestDeposit()
{
double largest = 0;
for(int i = 0; i < numTransactions; i++)
{
if(accountActivity[i] > 0 && accountActivity[i] > largest)
largest = accountActivity[i];
}
return largest;
}
  
void print()
{
for(int i = 0; i < numTransactions; i++)
{
if(accountActivity[i] > 0)
cout << "Deposit $" << accountActivity[i] << endl;
else
cout << "Withdraw $" << -accountActivity[i] << endl;
}
  
cout << endl << "Current balance: $" << balance << endl;
}
  
};


void test()
{
account a;
  
a.deposit(200);
a.withdraw(100);
a.deposit(500);
a.withdraw(300);
a.deposit(250);
a.print();
cout << "largest deposit is $" << a.getLargestDeposit() << endl;
}

int main()
{
  
test();
return 0;
}


----output----
Deposit $200
Withdraw $100
Deposit $500
Withdraw $300
Deposit $250

Current balance: $550
largest deposit is $500