create c++ programm that defines a class to represent a bank account.
Data members should include the depositor’s name, the account number(use a string), and the balance.
Member functions should allow the following:
1)Creating an object and initializing it.
2)Displaying the depositor’s name, account number, and balance.
3)Depositing an amount of money given by an argument.
4)Withdrawing an amount of money given by an argument.
having trouble with the member funtion ShowInfo() which has to output DepositorName, AccountNumber, and Balance
Code:
#include <cstring>
#include <iostream>
using namespace std;
class BankAccount
{
private:
std::string DepositorName;
std::string AccountNumber;
double Balance;
public:
BankAccount();
BankAccount(std::string depname, std::string acnum, double bal );
~BankAccount(); //destructor
void ShowInfo() const;
void Deposit(double depamount);
void Withdraw(double amount);
};
//non-defualt constructor
BankAccount::BankAccount(std::string depname, std::string acnum, double bal)
{
DepositorName = depname;
AccountNumber = acnum;
Balance = bal;
}
//destructor
BankAccount::~BankAccount()
{
}
void BankAccount::Withdraw(double amount)
{
if (amount < 0)
std::cout << "\nPlease enter positive number for the amount to withdraw.";
else
Balance -= amount;
}
void BankAccount::Deposit(double depamount)
{
if (depamount < 0)
std::cout << "\nPlease enter positive number for the amount to deposit.";
else
Balance+=depamount;
}
void BankAccount::ShowInfo() const
{
cout << DepositorName;
cout << AccountNumber;
cout << Balance;
}
int main()
{
BankAccount somename("some name", "08973541", 60000);
somename.ShowInfo();
somename.Deposit(15000);
somename.ShowInfo();
somename.Withdraw(30000);
somename.ShowInfo();
}