问题描述
我正在使用类创建银行数据库。我创建了一个大小为N的动态数组。现在,我想创建一个BankAccount类的对象,并将其附加到该数组中。另外,是否可以使用参数化构造函数使用动态数组初始化对象?如果是,如何在不提供参数的情况下声明动态数组?
class BanKAccount
{
public:
BanKAccount();
void Initialization();
void deposit(double b);
void withdraw(double b);
void Change_type(double b);
void change_name();
void GetFirstName();
void GetLastName();
void GetBalance();
void GetAccountNumber();
void GetAccountType();
~BanKAccount(); //destructor
private:
string first_name;
string second_name;
long acc_num;
char acc_type;
double Balance;
};
...
void Menu()
{
cout << "\nEnter A to create a new bank account" << endl;
cout << "Enter B to delete an existing bank account" << endl;
cout << "Enter C to perform a deposit transaction" << endl;
cout << "Enter D to perform a withdrawal transaction"<< endl;
cout << "Enter E to change account type of a customer" <<endl;
cout << "Enter F to check balance of a customer"<< endl;
cout << "Enter G to check account type of a customer" << endl;
cout << "Enter H to check the total balance of the bank" << endl;
cout << "Enter I to change name of a customer" <<endl;
cout << "Enter 0 to exit" <<endl;
}
void BanKAccount::Initialization()
{
cout << "Enter your First Name: ";
cin >> first_name;
}
void BanKAccount::deposit(double b)
{
Balance = Balance + b;
Change_type(Balance);
}
void BanKAccount::withdraw(double b)
{
Balance = Balance -b;
Change_type(Balance);
}
void BanKAccount::Change_type(double b)
{
if(b<50000)
{
acc_type = 'B';
}
}
void BanKAccount::GetBalance()
{
cout << "Your Balance: " << Balance<< endl;
}
void BanKAccount::GetAccountType()
{
cout << "Your Account Type is: " << acc_type <<endl;
}
void BanKAccount::GetFirstName()
{
cout << "First Name: " << first_name <<endl;
}
void BanKAccount::GetLastName()
{
cout << "Last Name: "<< second_name << endl;
}
void BanKAccount::change_name()
{
cout << "Enter your new first name: ";
cin >> first_name;
cout << "Enter your new second name: ";
cin >> second_name;
}
void BanKAccount::GetAccountNumber()
{
cout << "Your Account: " << acc_num;
}
BanKAccount::BanKAccount()
{
}
BanKAccount::~BanKAccount()
{
cout << "Destryoed";
}
int main()
{
int N;
int check = 0;
char response;
cout << "Enter the number of Accounts a Bank can Have: ";
cin >> N;
BanKAccount *ptr;
ptr = new BanKAccount[N];
do
{
Menu();
cin >> response;
while(!(response == '0' || response == 'A' || response == 'B' || response == 'C' || response == 'D' || response == 'E' || response == 'F' || response == 'G' || response == 'H' || response == 'I'))
{
cout << "Wrong input!: ";
cin>> response;
}
if(response == 'A')
{
system("CLS");
BanKAccount c1;
c1.Initialization();
//How do I append c1 to array?
}
}
while(response != '0');
return 0;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)