Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Account.cpp
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <fstream>
- #include <iomanip>
- #include <algorithm>
- #include <stdlib.h>
- using namespace std;
- class Account
- {
- private:
- int accountId; //account ID
- double balance; //current balance of the account
- double annualInterestRate; //current annual interest rate of the account (ex. 4.5)
- public:
- //Account();
- //Account(int id, double bal, double interest);
- //default constructor(no parameters)
- Account()
- {
- //cout << "Please enter an account number 0-9: " << endl;
- //cin >> accountId;
- }
- //three-parameter constructor
- Account(int id, double bal, double interest)
- {
- accountId = id;
- balance = bal;
- annualInterestRate = interest;
- }
- //function sets id to x
- void setAccountId(int x)
- {
- accountId = x;
- }
- //function sets balance to x
- void setBalance(double x)
- {
- balance = x;
- x = (rand() % 20000 + 10000);
- }
- //function sets annaulInterestRate to x
- void setInterest(double x)
- {
- annualInterestRate = x;
- srand(unsigned(time(NULL)));
- x = (1.5 + ((double)rand() / RAND_MAX) * (5.0 - 1.5));
- }
- //function returns accountI
- int getAccountId()
- {
- return accountId;
- }
- // Function returns balance
- double getBalance()
- {
- return balance;
- }
- //function returns annualInterest Rate
- double getInterest()
- {
- return annualInterestRate;
- }
- //Function calculates the monthly interest rate and returns the value
- double getMonthlyInterestRate()
- {
- double monthlyInterest = (annualInterestRate / 12);
- return monthlyInterest;
- }
- //Function calculates the amount earned per month from interest and
- //returns the value rounded to 2 decimal places. (Assume interest is
- //not compounding)
- double getMonthlyInterest()
- {
- return (getMonthlyInterestRate() * getBalance());
- }
- //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.
- bool withdraw(double amount)
- {
- if (getBalance() >= amount)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- //Function adds the amount passed as a parameter to the current balance.
- void deposit(double amount)
- {
- balance = (balance + amount);
- }
- };
- //AccountMain.cpp
- #include "Account.cpp"
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <fstream>
- #include <iomanip>
- #include <algorithm>
- using namespace std;
- double fRand(double fMin, double fMax)
- {
- double f = (double)rand() / RAND_MAX;
- return fMin + f * (fMax - fMin);
- }
- int menu(int inputaccnum, int menuchoice, Account list[10])
- {
- if (menuchoice == 1)
- {
- int depositinput;
- cout << fixed << setprecision(2) << "Your current Balance is: $" << list[inputaccnum].getBalance() << endl;
- cout << "Enter the amount you'd like you to deposit: ";
- cin >> depositinput;
- list[inputaccnum].deposit(depositinput);
- cout << endl;
- }
- else if (menuchoice == 2)
- {
- int withdrawinput;
- cout << fixed << setprecision(2) << "Your current Balance is: $" << list[inputaccnum].getBalance() << endl;
- cout << "Enter the amount you'd like to withdraw: ";
- cin >> withdrawinput;
- list[inputaccnum].withdraw(withdrawinput);
- cout << endl;
- }
- else if (menuchoice == 3)
- {
- cout << "Current Balance: $" << list[inputaccnum].getBalance() << endl;
- }
- else if (menuchoice == 4)
- {
- cout << "Monthly interest rate: " << list[inputaccnum].getMonthlyInterestRate() << "%" << endl;
- cout << "Yearly interest rate: " << setprecision(2) << list[inputaccnum].getInterest() << "%" << endl;
- }
- else //if (menuchoice = 5)
- {
- cout << "Account ID: " << list[inputaccnum].getAccountId() << endl;
- cout << "Current Balance: " << list[inputaccnum].getBalance() << endl;
- cout << "Monthly interest rate: " << list[inputaccnum].getMonthlyInterestRate() << endl;
- cout << "Monthly interest gain amount: " << list[inputaccnum].getMonthlyInterest() << endl;
- }
- return 0;
- }
- int main()
- {
- Account acc0, acc1, acc2, acc3, acc4, acc5, acc6, acc7, acc8, acc9;
- Account list[10] = { acc0, acc1, acc2, acc3, acc4, acc5, acc6, acc7, acc8, acc9 };
- acc0.setAccountId(0), acc1.setAccountId(1), acc2.setAccountId(2), acc3.setAccountId(3),
- acc4.setAccountId(4), acc5.setAccountId(5), acc6.setAccountId(6), acc7.setAccountId(7),
- acc8.setAccountId(8), acc9.setAccountId(9);
- int inputaccnum;
- cout << "Please enter an account number from 0-9: " << endl;
- cin >> inputaccnum;
- cout << list[inputaccnum].getAccountId();
- srand(unsigned(time(NULL)));
- list[inputaccnum].setBalance(fRand(10000.00, 20000.00));
- srand(unsigned(time(NULL)));
- list[inputaccnum].setInterest(1.5 + ((double)rand() / RAND_MAX) * (5.0 - 1.5));
- int menuchoice;
- cout << endl << "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 -1 to return to the main menu" << endl;
- cout << list[inputaccnum].getAccountId();
- cin >> menuchoice;
- int count = -1;
- for (int i = 0; i > count; i++)
- {
- if (menuchoice != -1)
- {
- menu(inputaccnum, menuchoice, list);
- cout << endl << "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 -1 to return to the main menu" << endl;
- cin >> menuchoice;
- }
- else
- {
- cout << "Please enter an account number from 0-9: " << endl;
- cin >> inputaccnum;
- srand(unsigned(time(NULL)));
- list[inputaccnum].setBalance((rand()) / (RAND_MAX / (20000.00 - 10000.00)));
- list[inputaccnum].setInterest(1.5 + ((double)rand() / RAND_MAX) * (5.0 - 1.5));
- cout << endl << "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 -1 to return to the main menu" << endl;
- cin >> menuchoice;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment