Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/155.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 作为对象数组从键盘输入的类的对象数_C++_Arrays_Object - Fatal编程技术网

C++ 作为对象数组从键盘输入的类的对象数

C++ 作为对象数组从键盘输入的类的对象数,c++,arrays,object,C++,Arrays,Object,我尝试做的这个练习在某一点上是这样的: 1-为每个储户生成唯一的帐号 对于第一个储户,账号为BA1000,对于第二个储户,账号为BA1001,依此类推 2-用户将通过键盘输入存款人数 因此,我知道下面的代码是不够的,但我只是不明白在用户输入对象(存款人)之前,我应该如何知道对象(存款人)的数量,所以我可以在generateAccount函数中使用该数字,这样我就可以知道通过存款人循环多长时间才能获得“BA1000”式的银行帐户 #include <iostream> using n

我尝试做的这个练习在某一点上是这样的:

1-为每个储户生成唯一的帐号 对于第一个储户,账号为BA1000,对于第二个储户,账号为BA1001,依此类推

2-用户将通过键盘输入存款人数

因此,我知道下面的代码是不够的,但我只是不明白在用户输入对象(存款人)之前,我应该如何知道对象(存款人)的数量,所以我可以在generateAccount函数中使用该数字,这样我就可以知道通过存款人循环多长时间才能获得“BA1000”式的银行帐户

#include <iostream>

using namespace std;

class BankAccount {

public:

string depistor_name;
string depositor_address;
string account_type;
int account_balance, nr_transactions;

void generateAccount () {
    string acc = "BA";
    int acc_nr = 1000;

    for ( int i = 0; i < //unknown number of objects so i have no variable to put here ; i++) {

    // below are comments of what i would need to do with this function
    // iterate and add +i to the acc_nr variable, until theres no more depositors.
   // print "BA" string + new acc_nr variable for each object
}

};

int main(int argc, const char * argv[]) {

return 0;

}
#包括
使用名称空间std;
类别银行帐户{
公众:
字符串depistor_name;
字符串储户地址;
字符串帐户类型;
国际账户余额、nr交易;
void generateAccount(){
字符串acc=“BA”;
int acc_nr=1000;
for(int i=0;i
如果我不需要使用用户从键盘输入的对象(储户)数量,我通常只需要创建一个对象数组,如下所示:

int x;
std::cout << "Please enter number of depositors";
cin >> x;
BankAccount ac[x];
intx;
std::cout>x;
银行账户ac[x];
但是我需要知道用户将要输入多少存款人,这样我就可以迭代并生成如上所示的帐户,而且我不知道是否有方法从类中的函数main中提取x


如果你不明白我想说什么,请询问更多细节,因为这可能会让人困惑。

你是否考虑过使用<代码>银行账户Ac[x]?不是标准C++,当代码> x/COD>不是常数表达式时,应该避免使用。在可能的情况下,最好使用<代码> STD::vector < /Cord>,否则您需要动态分配内存。这不是我所要求的,但我会采纳这个建议。我仍然不知道该如何做通用帐户功能。在不知道用户将从键盘输入多少对象的情况下进行初始化。检查-其Java,但方法相同。并且使用
std::vector