C++ 从数据集输出的银行帐户结构(这是一个赋值)

C++ 从数据集输出的银行帐户结构(这是一个赋值),c++,C++,我已被要求建立以下。在这个阶段,我只能编写与.h文件相对应的任务,不幸的是,尽管进行了数小时的研究,而且由于作为远程教育学生的痛苦,我的老师没有给我帮助。我不确定这些.h结构是否正确,也不确定从何处开始创建函数。你能告诉我我的.h文件是否正确吗?你能告诉我如何创建这个.h文件对应的函数吗 包含三个成员的Customer结构(在头文件Customer.h中定义): 客户名称、用户ID和Pin #ifndef CUSTOMER_H #define CUSTOMER_H using namespac

我已被要求建立以下。在这个阶段,我只能编写与.h文件相对应的任务,不幸的是,尽管进行了数小时的研究,而且由于作为远程教育学生的痛苦,我的老师没有给我帮助。我不确定这些.h结构是否正确,也不确定从何处开始创建函数。你能告诉我我的.h文件是否正确吗?你能告诉我如何创建这个.h文件对应的函数吗

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

    #ifndef CUSTOMER_H
    #define CUSTOMER_H
    using namespace std;
    
    struct customer
    {
        std::string name;
        std::string pin;
        std::string user_id
    };
    
  • 创建客户的函数
    CreateCustomer()
    。它有三个参数来初始化结构的每个成员(客户名称、用户ID和PinNumber)。所有参数都应具有默认的参数空白值。原型: 客户*CreateCustomer(常量字符串和名称、常量字符串和id、常量字符串和pin)

客户*CreateCustomer(常量字符串和名称、常量字符串和id、常量字符串和pin){ 返回新客户{name,id,pin}

  • 包含三个成员的事务结构(在头文件Transaction.h中定义):事务日期、说明和金额。金额不能为负值

    //.h文件

    struct Transaction 
    {
        std::string date;
        std::string description;
        double amount;
    };
    
  • 创建交易的函数CreateTransaction()。它有三个参数来初始化结构的每个成员(交易日期、说明和金额)。所有参数都应具有默认参数值。日期设置为“01/01/2014”,说明为空,金额为零。原型: 事务*创建事务(常量字符串和日期、常量字符串和说明、常量双精度和金额))

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

  • 函数CreateAccount()这将创建一个帐户。它有六个参数来初始化结构中的每个适当成员。日期参数用于为交易列表数组创建第一笔交易,说明是余额参数中的期初余额。因此,创建帐户后,交易计数应设置为一。所有参数第三个的ers应具有默认参数值。日期设置为“2014年1月1日”,余额、存款和取款设置为零值。原型:

    Account*CreateCount(常量客户和客户,常量标准::字符串& openingDate=“01/01/2014”,常数双和openingBalance=0,常数 双倍存款=0,双倍存款=0)

考虑到上述情况,我得到了一个数据集,其想法是,它曾经有一个特定的输出,他们在我的作业表中提供的代码粘贴在下面

> Provided Code - main() 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; }

先生,如果我之前的评论冒犯了您,我很抱歉。我想建议您学习您在课堂上可能错过的语言的基本知识

我将总结要点,就在这里,让您刷新您的记忆:

包括警卫 它们的目的是防止程序包含多个定义。它们的常用语法如下:

#ifndef X
#define X

    ...

#endif
这样做是为了在首次包含文件时,
ifndef X
将在预处理器中“计算”为
true
,并输入
ifndef
的正文(正文在
#endif
结束处结束)。正文应该做的第一件事是定义
X
,以便下次包含文件时,
ifndef
将在预处理器中“计算”到
false
,并“跳过”正文中包含的定义

标识符
X
对于每个文件当然应该是唯一的

使用命名空间
指令 当您包括
(请注意,标题不应包含
.h
)时,您包括
字符串
类,该类在
std
命名空间中定义。现在您有两个选择:

  • 使用
    std::string
  • 使用
    使用命名空间std;
    导入
    std
    命名空间,并能够使用
    字符串引用类
  • 通常认为第一种方法更好,但在学术环境中,第二种方法最常用。只需选择一种方法并坚持下去

    其他小事情 没有任何意义。每个语句/声明都应该以分号(
    )结尾,并且您已经在程序的其他部分中这样做了

    客户结构 您的客户结构应包括:

    • 名字
    • 用户id
    • 别针
    名称可以用字符串表示,因此我会使用
    std::string
    来表示。使用的ID和pin在我看来就像数字值,因此我可能会使用
    int
    来表示这两个值,导致结构为:

    struct Customer
    {
        std::string name;
        int pin;
        int user_id;
    };
    
    函数
    CreateCustomer
    这是分配:

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

    原型:
    Customer*CreateCustomer(常量字符串和名称、常量字符串和id、常量字符串和pin)

    从返回类型来看,我实际上害怕任务要求你做什么。他可能要求你返回一个动态分配的对象,这是非常糟糕的做法。但为了任务的缘故,这很简单,你可以使用:

    Customer* CreateCustomer(const string& name, const string& id, const string& pin) {
        return new Customer { name, id, pin };
    }
    
    关于这一点没什么要解释的。这是动态分配的内存,您应该
    std Transaction[]
    
    struct Customer
    {
        std::string name;
        int pin;
        int user_id;
    };
    
    Customer* CreateCustomer(const string& name, const string& id, const string& pin) {
        return new Customer { name, id, pin };
    }
    
    struct Transaction {
        std::string date;
        std::string description;
        double amount;
    };
    
    struct Account {
        Customer customer;
        int number;
        double balance, total_deposit, total_withdrawal;
        
    
        Transaction transactions[100];
    };
    
    struct CUSTOMER_H
    {
        std::string name[8];
        std::string pin;
        std::string Userid;
    };
    
    char name[8]; //this creates a character array with 8 elements numbered 0-7. You need to leave name[7] alone so it can hold the trailing \0, though, or you'll crash your program. So this can effectively hold a 7-character name.
    
    std::string name;
    
    //Transaction.h: we're just declaring things here
    struct Transaction
    {
      //<snip>
      double getAmount();
      void setAmount(double newAmount);
    
    private:
      double amount;
    }
    
    //Transaction.cpp: we're actually implementing things here. Yey code!
    
    double Transaction::getAmount() //note that we prefix the method name with the class name and a double colon. This is required when you're creating a class method.
    {
      return amount; //short and sweet. We don't need to do anything special here, we're just letting outside code see the value of amount since they can't access it directly.
    }
    
    void Transaction::setAmount(double newAmount)
    {
      if (newAmount > 0) //this is why we're doing the whole getter-setter thing. Now we get to control what goes into amount: amount will only be updated if newAmount > 0.
      {
        amount = newAmount;
      }
    }
    
    struct Account
    {
      //<snip>
      Transaction transactions[100];
      int transactionCount;
    }
    
    //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);
    
    //for the purposes of the next few lines of code, JoeCool is a valid Customer object that we've already set up using CreateCustomer.
    CreateAccount(JoeCool); //creates an account belonging to JoeCool. The opening date will be automatically set to 01/01/2014 and the balance, deposit and withdrawal will all be set to 0.
    CreateAccount(JoeCool, "09/10/14"); //creates an account belonging to JoeCool. The opening date will be set to 09/10/14, overriding our default date; however, since we didn't specify a balance, deposit, or withdrawal, they'll all be set to 0.
    CreateAccount(JoeCool, "12/11/15", 50, 100, 25); //creates an account belonging to JoeCool. We've overridden all our default parameters, so the opening date will be set to 12/11/15, the opening balance will be set to 50, the deposit will be set to 100, and the withdrawal will be set to 25.