Hello! I'm looking for help with a c++ assignment. My goal is use 3 files that operate an atm.
The 3 files are:
account.h (interface of account class)
account.cpp(implementation of account class)
accountMain.cpp(main function of account class)
the header file is supplied
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#include <iostream>
#include <cassert>
#include <iomanip>
#include <fstream>
#include <string>
#include <cmath>
#include <ctime>
#include <cstdlib>
using namespace std;
class Account
{
private:
//Private Data Members :
int accountId; //Account ID
double balance; //Current Balance of the account
double annualInterestRate; //Current Annual Interest Rate of the Account (ex. 4.5)
public:
//Public Member Functions : (Constructors)
Account(); //Default Constructor (no parameters)
Account(int id, double bal, double interest); //Three-Parameter Constructor
//Public Member Functions : (Setters)
void setAccountId(int x); //Function sets id to x
void setBalance(double x); //Function sets balance to x
void setInterest(double x); //Function sets annualInterestRate to x
//Public Member Functions : (Getters)
int getAccountId(); //Function returns accountId
double getBalance(); //Function returns balance
double getInterest(); //Function returns annualInterestRate
//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.
};
|
My assignment is to:
Write a program that creates an array of 10 Account objects.
When creating each Account object use the following guidelines:
• Each object’s accountId should be the index of its position within the array.
• The balance of each Account object should be created from a random number generator function returning values between 10,000.00 and 20,000.00. This return value should be rounded to two decimal places.
• 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.
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 some options. The five main bullets should form the menu presented. If a user makes any of the top five selections, then the menu should be represented. The menu should only not be represented with an entry of -1.
• Enter 1 to make a deposit
o Ask the user for the amount they wish to deposit
• Enter 2 to make a withdraw
o Ask the user for the amount they wish to withdraw
o Return if withdrawal was successful or unsuccessful depending on function return value
• Enter 3 to check balance
o Display the account’s current balance
• Enter 4 to check interest rate
o Display the account’s monthly and yearly interest rate
• Enter 5 to display account summary
o Display account id, balance, monthly interest rate, and monthly interest amount
• Enter -1 to return to the main menu
o This will return the user to the main menu prompting to select an account number
I am struggling with randomly generating the numbers for the balance and the interest, and also calling these functions in accountMain.cpp
Here is what my implementation looks like
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include <iostream>
#include "Account.h"
using namespace std;
Account::Account()
{ accountId = 0;
balance = 0;
annualInterestRate = 0;
}
Account::Account(int id, double bal, double interest)
balance = bal;
annualInterestRate = interest;
}
void Account::setAccountId (int x)
{ accountId = x;
}
int Account::getAccountId()
{ return accountId;
}
void Account::setBalance(double x)
{
x = rand() % 20000 + 10000.00;
balance = x;
}
void Account::deposit(double amount)
{ cout << "Enter amount to be deposited: " << endl;
cin >> amount;
balance += amount;
}
double Account::getBalance()
{ return balance;
}
void Account::setInterest(double x)
{ annualInterestRate = x;
}
double Account::getInterest()
{ return annualInterestRate;
}
double Account::getMonthlyInterestRate()
{ double mInterestRate;
mInterestRate = annualInterestRate / 12;
return mInterestRate;
}
double Account::getMonthlyInterest()
{ double mInterestRate;
double mInterest;
mInterestRate = annualInterestRate / 12;
mInterest = mInterestRate * balance;
return mInterest;
}
bool Account::withdraw(double amount)
{ if (balance >= amount)
{ balance -= amount;
return true;
}
else
{ return false;
}
}
|
Here is what I have for the main function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#include <iostream>
#include <cstdlib>
#include "Account.h"
using namespace std;
int get_account_id() // renamed from start()
{ int id;
cout << "\nPlease enter an account number from 0 - 9" << endl;
cin >> id;
return id;
}
int get_choice ()
{ int option;
cout << "Enter 1 to make a deposit" << endl;
cout << "Enter 2 to make a withdraw" << endl;
cout << "Enter 3 to check balance" << endl;
cout << "Enter 4 to check interest rate" << endl;
cout << "Enter 5 to display account summary" << endl;
cout << "Enter 0 to exit" << endl;
cin >> option;
return option;
}
void process_account (Account& accnt, int option)
{ double amt = 0;
switch (option)
{
case 1:
accnt.deposit (amt);
break;
case 2:
accnt.withdraw (amt);
break;
case 3:
accnt.getBalance();
break;
case 4:
cout << "Monthly interest rate: " << accnt.getMonthlyInterest() << endl;
cout << "Yearly interest rate: " << accnt.getInterest() << endl;
break;
case 5:
cout << "\nAccount ID: " << accnt.getAccountId() << endl;
cout << "Current Balance: " << accnt.getBalance() << endl;
cout << "Monthly interest rate: " << accnt.getMonthlyInterestRate() << endl;
cout << "Monthly interest amount: " << accnt.getMonthlyInterest() << endl;
break;
default:
cout << "nInvalid Selection." << endl;
}
}
int main()
{
int id;
int choice;
Account accnt[10]; //Create an array of 10 Account objects
system("pause");
return 0;
}
|
any help with the random number generators and calling these functions and outputting the options will be greatly appreciated.