In: Computer Science
In C++ with comments in code with screenshot
In this assignment, you are asked to create a class called Account, which models a bank account. The requirement of the account class is as follows, (1) It contains two data members: accountNumber and balance, which maintains the current account name and balance, respectively. (1) It contains three functions: functions credit() and debit(), which adds or subtracts the given amount from the balance, respectively. The debit() function shall print ”amount withdrawn exceeds the current balance!” if the amount is more than balance. A function print(), which shall print ”A/C no: xxx Balance=xxx” (e.g., A/C no: 991234 Balance=$88.88), with balance rounded to two decimal places.
When you submit your code, please upload your class code(s) and your test code to prove that your code works correctly.
#include <iostream>
#include <iomanip>
using namespace std;
class Account
{
private:
long accountNumber;
double balance;
public:
Account(long accountNumber,double balance)//
constructor
{
this->accountNumber =
accountNumber;
this->balance = balance;
}
void credit(double amount)
{
balance = balance + amount;
}
void debit(double amount)
{
if(amount > balance)
cout<<"\nAmount withdrawn
exceeds the current balance!"<<endl;
else
balance = balance - amount;
}
void print()
{
cout<<fixed<<setprecision(2);
cout<<"A/C no:
"<<accountNumber<<" Balance=$"<<balance;
}
};
int main() {
Account acc(991234,88.88);
acc.print();
acc.credit(55.30);
acc.debit(155.67);
acc.print();
return 0;
}
output:
A/C no: 991234 Balance=$88.88 Amount withdrawn exceeds the current balance! A/C no: 991234 Balance=$144.18
Do ask if any doubt. Please upvote.