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

I need help with a problem for my C++ class in which we need to use arrays to cr

ID: 3635659 • Letter: I

Question

I need help with a problem for my C++ class in which we need to use arrays to create a program. Here's what it asks. Any help will be greatly appreciated.

You are developing a BankAccount structure for Parkville Bank. The structure contains
fields for the account number, the account balance, and the annual interest rate earned on
the account. Write a main()function in which you create an array of five BankAccount
objects. Prompt the user for values for all the fields in the five BankAccounts. Do not
allow two or more accounts to have the same account number. After all the objects have
been entered:
» Display all the data for all five accounts.
» Display the total balance in all five accounts and the average balance.
» After displaying the statistics, prompt the user for an account number and display the
data for the requested account, or display an appropriate message if no such account
number exists. Continue to prompt the user for account numbers until an appropriate
sentinel value is entered.

Explanation / Answer

Compiled under VS2010. Hope it's everything that needed in your assignment. Ask me if u need any explanation conserning the code, or if u need anything else here.


#include<iostream>
using namespace std;

class BankAccount
{
public:
int accountNumber;
double accountBalance;
double annualInterest;

BankAccount() { accountNumber = 0; accountBalance = 0; annualInterest = 0; }
};

double averageBalance(BankAccount *acc, int n)
{
int result = 0;
for (int i = 0; i < n; i++)
result += acc->accountBalance;

return (result/n);
}

double totalBalance(BankAccount *acc, int n)
{
int result = 0;
for (int i = 0; i < n; i++)
result += acc->accountBalance;

return result;
}

int main()
{
BankAccount accounts[5];
for (int i = 0; i < 5; i++)
{
again:
cout << "Input the account number for "<< i+1 << " account: ";
cin >> accounts[i].accountNumber;
for (int k = 0; k < i; k++)
{
if (accounts[i].accountNumber == accounts[k].accountNumber)
{
cout << "Can't have the same account number, ";
goto again;
}
}

cout << "Input the account balance for "<< i+1 << " account: ";
cin >> accounts[i].accountBalance;
cout << "Input the account anual interest rate for "<< i+1 << " account: ";
cin >> accounts[i].annualInterest;
}

for (int i = 0; i < 5; i++)
{
cout << "Acc. Number: " << accounts[i].accountNumber << endl;
cout << "Acc. Balance: " << accounts[i].accountBalance << endl;
cout << "Acc. Annual Interest Rate: " << accounts[i].annualInterest << endl;

cout << endl;
}

cout << "Total Balance: "<< totalBalance(accounts, 5) << endl;
cout << "Average Balance: "<< averageBalance(accounts, 5) << endl;

rep:
int acn;
cout << "Input account number: ";
cin >> acn;

int i;
bool state = false;
for (i = 0; i < 5; i++)
{
if (acn == accounts[i].accountNumber)
{
cout << "Acc. Number: " << accounts[i].accountNumber << endl;
cout << "Acc. Balance: " << accounts[i].accountBalance << endl;
cout << "Acc. Annual Interest Rate: " << accounts[i].annualInterest << endl;
state = true;
}
}

if (state == false)
{
cout << "Account with this account number doesn't exist" << endl;
}

char er;
cout << "Press 1 to exit, anything else to continue" << endl;
cin >> er;
if (er != '1')
goto rep;

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote