Design a class Account that has the following member: Data Fields: account_id(int type), balance(double type)). Member Functions-> withdraw(),deposit(),getmonthly_interest() and parameterize constructor to initialize data members. Use this class to print the balance. Use the withdraw () to withdraw money less than Rs 5000 and then deposit more than or equal 1500 using deposit function.
#include<iostream>
#include<vector>
using namespace std;
class Account
{
int acc_ID;
double balance;
public:
Account(int _acc_ID, double _balance)
:acc_ID(_acc_ID), balance(_balance){}
void Print()
{
cout << "\nBalance is " << balance;
}
void withdraw()
{
double w;
cout << "\nPlease enter a money to withdraw:";
cin >> w;
if (w < balance&&w<5000)
{
balance -= w;
}
else
{
cout << "\nError!Prohibited operation!";
}
}
void deposit()
{
double d;
cout << "\nPlease enter a money to deposit:";
cin >> d;
if (d < 1500)
{
cout << "\nToo little amount of deposit!";
}
else
{
balance += d;
}
}
void getmonthly_interest()
{
float annual;
cout << "\nPlease, enter an annual interest of your deposit:";
cin >> annual;
cout<<"\nMonthly interest is "<< annual*balance / 12;
}
};
int main()
{
Account a(1, 2500);
a.deposit();
a.Print();
a.withdraw();
a.Print();
a.getmonthly_interest();
}
Comments
Leave a comment