MSINGLA3
MSINGLA3
#include <iostream>
using namespace std;
class Person {
protected:
string name; Q2 Create a class BankAccount with attributes
int age; accountNumber and balance. Derive a class
SavingsAccount from BankAccount with an
public: additional method calculateInterest that calculates
void setPerson(string n, int a) { interest based on a fixed interest rate (e.g., 5%) and
name = n; updates the balance. Implement methods to
age = a; deposit and withdraw money in the BankAccount
} class and use them in SavingsAccount.
class Account {
#include <iostream> protected:
using namespace std; double balance;
#include <iostream>
using namespace std;
class BankAccount {
private:
double balance;
public:
void deposit(double amount) {
balance += amount;
}
double getBalance() {
return balance;
}
};
public:
void setInterestRate(double rate) {
interestRate = rate;
}
void applyInterest() {
deposit(getBalance() * interestRate);