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");
	}

I am having a problem because what i am doing is not related to the class.

What do you mean? What specifically are you having difficulty with...Also, does your code compile? If not, where are the issues...

Take a look at the code below please and give me some suggestions as to how to make an efficient menu

If you are bent on making console menus, you may be interested in looking up escape sequences to help you format...
http://msdn.microsoft.com/en-ca/library/h21280bw.aspx

As for making an efficient menu, I would suggest moving all your menu initialization into another method (that stuff where you have "loading" and what not), and then the actual main menu to another method (called menu or whatever). This will just make things cleaner and easier to work with (in my opinion).

Then, based on whatever choice, you can move into separate sub-menus and whatnot (more functions)...I would also suggest you always have an option to return to the main menu (from a sub-menu if you implement this), and possibly might want to look into some error checking.

But if you really want my opinion on how to improve it, I would suggest making a program GUI...would make things way cleaner (from an end-user perspective), and would be a good way for you to start moving away from console applications....If you are interested (and I assume you are on windows), and have time on your hands, then look into Win32 programming.

Thanks for the reply. Yes, the program compiles fine. The only issue is getting the menu to work. I will review your recommendations and update when through.

How can i get the deposited funds from variable dep to be added to the savings account balance of 1500.

{
         int dep;
               case '1':
               	cout<<"Enter amount of money to deposit:"<< endl;
                 [B] cin>>dep;[/B]
                  sa.deposit ();
                  break;

to b added to

//we do some operations here
  ca.withdraw(6700.43);
	sa.payinterest();
	[B]sa.deposit(1500.00)[/B];

in the code from my first post?

This article has been dead for over six months. Start a new discussion instead.