Hi,
Some additional things:
You already have an array of your
struct
, so it seems unnecessary to have separate arrays for each of the things that are in the
struct
anyway.
Consider a
std::vector
, if allowed.
Try to avoid having
using namespace std;
Google to see why this is bad. Just put
std::
before each std thing - it's the best way in the end, all the expert people do it that way. You can use Find and Replace in your editor to change them all quickly.
Also avoid
endl
, it's not a problem now - but in future it could be inefficient because it flushes the buffer each time. Just use
'\n'
instead.
With this:
1 2
|
void printReport(int a, int w, int d, double eb, double bb, double ad, double aw, string name)
{
|
Consider having better meaningful variable names, don't worry about longer names - IMO it's a furphy to try to abbreviate everything too much. If one has good variable & function names, the code should read like telling a story. Here is a link to a comical version of what I mean, there is no reason why we all can't try to make our serious code read like this - without the humour I mean :+)
One can use this style to make the code easier to read:
1 2 3 4 5 6 7 8 9
|
void printReport(const int AccoutNumber, // use const when you know the value should not be changed
const int NumberOfWithdrawls,
const int NumberOfDeposits,
const double BalanceEnd,
const double BalanceBegin ,
const double DepositAmount,
const double WithdrawlAmount,
const std::string& name) // pass by reference for containers
{
|
With the
getFileName
functions, consider having a string as an argument for the type of account that it is, then you can have only one function, and avoid code duplication. The same idea applies to when the file was not found - only need 1 function for that as well.
For the
#defines
on lines 10 and 11, instead consider making use of the
toupper
function to convert the input to upper case, then you won't need the logic of upper or lower case.
Also, it's a good idea to declare your variables just before you use them. For example
dcount
(
DepositCount
) is declared on line 52 but not used until line 136.
Consider how many lines of code you have in functions. There is a sort of a rule that functions should not be longer than 40 LOC, some go for even less, and this includes
main
. Some of the things I mentioned earlier will help with this, but there is room for improvement. For example lines 128 to 146 should be a function. You have too much vertical white space - some is good, but too much isn't. The other concept is that a function should do 1 thing. Any compound statement (code in braces) is a good candidate for a function. This idea aids understanding because it is a simple form of abstraction.
What I mean about the abstraction, some pseudo code:
1 2 3
|
for (AllTheCars) {
WashCar();
}
|
I don't care HOW
WashCar()
works, all that I care about is that it washes a car. If I wrote that function, and someone else wants to use it, then they probably don't care either.
Anyway, Good Luck and we look forward to seeing your new code :+)