我想顯示的界面,詢問用戶是否他們想用checkings或儲蓄賬戶,然後當他們選擇把他們帶到我的通用顯示菜單。但我不太清楚如何設置它。我被告知要製作帳戶對象並使用指針,但正如您所看到的,我被卡住了。如果任何人都可以告訴我如何做到這一點,我將不勝感激。UI爲建立一個支票賬戶和儲蓄賬戶爲我的銀行項目
這裏是我的代碼:
#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
int main()
{
Account Savings;
Account Checkings;
Account *ptr;
Account savings; // Savings account object
char choice; // Menu selection
// Set numeric output formatting.
cout << fixed << showpoint << setprecision(2);
do
{
// Display the menu and get a valid selection.
displayMenu();
cin >> choice;
while (toupper(choice) < 'A' || toupper(choice) > 'G')
{
cout << "Please make a choice in the range " << "of A through G:";
cin >> choice;
}
// Process the user's menu selection.
switch(choice)
{
case 'a':
case 'A': cout << "The current balance is $";
cout << savings.getBalance() << endl;
break;
case 'b':
case 'B': cout << "There have been ";
cout << savings.getTransactions() << " transactions.\n";
break;
case 'c':
case 'C': cout << "Interest earned for this period: $";
cout << savings.getInterest() << endl;
break;
case 'd':
case 'D': makeDeposit(savings);
break;
case 'e':
case 'E': withdraw(savings);
break;
case 'f':
case 'F': savings.calcInterest();
cout << "Interest added.\n";
}
} while (toupper(choice) != 'G');
return 0;
}
void displayMenu()
{
cout << "\n Welcome to The Bank \n";
cout << "-----------------------------------------\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) Exit the program\n\n";
cout << "Enter your choice: ";
}
void makeDeposit(Account *acct)
{
double dollars;
cout << "Enter the amount of the deposit: ";
cin >> dollars;
cin.ignore();
acct.makeDeposit(dollars);
}
void withdraw(Account *acct)
{
double dollars;
cout << "Enter the amount of the withdrawal: ";
cin >> dollars;
cin.ignore();
if (!acct.withdraw(dollars))
cout << "ERROR: Withdrawal amount too large.\n\n";
}
我建議投資 ''在你的描述中。看起來像一個長句。 –
您可以通過'之開關語句之前choice'轉換'爲大寫或小寫節省了大量的代碼。請參閱'std :: toupper'或'std :: tolower'。 –