为我的银行项目设置支票账户和储蓄账户的UI
UI for Setting up a Checking account and Savings account for my bank project
我想显示一个界面,询问用户是否要使用支票或储蓄账户,然后当他们选择时,将其带到我的通用显示菜单。但我不太确定如何设置。我被告知要创建Account对象并使用指针,但正如你所看到的,我被卡住了。如果有人能告诉我如何做到这一点,我将不胜感激
这是我的代码:
#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 balancen";
cout << "B) Display the number of transactionsn";
cout << "C) Display interest earned for this periodn";
cout << "D) Make a depositn";
cout << "E) Make a withdrawaln";
cout << "F) Add interest for this periodn";
cout << "G) Exit the programnn";
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.nn";
}
试试这样的东西:
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) Savingsn";
cout << "B) Checkingn";
cout << "C) Exit the programnn";
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 balancen";
cout << "B) Display the number of transactionsn";
cout << "C) Display interest earned for this periodn";
cout << "D) Make a depositn";
cout << "E) Make a withdrawaln";
cout << "F) Add interest for this periodn";
cout << "G) Select a different accountn";
cout << "H) Exit the programnn";
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)
{
// ...
}
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 我的字符计数代码计算错误.为什么
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- cmake在我的项目中所需的所有静态库都不成功
- 为什么我的代码在输出中增加了93天
- 我的简单if-else语句是如何无法访问的代码
- 为什么我的for循环不能正确获取argv
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 0-1背包代码中的错误.我的代码中有什么错误
- 当我的阵列太大时出现分段错误
- 如何确认我的constexpr表达式实际上已经在编译时执行
- 当我使用 GUI 开发 QT 动态库时,如何查看我的 QT UI?
- 如何从 bash 脚本捕获终端输出并将其显示在我的 Qt UI 中?
- QT在UI文件中恢复了我的更改
- 我可以为我的自定义Qt UI元素定义自定义CSS/QSS属性吗?
- 为我的银行项目设置支票账户和储蓄账户的UI
- 我真的应该为我的应用程序使用单个qss文件而不是为每个(UI)类使用一个吗?
- 如何在我的qwidgets项目中复制.ui文件
- Win8如何将进程分类为"Background Process"?我的应用在 Win7 中运行,但在 Win8 中不显示任何 UI