I approached the program similar to how I've learned to think about a game. I made a big, state driven loop. I used enums to control the states, and just used a boolean value (exit) to control the loop.
First, the user selects the language after they insert their card (card is 'inserted' automatically, there is a cout statement that tells the user they inserted it.) So, we have to have the rest of the program's output in 2 languages. I chose English and Spanish. I implemented this by setting any output that is given to the console as variables. I set constants, for example,
const string ENGLISH_PIN_MENU_TEXT = "Please enter your pin Number.";
const string SPANISH_PIN_MENU_TEXT = "BLAH BLAH BLAH EL BLAH";
string pinMenuText;
while (!exit)
switch (currentState)
{
case SELECT_LANGUAGE:
if (input == 1) //english
pinMenuText = ENGLISH_PIN_MENU_TEXT;
else if (input == 2) //spanish
pinMenuText = SPANISH_PIN_MENU_TEXT;
break;
case PIN_MENU:
int input;
cout << pinMenuText;
cin >> input;
etc...
Is this a good way to implement language localization? I was trying to avoid writing to the hard drive cause I'm not extremely comfortable with file parsing and all that yet.
So yeah. The language implementation is one of the big things I would appreciate criticism on.
The other big question I have is about my menu implementation. I created a class ATMMenu that I used to make formatting the output text for each state in the program a little bit easier.
class ATMMenu {
public:
void SetText(std::string txtdisplayed);
void AddOption(int option, std::string optiontext);
void SetMaxTries(int maxtries);
int GetMaxTries();
int GetInput();
void Display();
private:
std::string _MenuText;
static const int MAX_OPTIONS = 5;
std::string _Options[MAX_OPTIONS];
int _MaxTries = 50;
std::string _Error;
};
Did I implement all of this alright? The general idea is that I use SetText to set the Menu's Text, AddOption to add options for the user to select, and then Display() outputs both of them together in a formatted cout state. GetInput then uses cin statements so that in my main() method I can put GetInput into a switch statement and then handle the user's input from there. Max Tries are there so that in the main() method I can use a for loop to let the user go through a menu more than once if incorrect input is entered (if the input is correct, the for loop breaks, if not, it loops again and gets more user input). How is this looking?
Those are my big 3 questions about everything I coded. The Language Implementation, The State Driven Design, and the ATMMenu class. What could I have done differently? How could I have added more classes and simplified the design? Is my coding style alright? How could I have taken advantage of pointers?
Here is one more excerpt from my actual program that shows the usage of the ATMMenu class and also the for loop I was talking about.
// Select account to display or withdraw from
case SELECT_ACCOUNT:
{
ATMMenu selAcct;
selAcct.SetText(accountSelect);
// Adds the options, checking and savings are both //string variables that are set in the SELECT_LANGUAGE state of //the loop
selAcct.AddOption(1, checking);
selAcct.AddOption(2, savings);
// allows the user multiple chances to enter correct
//input
for (int i = 0; i < selAcct.GetMaxTries(); i++)
{
selAcct.Display();
switch (selAcct.GetInput())
{
case 1:
//activeAccount is an enum
activeAccount = CHECKING;
curBal = CheckingBalance;
curState = BALANCE_OR_WITHDRAW;
break;
case 2:
activeAccount = SAVINGS;
curBal = SavingsBalance;
curState = BALANCE_OR_WITHDRAW;
break;
// 0 is used to exit the program.
case 0:
exit = true;
break;
default:
// handles all other entered numbers
cout << endl << invalidNumberError << endl;
break;
}
// If the correct input is received, break out of the for loop.
if (curState == BALANCE_OR_WITHDRAW || exit == true)
{
break;
}
}
break;
}
Thanks for any help I'm given.