【问题标题】:c++ developing BankAccount structure that creates a customer, transactions, accounts (uni assign help)c ++开发创建客户,交易,帐户的BankAccount结构(uni分配帮助)
【发布时间】:2014-05-11 11:42:24
【问题描述】:

男孩和女孩,我提前感谢你们的帮助。又是 C++ 问题。我在大学作业中遇到了困难,由于堆栈政策,我正在构建几天前在此单独帖子中发布在堆栈上的先前问题。

我的问题:下面是我的代码不起作用,有人可以帮我让它工作吗?我错过了什么? (我觉得我错过了很多)。

我在单独的头文件中有函数和结构,在 .ccp 中有“int main”。我正在使用 vis studio 来执行此操作。请不要认为我试图让其他人完成我的任务。下面是我的代码,后面是分配任务表(仅供参考)。

>     CODE
>     
>     // the int main must be my output to screen
>     int main()
>     {
>     Customer* Mary = CreateCustomer("Mary Jones", "235718", "5074");
>     Customer* John = CreateCustomer("John Smith", "375864", "3251");
>     Account* MaryAccount = CreateAccount(*Mary, "06-3121-10212357", "01/03/2014", 100);
>     Account* JohnAccount = CreateAccount(*John, "06-3121-10213758", "10/03/2014");
>     RecordWithdraw(MaryAccount, CreateTransaction("01/03/2014", "ATM Withdrawal", 50) );
>     RecordDeposit(MaryAccount, CreateTransaction("02/03/2014", "Deposit", 90) );
>     RecordWithdraw(MaryAccount, CreateTransaction("04/03/2014", "ATM Withdrawal", 150) );
>     RecordDeposit(MaryAccount, CreateTransaction("05/03/2014", "Deposit", 20) );
>     RecordWithdraw(MaryAccount, CreateTransaction("05/03/2014", "Withdraw", 100) );
>     RecordWithdraw(MaryAccount, CreateTransaction("05/03/2014", "Withdraw", 50) );
>     RecordDeposit(JohnAccount, CreateTransaction("11/03/2014", "Deposit", 20) );
>     RecordDeposit(JohnAccount, CreateTransaction("12/03/2014", "Deposit", 80) );
>     RecordWithdraw(JohnAccount, CreateTransaction("12/03/2014", "Withdraw", 50) );
>     PrintReport(MaryAccount);
>     PrintReport(JohnAccount);
>     return 0;
>     }
>     
>     // the .h file as a struct ass1 section CUSTOMER
>     
>     #ifndef CUSTOMER_H
>     #define CUSTOMER_H
>     
>     using namespace std;
>     
>     struct customer
>     {
>         std::string name;
>         std::string pin;
>         std::string user_id
>     };
>     
>     
>     // function for the above CUSTOMER
>     
>     Customer* CreateCustomer(const string& name, const string& id, const string& pin) {
>         return new Customer { name, id, pin };
>     
>     }
>     
>     
>     // the .h file as a struct ass1 section transaction
>     
>     struct Transaction 
>     
>     {
>         std::string date;
>         std::string description;
>         double amount;
>     };
>     
>     
>     
>     // function for the above transaction
>     
>     
>     transaction* CreateTransaction(const string& date, const string& description, const double& amount) {
>     
>         return new transaction { date, description, amount };
>     
>     }
>     
>     
>     // the .h file as a struct ass1 section account
>     
>     
>         struct Account {
>         Customer customer;
>         int number;
>         double balance, total_deposit, total_withdrawal;
>     
>     // function for the above account 
>     
>     //CreateAccount prototype:
>     
>     
>     Account* CreateAccount(const Customer& customer, const std::string& openingDate = "01/01/2014", const double& openingBalance
> = 0, const double& deposit = 0, const double& withdraw = 0);

对于这个分配,客户结构必须是:

CustomerName: string UserID: string Pin: string

交易结构必须是:

交易日期:字符串 交易描述:字符串 交易金额:双倍

帐户结构必须是:

持有人:客户 帐号:字符串 余额:双 总存款:双倍 总提款:双倍 交易清单:交易[] 交易计数:整数

包含三个成员的客户结构(在头文件 Customer.h 中定义): 客户姓名、用户 ID 和 Pin。

  • 创建客户的函数 CreateCustomer()。它有三个参数来初始化 结构的每个成员(客户名称、用户 ID 和 PinNumber)。所有参数 应指定默认参数空白值。原型:

Customer* CreateCustomer(const string& name, const string& id, const string& pin)

  • Transaction 结构(在头文件 Transaction.h 中定义)包含三个成员: 交易日期、描述和金额。金额不能为负值。

  • 创建事务的函数 CreateTransaction()。它具有三个参数来初始化结构的每个成员(交易日期、描述和金额)。所有参数都应具有要指定的默认参数值。日期设置为“01/01/2014”,描述为空白,金额为零。原型:

Transaction* CreateTransaction(const string& date, const string& description, const double& amount))

  • 包含七个成员的 Account 结构(在头文件 Account.h 中定义): 账户持有人,数量,余额,总存款,总取款,交易列表数组 现有交易记录最多 100 条记录和交易计数。

  • 创建帐户的函数 CreateAccount()。它有六个参数来初始化每个参数 结构的适当成员。用于创建第一笔交易的日期参数 Transaction List 数组,描述为余额参数中的期初余额。 因此,创建帐户后应将事务计数设置为 1。全部 第三个参数应该具有要指定的默认参数值。这 日期设置为“01/01/2014”,余额、存款和取款设置为零值。原型:

Account* CreateAccount(const Customer& holder, const string& number, const string& date, const double& 余额, const double&充值, const double&提现)

  • 一个函数 RecordDeposit() 将事务参数存储到事务列表中 参数 Account 的数组,并将 Transaction 计数加一。确保 检查交易参数的金额必须大于零。否则,显示 错误信息。不需要默认参数值。 void RecordDeposit(Account* account, Transaction* 交易)

  • 将 Transaction 参数存储到 Transaction List 的函数 RecordWithdraw() 参数 Account 的数组,并将 Transaction 计数加一。确保 检查交易参数的金额必须大于零且小于等于 参数账户余额。否则,显示错误消息。没有要求 默认参数值。

void RecordWithdraw(Account* account, Transaction* transaction)

  • 函数 PrintReport() 接受 Account 指针参数以显示摘要 余额帐户和数组上的交易记录列表显示为提供的输出 格式。原型:

void PrintReport(Account* account)

【问题讨论】:

    标签: c++ arrays dynamic parameters


    【解决方案1】:

    为了清晰起见,我将尝试给出一个通用结构而不是确切的代码。 您的 Account 结构需要一组交易来存储最近的 100 笔交易。添加一个新字段来存储这些(Transaction[] 或 Transaction*)。在 CreateAccount() 中,将其设置为 100 长的数组(初始化它)。在 CreateAccount() 中,您还需要使用参数中给出的信息设置所有字段。 在 RecordWithdraw() 和 RecordDeposit() 中,检查交易是否合法(由提供的限制允许),然后将新交易添加到交易数组中的下一个空闲槽(由 transaction# 确定),然后更新余额,总计提款/存款,以及账户的交易号。 希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-09
      • 2017-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-21
      • 2014-04-06
      相关资源
      最近更新 更多