Bank class must have the listed 2 constructors Default constructor sets variable
ID: 3938086 • Letter: B
Question
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 formExplanation / Answer
#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<<" "<<lname<<" "<<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()<<" "<<bnk1.getLname()<<" "<<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();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.