It is not even remotely moral to write the code for you (, nor would I enjoy the pointless exercise), but some guidance for your effort to search for this forum is in place. With all the derogatory attitude we may cause you to loose your faith in humanity. But I think everyone is stunned by the title of that post.
For starters, considering your level, forget smart solutions. There are good object oriented STL methods to be used in problems like this, but for you, few functions of your own and global variables will be more comprehensible. If the point is to write the code elegantly and compactly, to create the solution with maximum reuse of the features already available in the language's library, then stop reading my response.
Create a source file, open an IDE if you use one. Start with something less purposeful, just to experiment with.
In your problem, it should be obvious that you have several (3) distinct sets of data. The elements in each set are 'complex', in the sense that they have their own fields.
The most primitive non-C++, more like C, way to implement this is to use some structure for the elements in the set, like this:
1 2 3 4 5 6
|
struct A {
Type1 field1;
Type2 field2;
...
TypeN fieldN;
}
|
Then you can use array to represent the set:
N is fixed and this means that you must use another variable to store how much of those
A structures you actually use at each moment. When you have solution working with arrays, you may consider an STL equivalent that can grow arbitrarily and allows effective removal of entries.
Now, start breaking the operations the problem requires in little micro-steps. For example:
Transfer all holder accounts from branch to another branch. |
can be broken into many actions: "transfer a single holder account from one branch to another." Then break this further into:
1) find in the source branch one account for a holder
2) copy the account to the destination branch
3) remove the account from the source branch
4) adapt the data of the account in the destination branch, if necessary
Think about the steps required to complete an action. If it reads like a batch job, usually indicated by plural, then it is repetition of some fundamental step. Anticipate that doing something with something will require locating it first. Moving something usually requires copy and delete pair, etc. Forget the functions and the variables. They can be rearranged in many ways later without affecting the solution.
By this time, I hope you have realized that you will need to implement many generic (in the layman sense) actions for the data sets. You will need to be able to search in the data set, trying to match some component of the elements against some supplied value. E.g., you will need to search in
some_data_set, trying to match
field2 with some value. Create an empty C++ project in your IDE, or a C++ file and try to implement this in some generic case with which you feel comfortable. Gain confidence.
Now, if the search has unique match by design (like searching for a person by some ID), then the search is simply parametrized by the value you want to match and the result is the position where the occurrence was found. Do not forget to handle the case of no occurrences in the caller. Like, returning invalid position from the search and handling the situation in the calling function. Think what the user will expect. For example, warn the user, or simply do nothing.
If the search does not have unique match, you have to be able to call the search consecutively, restricting it to ever smaller portions of the set - if the search is forward, you will restrict it to the tail of the data set. The next search will follow after the position of the last occurrence. This requires another parameter. Then the calling function has a loop - finds occurrence with the search function, processes the occurrence, repeats with the elements of the data set following the last occurrence.
The searching will be equivalent if you use STL, but then you can directly use the provided implementations of the search functions. Implementing them is therefore redundant in the end, but I think that if you do not feel capable to do that, using the library routines is going to be hectic and incomprehensible for you. (I could never use STL if I did not feel I could create some idiotic substitute of STL functionality.)
Last hint. In the C-style approach above, deleting requires to first find what you want to delete, than move all following elements one position backward.
Someone had to communicate those ideas to you anyways. May be they did, or may be they didn't.
Regards