Question
Create a 7-file BankAccount C++ Project. Main is provided and should not be modified. UML BankAccount // Base #balance : double #accountNumber : int + setAccountNumber(int num) : void +getAccountNumber() : int +getAccountBalance() : double +depositMoney(double amt) : void +withdrawMoney(double amt) : bool | | | ------------------------------------------------------------------ | | | | Savings Account // Derived Checking Account // Derived - InterestRate : double -transactionCount : int - numberOfDays : int - earnedInterest : double +withdrawMoney(double m) : bool + getAccountbalance() : double +setInterestRate (double i) +getInterestEarned() : double +getNumberOfDays() : int Files Required: BankAccount.h BankAccount.cpp CheckingAccount.h CheckingAccount.cpp SavingsAccount.h SavingsAccount.cpp BankAccountMain.cpp // Provided and (Not To Be Modified) Coding Errors Exist in all files except BankAccountMain.cpp Task: Working to Identify and Correct Errors in six files. // // BankAccount.h File // #pragma once #include #include #include using namespace std; class BankAccount { protected: int AccountNumber; double AccountBalance; public: BankAccount(); // Default Constructor BankAccount(int acc, double bal) // Parameterized Constructor { AccountNumber=acc; AccountBalance=bal; } void setAccountNumber(int acc); int getAccountNumber(); double getAccountBalance(double bal); void depositMoney(double amt); bool withdrawMoney(double amt); }; // // BankAccount.cpp // #include "BankAccount.h" #include #include #include using namespace std; BankAccount::BankAccount() { AccountNumber=0; AccountBalance=0; } void BankAccount::setAccountNumber(int acc) { AccountNumber=acc; } int BankAccount::getAccountNumber() { return AccountNumber; } double BankAccount::getAccountBalance(double bal) { return AccountBalance; } void BankAccount::depositMoney(double amount) { } bool BankAccount::withdrawMoney(double amt){ if((bal-amt)>0){ bal = bal -amt; return true; } else return false; } // // CheckingAccount.h File // #pragma once #include #include #include #include #include "BankAccount.h" using namespace std; class CheckingAccount:public BankAccount { private: int transcationCount; public: double withdrawMoney; CheckingAccount(); // default CheckingAccount(int transactionCount, double amt) // parameterized { double withdrawMoney(double amt); } }; // // CheckingAccount.cpp // #include "CheckingAccount.h" #include #include #include using namespace std; CheckingAccount::CheckingAccount() { bool CheckingAccount::withdrawMoney(double amt){ transactionCount++; if(transactionCount>3&& (balance-amt)>0) { balance=balance-amt-0.5; return true; } else if ((balance-amt)>0){ balance=balance-amt; return true; } else return false; } // // SavingsAccount.h File // #pragma once #include "BankAccount.h" #include #include #include using namespace std; class SavingsAccount : public BankAccount { private: // member variables double dailyInterestRate; int NoofDaysLastTrans; double IntEarnedLastTrans; public: SavingsAccount(); // default constructor SavingsAccount(double interestRate, int dayLTrans, double IntLTrans, int acc, double bal); void setInterestRate(double); // from class BankAccount double getAccountBalance(); double getInterestEarned(); int getNumberOfDays(); }; // // SavingsAccount cpp file // #include "SavingsAccount.h" #include #include #include using namespace std; SavingsAccount::SavingsAccount(double interestRate, int dayLTrans, double IntLTrans, int acc, double bal) : BankAccount(acc, bal) { dailyInterestRate = interestRate; NoofDaysLastTrans = dayLTrans; IntEarnedLastTrans = IntLTrans; } void SavingsAccount::setInterestRate(double interestRate) { dailyInterestRate = interestRate; } double SavingsAccount::getAccountBalance() { double dRate = dailyInterestRate/365; NoofDaysLastTrans = 1+(rand()%7); IntEarnedLastTrans = AccountBalance * (NoofDaysLastTrans * dRate); AccountBalance += IntEarnedLastTrans; return AccountBalance; } double SavingsAccount::getInterestEarned() { return IntEarnedLastTrans; } int SavingsAccount::getNumberOfDays() { return NoofDaysLastTrans; } //BankAccountMain.cpp //Tester function for BankAccount class #include "BankAccount.h" #include "CheckingAccount.h" #include "SavingsAccount.h" #include #include #include using namespace std; void main(void) { int i = 0; int newAccountNumber = 0; double depositAmount = 0.0; double withdrawAmount = 0.0; double newInterestRate = 0.0; srand(GetTickCount()); //Seed the random number generator //BankAccount account1; CheckingAccount account1; SavingsAccount account2; cout << "Enter a six digit integer for your new savings account number: "; cin >> newAccountNumber; account2.setAccountNumber(newAccountNumber); cout << endl; cout << "Retrieving new savings account number" << endl; cout << "New Savings Account Number: " << account2.getAccountNumber() << endl << endl; cout << "Set savings account interest rate" << endl; cin >> newInterestRate; account2.setInterestRate(newInterestRate); cout << "Savings account balance for account # " << account2.getAccountNumber() << " is $" << account2.getAccountBalance() << endl << endl; cout << "Total interest earned: " << account2.getInterestEarned() << " over " << account2.getNumberOfDays() << " days" << endl << endl; cout << showpoint << fixed << setprecision(2); account2.depositMoney(100.0); cout << "Savings account balance for account # " << account1.getAccountNumber() << " is $" << account2.getAccountBalance() << endl; cout << "Total interest earned: " << account2.getInterestEarned() << " over " << account2.getNumberOfDays() << " days" << endl << endl; for(i = 0; i < 10; i++) { cout << "Withdraw money from savings account" << endl; if(account2.withdrawMoney(20.0) == false) cout << "Withdrawal denied, insufficient funds" << endl; cout << "Savings account balance for account # " << account2.getAccountNumber() << " is $" << account2.getAccountBalance() << endl; cout << "Total interest earned: " << account2.getInterestEarned() << " over " << account2.getNumberOfDays() << " days" << endl << endl; system ("pause"); } }
Explanation / Answer
#include #include #include class details { public: char *name; int age; int accno; char branch[50]; char city[40]; void getdetails() { name=new char[20]; cout