Question
C++ question: I have a BankAccount class that has private member variables, string name, string id, and int balance. I made an array of 5
C++ question: I have a BankAccount class that has private member variables, string name, string id, and int balance. I made an array of 5 Bank Account objects that stored different names, bank balances, and id numbers, and I am required to allow a user to select whether they want to sort a bank account by name, id, or balance. I NEED to make a function using bubble sort code to sort through the array but I am not allowed to create a sort function for each member variable, what I mean by that is...if the user selects to sort by name or sort by balance, I can't call a sortbyname function or a sortbybalance function, I need to call the same sort function for all, but I don't know how to do this as I only know how to call a member function is I already know what function I need to access in the class, for example i would call the arr[i].getName to get the get name string to sort. But, I believe I am supposed to use templates, is there a way for me to call on the specific getter function for the variable option the user decides to sort the array with using templates that way I call upon the same sort function for the member function calls?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started