#include<iostream> #include<conio.h> using namespace std;
class Account { private: double balance; public: Account() { balance=0; } Account(int x) { balance=x; } void setBalance() { cout<<"\nEnter initial balance you have in your account:"; int x; cin>>x; balance=x; } void credit() { cout<<"\nHow much money you want to add in your account:"; int x; cin>>x; balance=balance+x; } void debit() { cout<<"\nHow much money you want to deduct from your account:"; int x; cin>>x; balance=balance-x; } double getBalance() { return balance; } };
class SavingsAccount:public Account { private: double interestRate; public: SavingsAccount() { Account::setBalance(); interestRate=0; } void setInterest() { cout<<"\nThe amount of interest you want to imply on the account:"; int y; cin>>y; interestRate=y; } double calculateInterest() { cout<<"\nThe amount of interest in $ is:"; return((interestRate/100)*getBalance()); } };
void main() { SavingsAccount s; s.credit(); s.debit(); s.setInterest(); cout<<s.calculateInterest(); }