Advertisements
Advertisements
Question
Suppose you have a Kitty Bank with an initial amount of Rs500 and you have to add some more amount to it. Create a class 'Deposit' with a data member named 'amount' with an initial value of Rs500. Now make three constructors of this class as follows:
1. without any parameter - no amount will be added to the Kitty Bank
2. has a parameter which is the amount that will be added to the Kitty Bank
3. whenever an amount is added an additional equal amount will be deposited automatically.
Create an object of the 'Deposit’ and display the final amount in the Kitty Bank.
Solution
Program:
using namespace std;
#include<iostream>
class Deposit
{
public:
int amount;
Deposit()
{
amount = 500;
}
Deposit(int a)
{
amount = 500 + a;
}
Deposit(int a, int b)
{
amount = 500 + a + b;
}
void display()
{
cout<<amount;
}
};
int main()
{
Deposit D1;
int amt;
cout<<“\nEnter amount to deposit”;
cin>>amt;
cout<<“\nInitial Amount in the Bank
Rs.”<<D1.amount;
Deposit D2(amt);
cout<<“\nAmount in the Bank after deposit the amount is Rs.”<<D2.amount;
Deposit D3(amt,amt);
cout<<“\nAmount in the Bank after deposit with addition equal amount deposit
RS.”<<D3. amount;
}
Output: