Hello, everyone. I need help with a bank account class. I was supposed to create a class called Account which houses an attribute called balance that is protected and returns a double data type. There are some other things required of me which have been completed in the coded below. However, now i am being asked to create a menu to deposit, withdraw and show current balance. I am having a problem because what i am doing is not related to the class. Take a look at the code below please and give me some suggestions as to how to make an efficient menu. Help me with deposits and i will endeavor to work on the others.
#include <iostream.h> //predefined header file
#include <stdlib.h>
#include <conio.h>
#include <iomanip.h>
#include <stdio.h>
#include <dos.h>
#include <ctype.h>
class Accounts { //name of class
protected:
double balance;
public: //public member function
Accounts();
~Accounts();
double getbal() const;
void withdraw (double);
double deposit(double);
};
class savingsAccount: public Accounts {
public:
savingsAccount(double = 0.0);
~savingsAccount();
void payinterest();
void setrate(double);
protected: //protected member function
double rate;
};
class checkingAccount : public Accounts {
public:
checkingAccount(double = 0.0);
~checkingAccount();
void withdraw (double);
protected:
double fees;
};
Accounts::Accounts() : balance(0.0) {
}
Accounts::~Accounts(){
}
double Accounts::getbal() const {
return balance;
}
void Accounts::withdraw (double amount) {
if (amount > 0 && balance >= amount) {
balance -= amount;
}
}
double Accounts::deposit (double amount) {
if (amount > 0) {
balance += amount;
}
return balance;
}
savingsAccount::savingsAccount(double initbalance) : rate(0.0) {
balance = initbalance;
}
savingsAccount::~savingsAccount () {
}
void savingsAccount::payinterest() {
balance = balance*rate/365/100;
}
void savingsAccount::setrate(double r) {
if (r >= 0.0) {
rate = r;
}
}
checkingAccount::checkingAccount(double initbalance) : fees(0.0) {
balance = initbalance;
}
checkingAccount::~checkingAccount() {
}
void checkingAccount::withdraw(double amount) {
if (amount > 0 && balance >= amount) {
balance -= (amount+fees);
}
}
void main() {
Accounts a;
savingsAccount sa;
checkingAccount ca;
sa.setrate(16.30);
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<" WELCOME TO MY ACOOUNTING SYSTEM "<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<"Please wait for system load"<<endl;
cout<<""<<endl;
cout<<" loading..."<<endl;
sleep(3);
clrscr();
char choice;
cout<<" MAIN MENU"<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<" 1: Deposit"<<endl;
cout<<" 2: Withdraw"<<endl;
cout<<" 3: Account Balance"<<endl;
cout<<" 4: Exit"<<endl;
cout<<"Make Selection using the numbers ('X' to exit)"<<endl;
cout<<"---> "<<endl;
choice=toupper(getchar());
fflush (stdin);
switch(choice)
{
int dep;
case '1':
cout<<"Enter amount of money to deposit:"<< endl;
cin>>dep;
sa.payinterest();
break;
case '2':
a.getbal();
break;
case '3':
a.getbal();
break;
case '4':
break;
default:
cout<<"Invalid menu item...Please re-enter your choice"<<endl;
sleep(2);
break;
}//end of case
cout<<""<<endl;
cout<<"Savings Account Balance Before: $"<<sa.getbal()<<endl;
cout<<"Checking Account Balance Before: $"<<ca.getbal()<<endl<<endl;
//we do some operations here
ca.withdraw(6700.43);
sa.payinterest();
sa.deposit(1500.00);
cout<<"Savings Account Balance After: $"<<sa.getbal()<<endl;
cout<<"Checking Account Balance After: $"<<ca.getbal()<<endl;
cout<<endl;endl;
system("pause");
}