UI for Setting up a Checking account and Savings account for my bank project

时间:2015-12-08 19:29:33

标签: c++

I want to display an interface asking the user whether or not they want to use checkings or savings account, and then when they choose bring them to my generic display menu. But I'm not quite sure how to set it up. I was told to make Account objects and use a pointer, but as you can see I'm stuck. If anyone could give me any insight on how I would do this, I would greatly appreciate it.

Here is my code:

Public class MainClass{

      public static void main (final String[] args){

          String txtToBeDecrypted = "DA67C73756184F20ED92DF1614CB85ED";

         final DesHelper h = new DesHelper();

         String xc = h.decrypt(txtToBeDecrypted);

         System.out.printls(xc);

     }

}

#ifndef ACCOUNT_H 
#define ACCOUNT_H 

class Account 
{ 
private: 
  double balance; // Account balance 
  double interestRate; // Interest rate for the period 
  double interest; // Interest earned for the period 
  int transactions; // Number of transactions 

public: 
  Account(double iRate = 0.045, double bal = 0) 
  { balance = bal; 
    interestRate = iRate; 
    interest = 0; 
    transactions = 0; } 

  void setInterestRate(double iRate) 
  { interestRate = iRate; } 

  void makeDeposit(double amount) 
  { balance += amount; transactions++; } 

  bool withdraw(double amount); // Defined in Account.cpp 

  void calcInterest() 
  { interest = balance * interestRate; balance += interest; } 

  double getInterestRate() const 
  { return interestRate; }

  double getBalance() const 
  { return balance; } 

  double getInterest() const 
  { return interest; }     

  int getTransactions() const 
  { return transactions; } 

}; 

#endif

1 个答案:

答案 0 :(得分:0)

尝试这样的事情:

char displayAccountSelectionMenu();
char displayAccountActionMenu();
void makeDeposit(Account *acct);
void withdraw(Account *acct);

int main() 
{ 
    Account Savings;
    Account Checkings;
    Account *acct = NULL;

    char choice; // Menu selection 

    do
    {
        // Display the menu and get a valid selection. 
        choice = displayAccountSelectionMenu();

        // Process the user's menu selection. 
        switch (choice)
        {
            case 'A':
                acct = &Savings;
                break;

             case 'B':
                acct = &Checkings;
                break;

             case 'C':
                return 0;
        }

        // Set numeric output formatting. 
        cout << fixed << showpoint << setprecision(2); 

        do 
        { 
            // Display the menu and get a valid selection. 
            choice = displayAccountActionMenu(); 

            // Process the user's menu selection. 
            switch (choice) 
            { 
                case 'A':
                    cout << "The current balance is $"
                         << acct->getBalance() << endl; 
                    break; 

                case 'B':
                    cout << "There have been "
                         << acct->getTransactions() 
                         << " transactions." << endl;
                    break; 

                case 'C':
                    cout << "Interest earned for this period: $"
                         << acct->getInterest() << endl; 
                    break; 

                case 'D':
                    makeDeposit(acct); 
                    break; 

                case 'E':
                    withdraw(acct); 
                    break; 

                case 'F':
                    acct->calcInterest(); 
                    cout << "Interest added." << endl; 
                    break;

                case 'G':
                    break;

                case 'H':
                    return 0;
            } 
        }
        while (choice != 'G'); 
    }
    while (true);

    return 0; 
} 

char displayAccountSelectionMenu()
{
    char choice;

    cout << "\n Welcome to The Bank \n"; 
    cout << "-----------------------------------------\n"; 
    cout << "Select an account:\n";
    cout << "A) Savings\n"; 
    cout << "B) Checking\n"; 
    cout << "C) Exit the program\n\n"; 
    cout << "Enter your choice: "; 

    cin >> choice; 
    choice = toupper(choice);

    while ((choice < 'A') || (choice > 'C'))
    { 
        cout << "Please make a choice in the range of A through C:"; 
        cin >> choice; 
        choice = toupper(choice);
    } 

    return choice;
}

char displayAccountActionMenu() 
{ 
    char choice;

    cout << "\n Welcome to The Bank \n"; 
    cout << "-----------------------------------------\n"; 
    cout << "Select an action:\n";
    cout << "A) Display the account balance\n"; 
    cout << "B) Display the number of transactions\n"; 
    cout << "C) Display interest earned for this period\n"; 
    cout << "D) Make a deposit\n"; 
    cout << "E) Make a withdrawal\n"; 
    cout << "F) Add interest for this period\n"; 
    cout << "G) Select a different account\n"; 
    cout << "H) Exit the program\n\n"; 
    cout << "Enter your choice: "; 

    cin >> choice; 
    choice = toupper(choice);

    while ((choice < 'A') || (choice > 'H'))
    { 
        cout << "Please make a choice in the range of A through H:"; 
        cin >> choice; 
        choice = toupper(choice);
    } 

    return choice;
} 

void makeDeposit(Account *acct)
{
    //...
}

void withdraw(Account *acct)
{
    // ...
}