हिंदी
तमिलनाडु बोर्ड ऑफ सेकेंडरी एज्युकेशनएचएससी विज्ञान कक्षा ११

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

प्रश्न

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.

संक्षेप में उत्तर

उत्तर

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
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 15: Polymorphism - CASE STUDY [पृष्ठ २५९]

APPEARS IN

सामाचीर कलवी Computer Science [English] Class 11 TN Board
अध्याय 15 Polymorphism
CASE STUDY | Q 1. | पृष्ठ २५९
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×