Skip to main content
removed cursing and fixed a minor spelling issue
Source Link
Malachi
  • 28.7k
  • 11
  • 86
  • 188

Yes, the code's terrible and yes you've used overloading incorrectly, but it's hard for me to see how you were supposed to fill your project spec without using it incorrectly. Your lecturer must be awful if this stuff is what he teaches.

using namespace std;

Don't, ever. std is full of an ever-increasing number of unconstrained template algorithms with generic names. The price of writing std::cout instead of cout is nothing, and the price of having the compiler pick std::distance instead of your own distance will make you cry.

const int SIZE_OF_GENERIC_ARRAY = 100; 
const int SIZE_OF_FIBONACCI_ARRAY = 20;

All upper case names are conventionally reserved for macros. You don't want to know what happens if you clash with a macro. In addition, these are known as "magic buffer sizes"- they're constants with no logic or reason behind them. You should, at the absolute minimum, comment on why these specific sizes were required.

double arithmeticAverage;
char sequenceType;

Do not ever declare mutable variables at namespace scope. They are the worst kind of sin. They're awful, uncontrollable, and an incredible bitchare incredibly difficult to clean up later.

float Array[SIZE_OF_GENERIC_ARRAY];
int Fibonacci[SIZE_OF_FIBONACCI_ARRAY];

Do not ever use C-style arrays. They are that way for compatibility with B or BCPL, not because their behaviour is good. It isn't. They are tremendously unsafe. You can use std::array<float, size> or std::array<int, size> instead. std::array lives in <array> and acts like a real value type and Standard container.

Also, the whole _tmain thing is totally unnecessary, it's a legacy holdover from 1995 that has no use anymore. Use main unless you know what this stuff actually is. You also don't need that stdafx crap, although it takes a little knowledge to convince Visual Studio to shut up about it.

Now, as you've correctly noticed, your mean and standardDeviation functions are complete duplicates w.r.t. float and int versions. You can easily re-implement them as one template function for both, but they can also be much more easily defined by using the appropriate Standard algorithms, which live in <algorithm> and <numeric>.

Finally, outputMean and outputStandardDeviation are worthless junk, their logic should just be in main (also, don't they always use the terribly-named Array, instead of the FibonnacciFibonacci array, even if the user asked for Fib?)

Yes, the code's terrible and yes you've used overloading incorrectly, but it's hard for me to see how you were supposed to fill your project spec without using it incorrectly. Your lecturer must be awful if this stuff is what he teaches.

using namespace std;

Don't, ever. std is full of an ever-increasing number of unconstrained template algorithms with generic names. The price of writing std::cout instead of cout is nothing, and the price of having the compiler pick std::distance instead of your own distance will make you cry.

const int SIZE_OF_GENERIC_ARRAY = 100; 
const int SIZE_OF_FIBONACCI_ARRAY = 20;

All upper case names are conventionally reserved for macros. You don't want to know what happens if you clash with a macro. In addition, these are known as "magic buffer sizes"- they're constants with no logic or reason behind them. You should, at the absolute minimum, comment on why these specific sizes were required.

double arithmeticAverage;
char sequenceType;

Do not ever declare mutable variables at namespace scope. They are the worst kind of sin. They're awful, uncontrollable, and an incredible bitch to clean up later.

float Array[SIZE_OF_GENERIC_ARRAY];
int Fibonacci[SIZE_OF_FIBONACCI_ARRAY];

Do not ever use C-style arrays. They are that way for compatibility with B or BCPL, not because their behaviour is good. It isn't. They are tremendously unsafe. You can use std::array<float, size> or std::array<int, size> instead. std::array lives in <array> and acts like a real value type and Standard container.

Also, the whole _tmain thing is totally unnecessary, it's a legacy holdover from 1995 that has no use anymore. Use main unless you know what this stuff actually is. You also don't need that stdafx crap, although it takes a little knowledge to convince Visual Studio to shut up about it.

Now, as you've correctly noticed, your mean and standardDeviation functions are complete duplicates w.r.t. float and int versions. You can easily re-implement them as one template function for both, but they can also be much more easily defined by using the appropriate Standard algorithms, which live in <algorithm> and <numeric>.

Finally, outputMean and outputStandardDeviation are worthless junk, their logic should just be in main (also, don't they always use the terribly-named Array, instead of the Fibonnacci array, even if the user asked for Fib?)

Yes, the code's terrible and yes you've used overloading incorrectly, but it's hard for me to see how you were supposed to fill your project spec without using it incorrectly. Your lecturer must be awful if this stuff is what he teaches.

using namespace std;

Don't, ever. std is full of an ever-increasing number of unconstrained template algorithms with generic names. The price of writing std::cout instead of cout is nothing, and the price of having the compiler pick std::distance instead of your own distance will make you cry.

const int SIZE_OF_GENERIC_ARRAY = 100; 
const int SIZE_OF_FIBONACCI_ARRAY = 20;

All upper case names are conventionally reserved for macros. You don't want to know what happens if you clash with a macro. In addition, these are known as "magic buffer sizes"- they're constants with no logic or reason behind them. You should, at the absolute minimum, comment on why these specific sizes were required.

double arithmeticAverage;
char sequenceType;

Do not ever declare mutable variables at namespace scope. They are the worst kind of sin. They're awful, uncontrollable, and are incredibly difficult to clean up later.

float Array[SIZE_OF_GENERIC_ARRAY];
int Fibonacci[SIZE_OF_FIBONACCI_ARRAY];

Do not ever use C-style arrays. They are that way for compatibility with B or BCPL, not because their behaviour is good. It isn't. They are tremendously unsafe. You can use std::array<float, size> or std::array<int, size> instead. std::array lives in <array> and acts like a real value type and Standard container.

Also, the whole _tmain thing is totally unnecessary, it's a legacy holdover from 1995 that has no use anymore. Use main unless you know what this stuff actually is. You also don't need that stdafx crap, although it takes a little knowledge to convince Visual Studio to shut up about it.

Now, as you've correctly noticed, your mean and standardDeviation functions are complete duplicates w.r.t. float and int versions. You can easily re-implement them as one template function for both, but they can also be much more easily defined by using the appropriate Standard algorithms, which live in <algorithm> and <numeric>.

Finally, outputMean and outputStandardDeviation are worthless junk, their logic should just be in main (also, don't they always use the terribly-named Array, instead of the Fibonacci array, even if the user asked for Fib?)

added 16 characters in body
Source Link
DeadMG
  • 849
  • 7
  • 12

Yes, the code's terrible and yes you've used overloading incorrectly, but it's hard for me to see how you were supposed to fill your project spec without using it incorrectly. Your lecturer must be awful if this stuff is what he teaches.

using namespace std;

Don't, ever. std is full of an ever-increasing number of unconstrained template algorithms with generic names. The price of writing std::cout instead of cout is nothing, and the price of having the compiler pick std::distance instead of your own distance will make you cry.

const int SIZE_OF_GENERIC_ARRAY = 100; 
const int SIZE_OF_FIBONACCI_ARRAY = 20;

All upper case names are conventionally reserved for macros. You don't want to know what happens if you clash with a macro. In addition, these are known as "magic buffer sizes"- they're constants with no logic or reason behind them. You should, at the absolute minimum, comment on why these specific sizes were required.

double arithmeticAverage;
char sequenceType;

Do not ever declare mutable variables at namespace scope. They are the worst kind of sin. They're awful, uncontrollable, and an incredible bitch to clean up later.

float Array[SIZE_OF_GENERIC_ARRAY];
int Fibonacci[SIZE_OF_FIBONACCI_ARRAY];

Do not ever use C-style arrays. They are that way for compatibility with B or BCPL, not because their behaviour is good. It isn't. They are tremendously unsafe. You can use std::array<float, size> or std::array<int, size> instead. std::array lives in <array> and acts like a real value type and Standard container.

Also, the whole _tmain thing is totally unnecessary, it's a legacy holdover from 1995 that has no use anymore. Use main unless you know what this stuff actually is. You also don't need that stdafx crap, although it takes a little knowledge to convince Visual Studio to shut up about it.

Now, as you've correctly noticed, your mean and standardDeviation functions are complete duplicates of each otherw.r.t. float and int versions. You can easily re-implement them as one template function for both, but they can also be much more easily defined by using the appropriate Standard algorithms, which live in <algorithm> and <numeric>.

Finally, outputMean and outputStandardDeviation are worthless junk, their logic should just be in main (also, don't they always use the terribly-named Array, instead of the Fibonnacci array, even if the user asked for Fib?)

Yes, the code's terrible and yes you've used overloading incorrectly, but it's hard for me to see how you were supposed to fill your project spec without using it incorrectly. Your lecturer must be awful if this stuff is what he teaches.

using namespace std;

Don't, ever. std is full of an ever-increasing number of unconstrained template algorithms with generic names. The price of writing std::cout instead of cout is nothing, and the price of having the compiler pick std::distance instead of your own distance will make you cry.

const int SIZE_OF_GENERIC_ARRAY = 100; 
const int SIZE_OF_FIBONACCI_ARRAY = 20;

All upper case names are conventionally reserved for macros. You don't want to know what happens if you clash with a macro. In addition, these are known as "magic buffer sizes"- they're constants with no logic or reason behind them. You should, at the absolute minimum, comment on why these specific sizes were required.

double arithmeticAverage;
char sequenceType;

Do not ever declare mutable variables at namespace scope. They are the worst kind of sin. They're awful, uncontrollable, and an incredible bitch to clean up later.

float Array[SIZE_OF_GENERIC_ARRAY];
int Fibonacci[SIZE_OF_FIBONACCI_ARRAY];

Do not ever use C-style arrays. They are that way for compatibility with B or BCPL, not because their behaviour is good. It isn't. They are tremendously unsafe. You can use std::array<float, size> or std::array<int, size> instead. std::array lives in <array> and acts like a real value type and Standard container.

Also, the whole _tmain thing is totally unnecessary, it's a legacy holdover from 1995 that has no use anymore. Use main unless you know what this stuff actually is. You also don't need that stdafx crap, although it takes a little knowledge to convince Visual Studio to shut up about it.

Now, as you've correctly noticed, your mean and standardDeviation functions are complete duplicates of each other. You can easily re-implement them as one template function for both, but they can also be much more easily defined by using the appropriate Standard algorithms, which live in <algorithm> and <numeric>.

Finally, outputMean and outputStandardDeviation are worthless junk, their logic should just be in main (also, don't they always use the terribly-named Array, instead of the Fibonnacci array, even if the user asked for Fib?)

Yes, the code's terrible and yes you've used overloading incorrectly, but it's hard for me to see how you were supposed to fill your project spec without using it incorrectly. Your lecturer must be awful if this stuff is what he teaches.

using namespace std;

Don't, ever. std is full of an ever-increasing number of unconstrained template algorithms with generic names. The price of writing std::cout instead of cout is nothing, and the price of having the compiler pick std::distance instead of your own distance will make you cry.

const int SIZE_OF_GENERIC_ARRAY = 100; 
const int SIZE_OF_FIBONACCI_ARRAY = 20;

All upper case names are conventionally reserved for macros. You don't want to know what happens if you clash with a macro. In addition, these are known as "magic buffer sizes"- they're constants with no logic or reason behind them. You should, at the absolute minimum, comment on why these specific sizes were required.

double arithmeticAverage;
char sequenceType;

Do not ever declare mutable variables at namespace scope. They are the worst kind of sin. They're awful, uncontrollable, and an incredible bitch to clean up later.

float Array[SIZE_OF_GENERIC_ARRAY];
int Fibonacci[SIZE_OF_FIBONACCI_ARRAY];

Do not ever use C-style arrays. They are that way for compatibility with B or BCPL, not because their behaviour is good. It isn't. They are tremendously unsafe. You can use std::array<float, size> or std::array<int, size> instead. std::array lives in <array> and acts like a real value type and Standard container.

Also, the whole _tmain thing is totally unnecessary, it's a legacy holdover from 1995 that has no use anymore. Use main unless you know what this stuff actually is. You also don't need that stdafx crap, although it takes a little knowledge to convince Visual Studio to shut up about it.

Now, as you've correctly noticed, your mean and standardDeviation functions are complete duplicates w.r.t. float and int versions. You can easily re-implement them as one template function for both, but they can also be much more easily defined by using the appropriate Standard algorithms, which live in <algorithm> and <numeric>.

Finally, outputMean and outputStandardDeviation are worthless junk, their logic should just be in main (also, don't they always use the terribly-named Array, instead of the Fibonnacci array, even if the user asked for Fib?)

Source Link
DeadMG
  • 849
  • 7
  • 12

Yes, the code's terrible and yes you've used overloading incorrectly, but it's hard for me to see how you were supposed to fill your project spec without using it incorrectly. Your lecturer must be awful if this stuff is what he teaches.

using namespace std;

Don't, ever. std is full of an ever-increasing number of unconstrained template algorithms with generic names. The price of writing std::cout instead of cout is nothing, and the price of having the compiler pick std::distance instead of your own distance will make you cry.

const int SIZE_OF_GENERIC_ARRAY = 100; 
const int SIZE_OF_FIBONACCI_ARRAY = 20;

All upper case names are conventionally reserved for macros. You don't want to know what happens if you clash with a macro. In addition, these are known as "magic buffer sizes"- they're constants with no logic or reason behind them. You should, at the absolute minimum, comment on why these specific sizes were required.

double arithmeticAverage;
char sequenceType;

Do not ever declare mutable variables at namespace scope. They are the worst kind of sin. They're awful, uncontrollable, and an incredible bitch to clean up later.

float Array[SIZE_OF_GENERIC_ARRAY];
int Fibonacci[SIZE_OF_FIBONACCI_ARRAY];

Do not ever use C-style arrays. They are that way for compatibility with B or BCPL, not because their behaviour is good. It isn't. They are tremendously unsafe. You can use std::array<float, size> or std::array<int, size> instead. std::array lives in <array> and acts like a real value type and Standard container.

Also, the whole _tmain thing is totally unnecessary, it's a legacy holdover from 1995 that has no use anymore. Use main unless you know what this stuff actually is. You also don't need that stdafx crap, although it takes a little knowledge to convince Visual Studio to shut up about it.

Now, as you've correctly noticed, your mean and standardDeviation functions are complete duplicates of each other. You can easily re-implement them as one template function for both, but they can also be much more easily defined by using the appropriate Standard algorithms, which live in <algorithm> and <numeric>.

Finally, outputMean and outputStandardDeviation are worthless junk, their logic should just be in main (also, don't they always use the terribly-named Array, instead of the Fibonnacci array, even if the user asked for Fib?)