Hi guys, I am doing a C++ project that I have to turn in tomorrowafternoon. I ha
ID: 3609975 • Letter: H
Question
Hi guys, I am doing a C++ project that I have to turn in tomorrowafternoon. I have most of the project completed and I think thereare no errors (maybe a logical error) but there are no majorerrors. I am having trouble with my main class as it asks to createan array and its been awhile since I used an array so I am morethan rusty in that area. Could someone please help and I will awardlife saver points. Thank you.This is what the project asks( its long but please read as its nottoo difficult):
Develop a BankAccounts class, containing private fields that holdthe account number and the account balance. Include a constantstatic filed that holds the annual interest rate (3%) earned onaccounts at Parkville Bank. Create three public member functionsfor the class, as follows:
An enterAccountData( ) function that prompts the user for valuesfor the account number and balance. Allow neither a negativeaccount number nor one less than 1000, and do not allow a negativebalance: continue to prompt the user until valid values areenetered.
A computeInterest( ) function that accepts an integer argument thatrepresents the number of years the account will earn interest. Thefunction displays the account number, then displays the endingbalance of the account eachy year, based on the interest rateattached to the BankAccounts.
A displayAccount( ) function that displays the details of theBankAccounts.
Create a main( ) function that declares an array of 10 BankAccountsobjects. After the first BankAccounts object is entered, ask theuser if he/she wants to continue. Prompt the user for BankAccountsvalues until the user wants to quit or enters 10 BankAccountsobjects, whichever comes first. For each BankAccounts entered,display the BankAccounts details. The prompt the user for a termwith a value btw 1 and 40 inclusive. Continue to prompt the useruntil a valid value is entered. Then pass the array of BankAccontsobjects, the count of valid objects in the array, and the desiredterm to a function that calculates and displays the values of eachof the BankAccounts after the given number of years at the standardinterest rate.
I know that was long but it is not too difficult, this is is mycode so far (w/o the main function completed since that is where Iam having trouble):
#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;
//class declaration
class BankAccounts
{
private:
int acctNum;
double acctBal;
const static doubleinterestRate;
public:
void enterAccountData(intact, int bal);
void computeInterest(intyear);
void displayAccount();
};
//class implementation
double interestRate = 0.03;
void BankAccounts::enterAccountData(int account, int balance)
{
acctNum = account;
acctBal = balance;
//Allows user to enter an account number thatcannot be less than 1000 or greater than 9999
cout<<"Please enter the accountnumber"<<endl;
cin>>account;
while(account < 1000 || account > 9999)
{
cout<<"Error: Invalid account number,please try again."<<endl;
cin>>account;
}
//Allows user to enter a balance that cannot benegative
cout<<"Please enter the balance for"<<account<<endl;
cin>>balance;
while(balance < 0)
{
cout<<"Error: Invalidbalance, cannot have a negative balance, please check and tryagain"<<endl;
cin>>balance;
}
}
void BankAccounts::computeInterest(int year)
{
year = year;
cout<<"How many years has the account beenactive?"<<endl;
cin>>year;
cout<<acctNum;
//calculates the balance with the interest rateaccording to the number of years
acctBal = acctBal + year / 0.03;
cout<<acctBal;
}
void BankAccounts::displayAccount()
{
cout<<acctNum<<endl;
cout<<acctBal<<endl;
}
//main function
int main()
{
const int BANK_ACCOUNTS = 10;
int account[BANK_ACCOUNTS];
system("PAUSE");
};
So please help me and I will award lifesaver points. Thanksagain.
Explanation / Answer
#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespacestd;
//class declaration
class BankAccounts
{
private:
int acctNum;
double acctBal;
const static doubleinterestRate;
public:
voidenterAccountData();
voidcomputeInterest();
voiddisplayAccount();
};
//class implementation
double interestRate = 0.03;
voidBankAccounts::enterAccountData()
{
int account;
double balance;
//Allows user to enter an account number thatcannot be less than 1000 or greater than 9999
cout<<"Please enter the accountnumber"<<endl;
cin>>account;
while((account < 1000) || (account > 9999))
{
cout<<"Error: Invalid account number,please try again."<<endl;
cin>>account;
}
//Allows user to enter a balance that cannot benegative
cout<<"Please enter the balance for"<<account<<endl;
cin>>balance;
while(balance < 0)
{
cout<<"Error:Invalid balance, cannot have a negative balance, please check andtry again"<<endl;
cin>>balance;
}
acctNum = account;
acctBal = balance;
}
voidBankAccounts::computeInterest()
{
int year;
cout<<"How many years has the account beenactive?"<<endl;
cin>>year;
//calculates the balance with the interest rateaccording to the number of years
acctBal = acctBal + year / 0.03;
}
void BankAccounts::displayAccount()
{
cout<<"Account: "<< acctNum<<endl;
cout<<"Balance: "<< acctBal<<endl;
}
//main function
int main()
{
char ans;
int i=0;
BankAccounts account[10];
do{
account[i].enterAccountData();
account[i].computeInterest();
account[i].displayAccount();
cout<<"Do you want to enter moredata?(y/n)"<<endl;
cin >> ans;
i++;
}while(ans == 'y');
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.