This lab introduces you to writing a C++ program to implement the concept of cla
ID: 3657196 • Letter: T
Question
This lab introduces you to writing a C++ program to implement the concept of class inheritance using different types of bank accounts as a model. In this lab, you will create a base class, called CBankAccount, and two additional classes (each derived from CBankAccount), called CSavingsAccount and CCheckingAccount. You will then test the operations of each class in function main() to simulate the transactions of both a checking account and a savings account. so far i have: main.cpp #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()); //instantiate savings and checking accounts CheckingAccount account1; //SavingsAccount account2; //Create new checking account // In the following segment make sure the account number is between 00000-99999 cout << "Enter a five digit integer for your new checking account number: "; cin >> newAccountNumber; //Store new account number account1.setAccountNumber(newAccountNumber); //initial deposit of $100 account1.depositMoney(100.0); cout << showpoint << fixed << setprecision(2); cout << "A new checking account has been established." << endl; cout << "The new Checking Account Number is: " << account1.getAccountNumber() << endl; cout << "The new Checking account Balance for account # " << account1.getAccountNumber() << " is $" << account1.getAccountBalance() << endl << endl; //Test for checking account for withdrawals and related info for(i= 0; i< 10; i++) { cout << "withdraw money from checking account" << endl; { if(account1.withdrawMoney(20.0)) cout << "$0.50 transaction fee deducted from account if the number of transactions exceeds three." << endl; else cout << "ACTION DENIED, INSUFFICIENT FUNDS!!!" << endl; } cout << "checking account balance for account # " << account1.getAccountNumber() << " is $" << account1.getAccountBalance() << endl << endl; } //create new savings account //in the following segment make sure the account numer is between 00000-99999 /*cout << "enter a five digit integer for your new savings account number: "; cin >> newAccountNumber; //store new account number account2.setAccountNumber(newAccountNumber); //initial deposit of 100$ account2.depositMoney(100.0); cout << showpoint << fixed << setprecision(2); cout << "a new savings account has been established" << endl; cout << "the new savings account number is: " << account2.getAccountNumber() << endl; cout << "set savings account annual interest rate (in%): "; cin >> newInterestRate; account2.SetInterestRate(newInterestRate); cout << "the new 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 << endl; //Test withdrawal from savings as well as related info for(i = 0; i < 10; i++) { cout<< "withdraw money from savings account" << endl; if(account2.withdrawMoney(20.0) == false) cout << "withdrawal denied, insuficcient 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; }*/ return; } /******************************************************************/ bankaccount.cpp #include "BankAccount.h" BankAccount::BankAccount(void) { accountNumber = 0; accountBalance = 0.0; } BankAccount::~BankAccount(void) { } // accessor for customer account number int BankAccount::getAccountNumber(void) { return accountNumber; } //Return customer account balance double BankAccount::getAccountBalance(void) { return accountBalance; } //Deposit money into customer bank account void BankAccount::depositMoney(double depositAmount) { return ; //accountBalance += depositAmount; } //Withdraw money from customer bank account bool BankAccount::withdrawMoney(double withdrawAmount) { if(accountBalance - withdrawAmount < 0) return false; else { accountBalance -= withdrawAmount; return true; } } //Set customer bank account number void BankAccount::setAccountNumber(int newAccountNumber) { accountNumber = newAccountNumber; } /************************************************************/ checkingaccount.cpp #include "CheckingAccount.h" #include using namespace std; CheckingAccount::CheckingAccount(void) { transactionCount = 0; } CheckingAccount::~CheckingAccount(void) { } //Withdraw money from customer bank account bool CheckingAccount::withdrawMoney(double withdrawAmount) { transactionCount++; if(transactionCount > 3) { if(accountBalance - withdrawAmount - 0.5 < 0) return false; else { accountBalance -= (withdrawAmount + 0.5); cout << "$0.50 transaction fee included" << endl; return true; } } else { if(accountBalance - withdrawAmount < 0) return false; else accountBalance -= withdrawAmount; return true; } } /*****************************************************************/ savingsaccount.cpp #include "SavingsAccount.h" #include SavingsAccount::SavingsAccount(void) //: earnedInterest(0) { } SavingsAccount::~SavingsAccount(void) { } double SavingsAccount::getAccountBalance(void) { numberofDays = rand()%8; earnedInterest = accountBalance * (numberofDays * interestRate/(100*365)); accountBalance += earnedInterest; return accountBalance; } //Set daily interest rate void SavingsAccount::SetInterestRate(double newInterestRate) { interestRate = newInterestRate; } //returns interest earned since last transaction double SavingsAccount::getInterestEarned(void) { return earnedInterest; } //returns number of days over which interest was last earned int SavingsAccount::getNumberofDays(void) { return numberofDays; } /******************************************************************************/ bankaccount.h #pragma once class BankAccount { public: BankAccount(void); ~BankAccount(void); // Accessor for customer account number int getAccountNumber(void); // Return customer account ballance double getAccountBalance(void); void depositMoney(double depositAmount); // Deposit money into customer bank account bool withdrawMoney(double withdrawAmount); // Set customer bank account number void setAccountNumber(int newAccountNumber); protected: // Customer bank account number int accountNumber; //Customer bank account balance double accountBalance; }; /********************************************/ checkingaccount.h #pragma once #include "BankAccount.h" class CheckingAccount : public BankAccount { public: CheckingAccount(void); ~CheckingAccount(void); bool withdrawMoney(double); private: int transactionCount; }; /***********************************************/ savings.h #pragma once #include "BankAccount.h" class SavingsAccount : public BankAccount { public: SavingsAccount(void); ~SavingsAccount(void); double getAccountBalance(void); // Set daily interest rate void SetInterestRate(double); private: //Daily interest rate double interestRate; // Number of days since last account transaction int numberofDays; // Amount of interest earned since last transaction double earnedInterest; public: //Returns interest earned since last transaction double getInterestEarned(void); // Returns number of days over which interest accumulated int getNumberofDays(void); }; Conclusions: Write at least one nontrivial paragraph that explains, in detail, either a significant problem you had and how you solved it or, if you had no significant problems, something you learned by doing the exercise. Each lab exercise should have a separate section in the lab-report document. Your lab grade is based upon the formatting of your source code; the use of meaningful identifiers; the extent of internal documentation; the degree to which an exercisesExplanation / Answer
#include #include #include #include #include class account{ protected: char cname[20]; int accno; char type; int bal; public: account() { strcpy(cname," "); accno=0; type=' '; bal=0; } void input(){ coutcname; coutaccno; fflush(stdin); couttype; fflush(stdin); coutbal; } void display(){ coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.