q1-2.cpp - #include<iostream> using namespace std class Account public double bal\/account balance public Account Account(double x if(x < 0.0 x = 0.0

q1-2.cpp - #include<iostream> using namespace std class...

This preview shows page 1 - 3 out of 3 pages.

#include<iostream>using namespace std;class Account {public:double bal;//account balancepublic:Account() {}Account(double x) {if (x < 0.0) {x = 0.0;cout << "Balance set to Rs 0.0" << endl;}bal = x;}bool deposit(double x) {if (x < 0.0) {return false;}bal += x;return true;}bool withdraw(double x){if ((x < 0.0) || (bal<x)){cout << "Withdrawal amount exceeded account balance" << endl;return false;}bal -= x;return true;}double giveBalance() { return bal; }};class ProfitAccount :public Account {double rate;//interest %public:ProfitAccount() {}ProfitAccount(double x, double y) : Account(x) {
Background image
//bal = x;rate = y;}double computeInterest() {return (bal*rate)/100;}};class CurrentAccount : public Account{double fee;//fee per transactionpublic:CurrentAccount() {}CurrentAccount(double x, double y) : Account(x){fee = y;}bool deposit(double x){if (x < 0.0) {return false;}bal += x;bal -= fee;return true;}bool withdraw(double x) {if ((x < 0.0) || (bal<(x + fee))) {cout << "Withdrawal amount exceeded account balance" << endl;return false;}bal -= x;bal -= fee;return true;}};int main(){ProfitAccount pf1(-1000.0, 3), pf2(25000.0, 2);CurrentAccount ca1(-1784.0, 2.5), ca2(50000, 2.5);double interest;cout << "Profit Account 1:" << endl;cout <<"Current Balance = "<< pf1.giveBalance() << endl;
Background image
Background image

You've reached the end of your free preview.

Want to read all 3 pages?

  • Fall '18
  • Zia Ul Rehman
  • current account, #include

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture