Você está na página 1de 4

#include<iostream>

#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
class account{
protected:
string name;
int accNo, type;
float balance;
public:
static int curAccNo;
void deposit(float amount){
balance += amount;
cout<<"The updated balance is "<<balance<<".\n";
}
void disp(){
string acct;
if(type == 0){
acct = "current";
}
else if(type == 1){
acct = "savings";
}
cout<<name<<"\'s "<<acct<<" account with account number "<<accNo<<" have "<<
balance<<" left.\n";
}
void withdraw(float amount){
if(balance <= 0){
cout<<"Sorry, You can't withdraw because of insufficient funds\n";
return;
}
balance -= amount;
cout<<"The updated balance is "<<balance<<".\n";
}
};
class sav_account: public account{
float interest; //Can set the interest rate only here
int compound ; // Can set the number of times interest is compounded per year
public:
sav_account(string aname, int atype, float amount){
interest = 0.035;
compound = 4;
name = aname;
type = atype;
balance = amount;
accNo = account::curAccNo;
account::curAccNo++;
}
void computeInterest(float time){
balance = balance*pow((1+(interest/compound)),time*compound);
}
void withdrawl(float amount, float time){
computeInterest(time);
withdraw(amount);

}
void deposit1(float amount, float time){
computeInterest(time);
deposit(amount);
}
void display(float time){
computeInterest(time);
disp();
}
};
class cur_account: public account{
bool checkbook , penalty ;
int checknum;
public:
static int curCheckbook;
cur_account(string aname, int atype, float amount){
name = aname;
type = atype;
balance = amount;
accNo = account::curAccNo;
account::curAccNo++;
checkbook = 0;
penalty = 0;
}
void check(){
if( penalty == 0){
if (balance<1000){
penalty = 1;
cout<<"Your balance is below 1000. You need to pay the penalty\n";
}
}
}
void withdrawl(float amount){
withdraw(amount);
check();
}
void payPenalty(){
if(penalty){
penalty = 0;
}
else{
cout<<"You don't have any penalty\n";
}
}
void createCheckbook(){
checkbook = 1;
checknum = cur_account::curCheckbook++;
}
void display(){
disp();
if(checkbook){
cout<<"The unique checkbook id is "<<checknum<<".\n";
}
}

};
int cur_account::curCheckbook = 1;
int account::curAccNo = 1;
int main(){
string name;
int type;
float amount;
cout<<"Please enter your name: ";
cin>>name;
cout<<"What type of account do you want? (0:current, 1:savings) ";
cin>>type;
cout<<"How much amount to start with? ";
cin>>amount;
cur_account acc1("dummy",0,0);
sav_account acc2("dummy",1,0);
if(type == 0){
acc1 = cur_account(name, type, amount);
}
else{
acc2 = sav_account(name, type, amount);
}
bool further = 1;
int todo = 2;
float time;
while(1){
cout<<"Do you want to proceed further ?(0 if NO) ";
cin>>further;
if (further == 0){
break;
}
if(type == 0){
cout<<"What do you want to do ? (0 = deposit, 1=withdraw, 2=display, 3=pay
Penalty, 4=Create Checkbook) :";
cin>>todo;
if(todo==0){
cout<<"please enter the amount :";
cin>>amount;
acc1.deposit(amount);
}
else if(todo==1){
cout<<"Please enter the amount :";
cin>>amount;
acc1.withdrawl(amount);
}
else if(todo==2){
acc1.display();
}
else if(todo == 3){
acc1.payPenalty();
}
else{
acc1.createCheckbook();
}
}
else{
cout<<"What do you want to do ? (0=deposit, 1=withdraw, 2=display) :";
cin>>todo;

if (todo==0){
cout<<"Please enter the amount and time :";
cin>>amount>>time;
acc2.deposit1(amount,time);
}
if(todo==1){
cout<<"Please enter the amount and time :";
cin>>amount>>time;
acc2.withdrawl(amount, time);
}
else{
cout<<"Please enter the time :";
cin>>time;
acc2.display(time);
}
}
}
return 0;
}

Você também pode gostar