Your final code is nice and clean (as in, easy to understand) but there are a few improvements you could make. 1 - 7 are the keys ones. The other three prob more a matter of taste.
1. you should use clearer names for your function params and some of your variables.
(And I like to see param names in forward definitions, so I get a better idea of what data is being passed to the function, without having to find the defnition)
2 bool variables should be set to either true or false
3.as you're outputting a fixed set of const string, I would prob not use std::string here
Each time you call string::operator= you're copying a string from its char buffer to heap memory. If you were building a longer string, this would make sense, but here I would make "ouput" a const char*
4. setw only applies to the first insertions after it. so this line
cout << fixed << setw(3);
should lose the - pointless - setw()
Same with first line in drawTable()
See:
http://www.cplusplus.com/reference/iostream/manipulators/setw/
But fixed applies until it is changed to scientific, so you don't need to use it before each insertion, unless you use a mixture of fixed and scientific
5. It would prob be better to use constants for the graph range.
(Or even variables)
6. I would prob test bGraphed separately to your other condition, so you don't repeat the same test so often.
(I also prefer to test independent decisions separately: here you asking (a) am I plotting a point or not and (b) if not, am I on an axis)
7. I would use const for the first param of your two drawing functions
1 2
|
void drawTable(const point object[], int);
void drawGraph(const point object[]);
|
8. For consistency, I would define calcNumbers as:
void calcNumbers(point object[], int);
(or use point* for all functions)
9. The return at the end of the functions returning void could be removed. You only need a
return;
if you want to exit the function early.
(It's benign but not normally done. As a lot of people are lazy?)
10. Finally, a matter of personal taste. I would use "x == 0" where you use !x. This is because it makes it clearer to me what's happening (I only ever use !x style for bool values)
Andy