I am currently working on a banking service project, on a beginner level. I am thinking to cut down on how I have passed ‘Customer’ class’s cust object’s reference as a parameter in each method of each class, in a way so that I am able to NOT pass ‘Customer’ class’s object for a function definition.
class accounts;
class transactions;
class Customer;
class BankingServices;
class accounts
{
public:
int acc_no;
std::string acc_password;
public:
void details(Customer& cust) const
{
std::cout << "Your Account number is: " << cust.acc.acc_no << std::endl;
std::cout << "Your Account password is: " << cust.acc.acc_password << std::endl;
}
void add();
void bal(Customer& cust);
};
class transactions
{
public:
int transHis[3];
public:
transactions()
{
transHis[3] = {0};
}
void transfer(int amt, int to_acc_no, Customer& cust);
void withdraw(int amt, Customer& cust);
void deposit(int amt, Customer& cust);
void updateHis(int amt, Customer& cust);
void showTransHis(Customer& cust);
};
class Customer
{
public:
std::string name;
accounts acc;
transactions trans;
public:
Customer()
{
}
void details() const
{
std::cout << "Your Account number is: " << this->acc.acc_no << std::endl;
}
void create_cust(Customer& cust); // adds a customer and it's details into the database(it has add_acc() as a sub function)
};
class BankingServices
{
public:
Customer cust;
public:
BankingServices()
{
int val;
std::cout << "Press 1 to create an account, if not a customer and don't have an account." << std::endl;
std::cout << "Press 2 to enter account details ,if already a customer. " << std::endl;
// taking input for 'val' and checking
val = chkInputValfor2(&val);
if (val == 1)
{
this->cust.create_cust(this->cust);
}
else
{
std::cout << "Enter your first name: ";
std::cin >> this->cust.name;
std::cout << "Enter your Account Number: ";
std::cin >> this->cust.acc.acc_no;
std::cout << "Enter your Password: ";
std::cin >> this->cust.acc.acc_password;
}
}
void services()
{
int val;
std::cout << "Enter 1 to withdraw money " << "Enter 2 to deposit money" << std::endl;
std::cout << "Enter 3 to transfer money " << "Enter 4 to check acccount balance" << std::endl;
std::cout << "Enter 5 to see transaction history " << "Enter 6 to fetch account details" << std::endl;
std::cin >> val;
if (val == 1)
{
int amt;
std::cout << "Enter Amount to be withdrawn: ";
std::cin >> amt;
this->cust.trans.withdraw(amt, this->cust);
}
else if (val == 2)
{
int amt;
std::cout << "Enter amount to be deposited: ";
std::cin >> amt;
this->cust.trans.deposit(amt, this->cust);
}
else if (val == 3)
{
int amt, to_acc_no;
std::cout << "Enter amount to be transfered: ";
std::cin >> amt;
std::cout << std::endl;
std::cout << "Enter account number to reciever: ";
std::cin >> to_acc_no;
std::cout << std::endl;
this->cust.trans.transfer(amt, to_acc_no, this->cust);
}
else if (val == 4)
{
this->cust.acc.bal(this->cust);
}
else if (val == 5)
{
this->cust.trans.showTransHis(this->cust);
}
else if (val == 6)
{
this->cust.acc.details(this->cust);
}
else
{
std::cout << "Wrong input! Enter again" << std::endl;
services();
}
}
};
I thought of using inheritance but that didn’t work. I thought inheriting customer class in accounts, transactions, BankingServices class would help, but it didn’t. May be there is something i did wrong. I am expecting a way somehow I need not to pass the cust object’s reference for every function.
Kovidh V.S. Bhati is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.