in c++ 1.) Every bank offers a saving account. Derive the class savingAccount fr
ID: 3677822 • Letter: I
Question
in c++
1.) Every bank offers a saving account. Derive the class savingAccount from the class bankAccount (designed in prelab 8). This class inherits members to store the account number and the balance from the base class. A customer with a savings account typically receives interest, makes deposit, and withdraw money. In addition to the operations inherited from the base class, this class should provide the following operations: set annual interest rate, set deposit, calculate monthly interest rate, withdraw (override the method of the base class), and print account information. Add appropriate constructors.
2.) Write a program testBack to test all of your classes designed in prelab 8 and in this lab.
here is the pre-lab .h
class bankAccount
{
public:
bankAccount(int accountNum, double bal) :
accountNumber(accountNum), balance(bal) {}
void set_accountNumber(int accountNum){
accountNumber = accountNum;
}
void set_balance(double bal){
balance = bal;
}
int get_accountNum() const { return accountNumber; }
double get_balance() const { return balance; }
double deposit(double d);
double withdraw(double w);
void disinfo();
protected:
double balance;
int accountNumber;
};
this is the pre-lab .cpp
#include "bankAccount.h"
#include <iostream>
using namespace std;
double bankAccount::deposit(double d) {
return balance + d;
}
double bankAccount::withdraw(double w){
return balance - w;
}
void bankAccount ::disinfo(){
cout << "Your account number is " << accountNumber << endl;
cout << "Your balance is " << balance << endl;
}
Explanation / Answer
######bankAccount.h########
class bankAccount
{
protected:
double balance;
int accountNumber;
public:
bankAccount(int accountNum, double bal){
accountNumber= accountNum;
balance = bal;
}
void set_accountNumber(int accountNum){
accountNumber = accountNum;
}
void set_balance(double bal){
balance = bal;
}
int get_accountNum() const { return accountNumber; }
double get_balance() const { return balance; }
double deposit(double d);
double withdraw(double w);
void disinfo();
};
###### bankAccount.cpp#########
#include "bankAccount.h"
#include <iostream>
using namespace std;
double bankAccount::deposit(double d) {
return balance + d;
}
double bankAccount::withdraw(double w){
return balance - w;
}
void bankAccount ::disinfo(){
cout << "Your account number is " << accountNumber << endl;
cout << "Your balance is " << balance << endl;
}
########## savingAccount.h#########
class savingAccount: public bankAccount{
private:
double annualInterestRate;
public:
savingAccount(int accountNum, double bal,double rate):bankAccount(accountNum, bal){
annualInterestRate = rate;
}
void set_rate(double rate){
annualInterestRate = rate;
}
double deposit(double d) {
return get_balance() + d;
}
double get_rate() const { return annualInterestRate; }
double withdraw(double w){
return get_balance() - w;
}
double monthly_rate(){
return annualInterestRate/12.0;
}
};
############ testBank.cpp############
#include<iostream>
#include "bankAccount.h"
#include "savingAccount.h"
using namespace std;
int main(){
bankAccount b1(1, 100);
savingAccount s1(2, 120.5, 12.3);
cout<<b1.get_balance()<<endl;
cout<<s1.get_balance()<<endl;
s1.deposit(50);
cout<<s1.get_balance()<<endl;
cout<<s1.withdraw(100)<<endl;
cout<<s1.get_balance()<<endl;
return 0;
}
###########################
compile using :
g++ -c bankAccount.cpp
g++ -c testBank.cpp
/*
Output:
100
120.5
120.5
20.5
120.5
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.