#include<iostream>
usingnamespace std;
//BankAccount class
class BankAccount
{
// Declare private variables.
private:
int accNum;
float accBal;
float intRate;
int left;
//Declare of public member functions.
public:
void displayAccount();
BankAccount(int,float=0,float=0); /*Note that second
and third arguments
have default values if no value is received while object creation.*/
};
// Define constructor.
BankAccount::BankAccount(int num, float bal, float rate)
{
accNum = num;
accBal = left;
intRate = rate;
//Check if account number is valid.
if (accNum < 1000 || accNum>9999)
{
accNum = 0;
}
}
// Function to print all information.
void BankAccount::displayAccount()
// main function.
void main()
{
int acc;
float bal, rate;
char choice;
//Accept account information till user chooses to exit.
do
{
cout << endl << "Enter the account number: ";
cin >> acc;
cout << "Enter the account balance: ";
cin >> bal;
cout << "Enter the interest rate: ";
cin >> rate;
BankAccount B(acc, bal, rate); /*The scope of
object 'B'is
limited to this loop for single itteration. Every itteration will create and destroy a new object 'B'.*/
B.displayAccount();
cout << "\nDo you want to enter more"<<
" accounts?(y/n)";
cin >> choice;
if(choice=='n'||choice=='N')
{
break;
return;
}
} while (1);
}