Archived

This topic is now archived and is closed to further replies.

My BankAccount Program

This topic is 5156 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey this was a second major project of mine still working on it I would like you to look over the code and tell me things that could improve my design for easier understanding. THANKS!
bool MENU = true;
#define STDOUT GetStdHandle(STD_OUTPUT_HANDLE)
#define FG_BLUE FOREGROUND_BLUE
#define FG_GREEN FOREGROUND_GREEN
#define FG_RED FOREGROUND_RED
using std::cout;
using std::cin;
using std::endl;
enum ERR_CODE {SUCCES = 1 , FAIL};
void Menu(int &rChoice);
void my_clrscr(); 

class BankAccount
{
public:
	BankAccount():Balance(0){};
	~BankAccount(){};
	void AddBalance(float &Money) {Balance = Balance + Money;}
	void TakeBalance(float &Money);
	float CheckBalance() const {return Balance;}
private:
	float Balance;
};

class ErrorCheck
{
public:
	ERR_CODE MoneyCheck(float &rMoney);
	ERR_CODE MenuCheck(int &rChoice);
};
#include <iostream>
#include <windows.h>
#include "Counter.hpp"

int main()
{
	BankAccount ClientOne;
	ErrorCheck ErrCheck;
	int Choice;
	float Money;

	while (MENU)
	{
		SetConsoleTextAttribute(STDOUT, FG_GREEN|FG_RED|FG_BLUE);
		cout << "\nCURRENT BALANCE: $" << ClientOne.CheckBalance() << '\n';
		Menu(Choice);
		if ((ErrCheck.MenuCheck(Choice)) == SUCCES)
		{
			switch(Choice)
			{
			case 1:
				cout << "Amount of Money to Input $";
				SetConsoleTextAttribute(STDOUT, FG_GREEN);
				cin >> Money;
				if ((ErrCheck.MoneyCheck(Money)) == FAIL)
					break;
				else
				{
					ClientOne.AddBalance(Money);
					SetConsoleTextAttribute(STDOUT, FG_GREEN|FG_RED|FG_BLUE);
					cout << "\nNew Balance $" << ClientOne.CheckBalance() << '\n';
					break;
				}
			case 2:
				cout << "Amount of Money to Take Out $";
				SetConsoleTextAttribute(STDOUT, FG_GREEN);
				cin >> Money;
				if ((ErrCheck.MoneyCheck(Money)) == FAIL)
					break;
				else
				{
					ClientOne.TakeBalance(Money);
					SetConsoleTextAttribute(STDOUT, FG_GREEN|FG_RED|FG_BLUE);
					cout << "\nNew Balance $" << ClientOne.CheckBalance() << '\n';
					break;
				}
			case 3:
				MENU = false;
				break;
			}
		}
	}
	
return 0;
}

ERR_CODE ErrorCheck::MoneyCheck(float &rMoney)
{
	if (rMoney < 0)
	{
		cout << "\nNo such thing as negative money!\n";
		return FAIL;
	}
	else 
		return SUCCES;
}

ERR_CODE ErrorCheck::MenuCheck(int &rChoice)
{
	if (rChoice < 1 || rChoice >3)
	{
		return FAIL;
	}
	else
	{
		return SUCCES;
	}
}

void BankAccount::TakeBalance(float &Money)
{
	if(Balance - Money < 0)
	{
		cout << "\nSorry you cannot take out that much money:(\n";
	}
	else
		Balance = Balance - Money;
}


void Menu(int &rChoice)
{
	int fChoice;
	cout << "Welcome Choose Something!" << endl;
	cout << "(1)Add Money\n";
	cout << "(2)Take Money\n";
	cout << "(3)Exit\n";
	cin >> fChoice;
	rChoice = fChoice;
}


void my_clrscr()
{    
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	COORD coord = { 0, 0 }; 
	DWORD count;
	CONSOLE_SCREEN_BUFFER_INFO console_info;
	GetConsoleScreenBufferInfo(handle, &console_info); 
	FillConsoleOutputCharacter(handle, ' ', console_info.dwSize.X * console_info.dwSize.Y, coord, &count);  
	SetConsoleCursorPosition(handle, coord); 
}
[edited by - Mat1515 on November 6, 2003 10:59:59 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Please list your bank account numbers and which bank you''re using, then we can help you a little more.

Share this post


Link to post
Share on other sites
Looks pretty good to me, but just some suggestions:

Why have the ErrorCheck class? It seems to me like you have just dumped two general, unrelated functions together in that class, and that is no reason for making a class. Declare them globally instead of writing a class specifically for them.

Also, IMO I wouldn't declare an enum for the sole purpose of checking function return values as either success or fail, that's what bool is for!

[edited by - chacha on November 6, 2003 10:42:26 AM]

Share this post


Link to post
Share on other sites