- 1

homework help C++

please help my deadline is in 2 hours and I've been stuck on this homework for 3 days, I just don't get it create a class called account: a bank uses the class account to represent customers bank accounts. your class should include one data member type of type into to represent account balance. your class should provide a constructor that receives an initial balance and uses it to initialize the data member. the constructor should validate the initial balance to ensure that it is greater than or equal to 0. if not, the initial balance should be set to 0 and the constructor should display an error message indicating that the initial balance was invalid. the class should provide three member functions. member function credit should add an amount to the current balance. memeber function debit should withdraw, money from the account and should ensure that the debit amount does not exceed the accounts balance . if it does, the balance should be left unchanged and the function should print a message

2nd Oct 2020, 7:00 AM
hasna
hasna - avatar
2 Respostas
+ 1
Here is an example. Hope It helps you! class Account { private: double balance; public: Account(); Account(double b); double getBalance(); void setBalance(double b); void withdraw(); } Account::Account() { balance = 0; } Account::Account(double b) { if(b < 0) cout<<"Error!!! Amount of money cannot be less than 0"; else balance = b; } double Account::getBalance() { return balance; } void Account::setBalance(double b) { if(b < 0) cout<<"Error!!! Amount of money cannot be less than 0"; else balance = b; } void Account::withdraw() { double amount; char answer; cout<<"Input the amount of money: "; cin>>amount; while(amount > balance) { cout<<"The amount of money is greater than balance. Do you want continue (Y/N)?: "; cin>>anwser; if(answer == 'N' || answer == 'n') return; cout<<"Input the amount of money: "; cin>>amount; } balance -= amount; cout<<"The balance is current: "<<balance; }
2nd Oct 2020, 7:49 AM
Hung
0
thank you so much!
2nd Oct 2020, 9:17 AM
hasna
hasna - avatar