#include \"stdafx.h\" #include <iostream> #include <conio.h> using namespace std
ID: 3609978 • Letter: #
Question
#include "stdafx.h"#include <iostream>
#include <conio.h>
using namespace std;
//class declaration
class BankAccounts
{
private:
int acctNum;
double acctBal;
const static double interestRate;
public:
void enterAccountData();
void computeInterest();
void displayAccount();
};
//class implementation
double interestRate = 0.03;
void BankAccounts::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: Invalidaccount 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;
}
acctNum = account;
acctBal = balance;
}
void BankAccounts::computeInterest()
{
int year;
cout<<"Please enter a term from 1 to40"<<endl;
cin>>year;
while(year > 40 || year < 1)
{
cout<<"You have chosenthe wrong number of years please try again"<<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 toenter more data?(y/n)"<<endl;
cin >> ans;
i++;
}while(ans == 'y');
return 0;
Could someone help me make sure that the user is not allowed to usethe same account number for other accounts.
Also how do I make it so that after 10 accounts have been eneteredthe program quits?
Ill reward lifsaver points.
Explanation / Answer
//#include "stdafx.h" #include #include using namespace std; //class declaration class BankAccounts { public: int acctNum; double acctBal; const static doubleinterestRate; public: voidenterAccountData(int i); voidcomputeInterest(); voiddisplayAccount(); // ={0,0,0,0,0,0,0,0,0,0} }; //class implementation static int accountNums[10] = {0}; double interestRate = 0.03; void BankAccounts::enterAccountData(int i) { //acctNum = account; //acctBal = balance; int account, balance; //Allows user to enter an account number thatcannot be less than 1000 or greater than 9999 coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.