can any one give an example of a programm usess output from a file to find maximum, minimum, average and variance?
i really cant find a solution for it.
The question is
Write a program that uses a function template called min, max, ave and var to determine the minimum, maximum, average and variance of the numbers as shown as below:
24
101
1001
55
69
25
14
23
75
885
3548
5
4
65
69
99
You must use the external input file as the input in your program in order to calculate the output of minimum, maximum, average and variance of these given numbers.
Since all the return types are primitives, we can use specifics and let casting do its job.
The example I gave assumes you are using some collective data structure. If you want, you can iterate through the list of items and process them two at a time.
1 2 3 4 5 6 7 8
template <class T> //class or typename shouldn't really matter.
T max(const T t1, const T t2)
{
return ((t1 > t2) ? t1 : t2);
}
//Follow the same pattern for the rest
Ok after reading your last reply after my previous post, it seems to me that you are somewhere at entry level.
If you are, then I do not think you should be solving the problem. Unless of course your goal is to make a program that behaves the same as what the problem states.
If this is not something required of you to be done, then just ignore all the generics examples I posted, continue on with what you have. If this is for school work or something of the sort, then you need a lot of catching up to do.
haha, thats right. is assignment. i am too lazy before this and we are use to spoon feed by our lectural.
so maybe after this have too work harder la. i just found the template file in the tutorial of cplusplus.com
so maybe i will take a look in it.
Thanks anyway.