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

Class Account Private Data Members: static int genId int accountId double balanc

ID: 3912412 • Letter: C

Question

Class Account

Private Data Members:

static int genId

int accountId

double balance

double annualInterestRate

Static data member used to assign value to accountId;

Account ID

Current Balance of the account

Current Annual Interest Rate of the Account (ex. 4.5)

Public Member Functions:

Account()

Account(int id, double bal, double interest)

Constructors:

Default Constructor (no parameters)

Overloaded Constructor: Three-Parameter Constructor

Public Member Functions:

void setAccountId (int x)

void setBalance(double x)

void setInterest(double x)

Setters:

Function sets id to x

Function sets balance to x

Function sets annualInterestRate to x

Public Member Functions:

int getAccountId()

double getBalance()

double getInterest()

static double getGenId()

Getters:

Function returns accountId

Function returns balance

Function returns annualInterestRate

Static Function used to returns genId

Public Member Functions:

double getMonthlyInterestRate()

Function calculates the monthly interest rate and returns the value

double getMonthlyInterest()

Function calculates the amount earned per month from interest and returns the value rounded to 2 decimal places. (Assume interest is not compounding)

Bool withdraw(double amount)

Function only allows withdraw if the current balance is greater than or equal to the withdraw amount. Return true if withdrawal is successful, else return false.

void deposit(double amount)

Function adds the amount passed as a parameter to the current balance.

Write a program that creates an array of 10 Account objects.  (IN C++)

When creating each Account object, make sure the object is initialized in both the default and overloaded constructor functions with following guidelines:

Each object’s accountId should be the index of its position within the array. Add a static data member to initialize the accountId.

The balance of each Account object should be created from a random number generator function returning values between 100.00 and 200.00.

The interest rate of each Account object should be created from a random number generator function returning values between 1.5 and 5.0. This return value should be rounded to one decimal place.

Main Program and remaining member function defintions:

The program should then ask the user to select an account number from 0 – 9 or -1 to exit the program.

If an account number is selected, then the user should be presented with the following options:

Enter 1 to make a deposit

Ask the user for the amount they wish to deposit

Enter 2 to make a withdraw

Ask the user for the amount they wish to withdraw

Return if withdrawal was successful or unsuccessful depending on function return value

Enter 3 to check balance

Display the account’s current balance

Enter 4 to check interest rate

Display the account’s monthly and yearly interest rate

Enter 5 to display account summary

Display account id, balance, monthly interest rate, and monthly interest amount

Enter 99 to exit to the main menu to select another account number.

Class Account

Private Data Members:

static int genId

int accountId

double balance

double annualInterestRate

Static data member used to assign value to accountId;

Account ID

Current Balance of the account

Current Annual Interest Rate of the Account (ex. 4.5)

Public Member Functions:

Account()

Account(int id, double bal, double interest)

Constructors:

Default Constructor (no parameters)

Overloaded Constructor: Three-Parameter Constructor

Public Member Functions:

void setAccountId (int x)

void setBalance(double x)

void setInterest(double x)

Setters:

Function sets id to x

Function sets balance to x

Function sets annualInterestRate to x

Public Member Functions:

int getAccountId()

double getBalance()

double getInterest()

static double getGenId()

Getters:

Function returns accountId

Function returns balance

Function returns annualInterestRate

Static Function used to returns genId

Public Member Functions:

double getMonthlyInterestRate()

Function calculates the monthly interest rate and returns the value

double getMonthlyInterest()

Function calculates the amount earned per month from interest and returns the value rounded to 2 decimal places. (Assume interest is not compounding)

Bool withdraw(double amount)

Function only allows withdraw if the current balance is greater than or equal to the withdraw amount. Return true if withdrawal is successful, else return false.

void deposit(double amount)

Function adds the amount passed as a parameter to the current balance.

Explanation / Answer

#include<iostream>

#include<stdlib.h>

using namespace std;

class account{

int accountid;

double balance;

double annual_interest_rate;

double monthly_interest_rate;

public:

account(int id){

accountid=id;

balance=(rand()%10000)/100+100.00;

annual_interest_rate=(rand()%36)/10+1.5;

monthly_interest_rate=(rand()%36)/10+1.5;

}

account(int id,double bal, double interest){

accountid=id;

balance=bal;

annual_interest_rate=interest;

monthly_interest_rate=(rand()%36)/10+1.5;

}

void setAccountId (int x){accountid=x;}

void setBalance(double x){balance=x;}

void setInterest(double x){annual_interest_rate=x;}

int getAccountId(){return accountid;}

double getBalance(){return balance;}

double getAnnualInterest(){return annual_interest_rate;}

double getMonthlyInterestRate(){return monthly_interest_rate;}

double getMonthlyInterest(){return (balance*monthly_interest_rate)/100;}

bool withdraw(double amount){

if(balance>=amount){

balance-=amount;

return true;

}

else return false;

}

void deposit(double amount){

balance+=amount;

}

};

int main(){

account arr[10]={0,1,2,3,4,5,6,7,8,9};

int account_number,choice;

double amount;

while(1){ cout<<"enter account number ";

cin>>account_number;

if(account_number>9||account_number<0){cout<<"invalid account number ";break;}

  

cout<<"1:Deposit 2:withdraw 3:check Balance 4:check Interest rate 5:Account summary 6:no choice ";

cout<<"enter choice:";

cin>>choice;

switch(choice){

case 1:{ cout<<"enter amount to deposit : ";

cin>>amount;

arr[account_number].deposit(amount);

break;

}

case 2:{

cout<<"enter amount to withdraw ";

cin>>amount;

bool k=arr[account_number].withdraw(amount);

if(k==true)cout<<amount <<" is withdrawn from account number "<<account_number<<" ";

else cout<<"low balance ";

break;

}

case 3:{

cout<<"Balance is : "<<arr[account_number].getBalance()<<" ";

break;

}

case 4:{

cout<<"Monthly Interest rate : "<<arr[account_number].getMonthlyInterestRate()<<" ";

cout<<"Annual Interest rate : "<<arr[account_number].getAnnualInterest()<<" ";

break;

}

case 5:{

cout<<"Account id : "<<arr[account_number].getAccountId()<<" ";

cout<<"Balance is : "<<arr[account_number].getBalance()<<" ";

cout<<"Monthly Interest rate : "<<arr[account_number].getMonthlyInterestRate()<<" ";

cout<< "monthly interest amount : "<<arr[account_number].getMonthlyInterest()<<" ";

break;

}

case 6:{

break;

}

}

  

}

return 0;

}