mercredi 16 mars 2022

I need help in my c++ code, the code is working but it's not calculating correct compound interest?

Program- Assume that a bank maintains two kinds of accounts for customers, one called as saving second account and adult as current account. The savings compound interest and withdrawal facilities, but no checkbook facility. The current account provides checkbook facility but no interest current account holders should also maintain a minimum balance and if the balance falls below this level, a service charge is imposed. Create a class account that stores customer name, account number and type of account. From this derive the class says. cur_acct and sav_acct to make them more specific to their requirements. Include necessary member functions in order to achieve the following tasks.

  1. Accept deposit from a customer and update the balance.
  2. Display the balance.
  3. Compute and deposit
  4. Permit withdrawal and update the balance.
  5. Check for the minimum balance, imposed penalty, necessary, and update the balance. code-
#include<iostream

#include<math.h>

using namespace std;

class account

{

public:

char name[20], atype[2];

long acc_no, bal, d_amt, w_amt;

void get()

{

cout<<"Enter Customer Name=";

cin>>name;

cout<<"Enter Account Number=";

cin>>acc_no;

cout<<"Enter type of account:Saving(s) or Current(c)=";

cin>>atype;

cout<<"Enter Account balance=";

cin>>bal;

}

void display()

{

cout<<"\nCustomer Name = "<<name;

cout<<"\nAccount no = "<<acc_no;

cout<<"\nAccount type = "<<atype;

cout<<"\nAccount balance = "<<bal;

}

void deposit()

{

cout<<"\nplease enter deposit amount=";

cin>>d_amt;

bal+=d_amt;

cout<<"\nUpdated account balance is="<<bal;

}

void exit()

{

cout<<"Thank you for visiting. :)";

}

};

//saving account

class sav_acct:public account

{

public:

int t,r;

float ci;

void compound()

{

cout<<"enter rate of interest="<<endl;

cin>>r;

cout<<"Enter time="<<endl;

cin>>t;

ci=bal*pow(1+r/100,t);

cout<<"compound interest is="<<ci<<endl;

//cout<<"New balance is="<<bal;

}

void withdraw()

{

cout<<"\nEnter the amount you want to withdraw=";

cin>>w_amt;

if (w_amt>bal)

{

cout<<"\nInsufficient balance";

}

else

{

bal=bal-w_amt;

cout<<"\nUpdated account balance is="<<bal;

}

}

};

//current account

class cur_acct:public account

{

public:

void min_bal()

{

if(bal<500)

{

cout<<"\nPenality imposed: \nnew balance is:"<<bal-50;

}

else

{

cout<<"\nNo penalty imposed";

}

}

void withdraw()

{

cout<<"\nEnter the amount you want to withdraw=";

cin>>w_amt;

if (w_amt>bal)

{

cout<<"\nInsufficient balance";

}

else

{

bal=bal-w_amt;

cout<<"\nUpdated account balance is="<<bal;

}

}

};

int main()

{

sav_acct s1;

cur_acct c1;

int num;

c1.get();

c1.display();

while(1)

{

cout<<"\n\nWelcome to VMOU Bank"<<endl;

cout<<"Enter the following options:\n";

cout<<" 1: Deposit \n 2: Withdraw \n 3: Calculate Compound \n 4: Balance Check \n 5: EXIT \n";

cin>>num;

switch(num)

{

case 1: c1.deposit();break;

case 2: c1.withdraw();break;

case 3: s1.compound();break;

case 4: c1.min_bal();break;

case 5: c1.exit();break;

default: cout<<"Enter valid option";

}

}

return 0;

}

Aucun commentaire:

Enregistrer un commentaire