English
Tamil Nadu Board of Secondary EducationHSC Science Class 11

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. - Computer Science

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.

Answer in Brief

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:

shaalaa.com
  Is there an error in this question or solution?
Chapter 15: Polymorphism - CASE STUDY [Page 259]

APPEARS IN

Samacheer Kalvi Computer Science [English] Class 11 TN Board
Chapter 15 Polymorphism
CASE STUDY | Q 1. | Page 259
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×
Our website is made possible by ad-free subscriptions or displaying online advertisements to our visitors.
If you don't like ads you can support us by buying an ad-free subscription or please consider supporting us by disabling your ad blocker. Thank you.