Bank class must have the listed 2 constructors Default const

Bank class must have the listed 2 constructors Default constructor sets variables to john doe 0.0 2^nd constructor accepts 3 parameters and sets up account variables to those values 3 getters and 3 setters add method- accepts one parameter (double) and adds that amount to balance of calling object withdraw Method-Accepts one PARAMETER(double) subtracts that amount from the balance only if the account balance is great enough -otherwise, print a \"not enough funds method\" message print method -displays account info in tabular form

Solution

#include<iostream>
#include<string>
using namespace std;
class Bank
{
   string fname;
   string lname;
   double balance;
public:
   Bank()
   {
       fname = \"\" ;
       lname = \"\";
       balance = 0;
   }
   Bank(string f, string l,double bal)
   {
       fname = f;
       lname = l;
       balance= bal;
   }
   string getFname()
   {
       return fname;
   }
   string getLname()
   {
       return lname;
   }
   double getbal()
   {
       return balance;
   }
   void setFname(string f)
   {
       fname = f;
   }
   void setLname(string l)
   {
       lname = l;
   }
   void setbal(double bal)
   {
       balance = bal;
   }
   void add_amt(double amt)
   {
       balance+=amt;
   }
   void withdraw_amt(double amt)
   {
      
       if( balance <= 0 )
       {
           cout<<\"not enough funds \"<<endl;

           return;
       }
       balance-=amt;
   }
   void print()
   {
       cout<<\"Firstname   Lastname   balance\"<<endl;
       cout<<fname<<\"\\t\"<<lname<<\"\\t\"<<balance<<endl;
   }
};
int main()
{

   Bank bnk1;
   Bank bnk2(\"John\",\"Doe\",12.7);

   //Testing set methods for class
   bnk1.setFname(\"John\");
   bnk1.setLname(\"Doe\");
   bnk1.setbal(15.8);

   //Testing get methods for class
   cout<<\"Firstname   Lastname   balance\"<<endl;
   cout<<bnk1.getFname()<<\"\\t\"<<bnk1.getLname()<<\"\\t\"<<bnk1.getbal()<<endl;

   //testing print method of class

   bnk2.print();

   //testing add amount

   bnk2.add_amt(12);

   bnk2.print();

   //testing withdraw

   bnk2.withdraw_amt(12);
   bnk2.print();
  
   bnk2.withdraw_amt(12.7);
   bnk2.print();

   bnk2.withdraw_amt(12.7);
   bnk2.print();
  
}

 Bank class must have the listed 2 constructors Default constructor sets variables to john doe 0.0 2^nd constructor accepts 3 parameters and sets up account var
 Bank class must have the listed 2 constructors Default constructor sets variables to john doe 0.0 2^nd constructor accepts 3 parameters and sets up account var

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site