fueanta

Bank Account and Interest

Sep 6th, 2016
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.38 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Account {
  6. protected:
  7.     string acc_title;
  8.     string acc_no;
  9.     double balance;
  10. public:
  11.     void set_Values(string acc_title, string acc_no, double balance) {
  12.         this->acc_title= acc_title;
  13.         this->acc_no= acc_no;
  14.         this->balance= balance;
  15.     }
  16.     void display() {
  17.         cout << "\nTitle: " << acc_title << endl;
  18.         cout << "Account Number: " << acc_no << endl;
  19.         cout << "Balance: " << balance << endl;
  20.         //cout << endl;
  21.     }
  22.     Account () {
  23.         cout << "An account has been created." << endl;
  24.     }
  25.     Account (string acc_title, string acc_no, double balance) {
  26.         this->acc_title= acc_title;
  27.         this->acc_no= acc_no;
  28.         this->balance= balance;
  29.     }
  30.     ~Account () {
  31.         cout << "\nAn account has been deleted : " << acc_title << endl;
  32.     }
  33.     void diposit (double amount) {
  34.         balance+=amount;
  35.         cout << "Tk " << amount << " has been added to " << acc_title <<"'s account." << endl;
  36.     }
  37.     void withdraw (double amount) {
  38.         if ((balance-amount)<=0)
  39.             cout << "Withdraw cannot be possible due to low balance." << endl;
  40.         else {
  41.             balance-=amount;
  42.             cout << "Tk " << amount << " has been withdrawn from " << acc_title <<"'s account." << endl;
  43.         }
  44.     }
  45. };
  46.  
  47. class SV : public Account {
  48.     double interest_rate;
  49. public:
  50.     void set_interest(double interest) {
  51.         interest_rate= interest;
  52.         balance+=(balance*interest)/100; cout << endl;
  53.         cout << interest_rate << "% interest has been added to the balance." << endl;
  54.         //cout << balance << endl;
  55.     }
  56.     SV(string title, string no, double balance):Account(title,no,balance)
  57.     {}
  58.     void display() {
  59.         cout << endl;
  60.         Account::display();
  61.         cout << "Interest Rate: " << interest_rate << endl;
  62.     }
  63. };
  64.  
  65. int main(void) {
  66.     string name,num;
  67.     double balance;
  68.     cout << "Account Name: "; cin >> name;
  69.     cout << "Account Number: "; cin >> num;
  70.     cout << "Balance: "; cin >> balance;
  71.     Account A1(name,num,balance);
  72.     A1.display();
  73.     cout << "\nAccount Name: "; cin >> name;
  74.     cout << "Account Number: "; cin >> num;
  75.     cout << "Balance: "; cin >> balance;
  76.     SV S1(name,num,balance);
  77.     S1.Account::display();
  78.     S1.set_interest(10);
  79.     S1.display();
  80.     return 0;
  81. }
Add Comment
Please, Sign In to add comment