Array/List?
-
- I'm sorry, but I know this is a real newbie-question: how do I make an array for for instance UINT's or doubles, or CButtons? 2) Is there a possibility to determine (fast!) what the highest or lowest value in an UINT- or doubles-array or list is? I need this, because I've planned to make 1) my very own CHistogramCtrl 2) a (useless) dialog, containing one button, that devides itself into 4 new ones after clicking on it (and so on: click on one of the new buttons and it will start over again).
-
- I'm sorry, but I know this is a real newbie-question: how do I make an array for for instance UINT's or doubles, or CButtons? 2) Is there a possibility to determine (fast!) what the highest or lowest value in an UINT- or doubles-array or list is? I need this, because I've planned to make 1) my very own CHistogramCtrl 2) a (useless) dialog, containing one button, that devides itself into 4 new ones after clicking on it (and so on: click on one of the new buttons and it will start over again).
DaFrawg wrote: how do I make an array for for instance UINT's or doubles, or CButtons?
UINT uArray[5]; double dArray[10]; CButton btnArray[3];
DaFrawg wrote: 2) Is there a possibility to determine (fast!) what the highest or lowest value in an UINT- or doubles-array or list is? The lowest value is always going to be zero. The highest value is always going to be the number of elements minus 1;int nCount = (sizeof(uArray) / sizeof(UINT)) - 1;
Since you are using MFC, you might want to look at theCArray
-related classes. -
DaFrawg wrote: how do I make an array for for instance UINT's or doubles, or CButtons?
UINT uArray[5]; double dArray[10]; CButton btnArray[3];
DaFrawg wrote: 2) Is there a possibility to determine (fast!) what the highest or lowest value in an UINT- or doubles-array or list is? The lowest value is always going to be zero. The highest value is always going to be the number of elements minus 1;int nCount = (sizeof(uArray) / sizeof(UINT)) - 1;
Since you are using MFC, you might want to look at theCArray
-related classes.DavidCrow wrote: The lowest value is always going to be zero. The highest value is always going to be the number of elements minus 1 Doesn't he mean the element with the largest value? Kevin
-
DavidCrow wrote: The lowest value is always going to be zero. The highest value is always going to be the number of elements minus 1 Doesn't he mean the element with the largest value? Kevin
I'm not real sure. Even though the word 'value' was used, I took it with a grain of salt. Folks' use of words in these forums vary so much, it's hard to assume anything.
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
-
- I'm sorry, but I know this is a real newbie-question: how do I make an array for for instance UINT's or doubles, or CButtons? 2) Is there a possibility to determine (fast!) what the highest or lowest value in an UINT- or doubles-array or list is? I need this, because I've planned to make 1) my very own CHistogramCtrl 2) a (useless) dialog, containing one button, that devides itself into 4 new ones after clicking on it (and so on: click on one of the new buttons and it will start over again).
How much of a beginner are you? Are you a beginner of VC++/MFC only or are you also fairly new to C++? Apart from David's answer below you could also try using the vector class with the max_element algorithm. If you type "max_element" in the Help index and click on the Sample program link there is an example showing how to use it. It is also possible to use max_element on a raw array, if you find that easier to get your head round.
double histogram[] = { 1, 4, 4, 6, 1, 2, 2, 3, 1, 6, 6, 6, 5, 7, 5, 4, 4 }; int count = sizeof(histogram) / sizeof(histogram[0]); double* begin = histogram; double* end = histogram + count; double* maximum = max_element(begin, end); afxDump << "Maximum = " << *maximum << "\n"; // or use TRACE
You should also "include " Kevin -
How much of a beginner are you? Are you a beginner of VC++/MFC only or are you also fairly new to C++? Apart from David's answer below you could also try using the vector class with the max_element algorithm. If you type "max_element" in the Help index and click on the Sample program link there is an example showing how to use it. It is also possible to use max_element on a raw array, if you find that easier to get your head round.
double histogram[] = { 1, 4, 4, 6, 1, 2, 2, 3, 1, 6, 6, 6, 5, 7, 5, 4, 4 }; int count = sizeof(histogram) / sizeof(histogram[0]); double* begin = histogram; double* end = histogram + count; double* maximum = max_element(begin, end); afxDump << "Maximum = " << *maximum << "\n"; // or use TRACE
You should also "include " Kevin#include Kevin
-
How much of a beginner are you? Are you a beginner of VC++/MFC only or are you also fairly new to C++? Apart from David's answer below you could also try using the vector class with the max_element algorithm. If you type "max_element" in the Help index and click on the Sample program link there is an example showing how to use it. It is also possible to use max_element on a raw array, if you find that easier to get your head round.
double histogram[] = { 1, 4, 4, 6, 1, 2, 2, 3, 1, 6, 6, 6, 5, 7, 5, 4, 4 }; int count = sizeof(histogram) / sizeof(histogram[0]); double* begin = histogram; double* end = histogram + count; double* maximum = max_element(begin, end); afxDump << "Maximum = " << *maximum << "\n"; // or use TRACE
You should also "include " KevinI'm a beginner of VC++/MFC, but I still don't get some C++ basics, like working with 'friend' and 'operator' and arrays, especially when they're declared to be a class member (this isn't good English, is it?). But if I understand it well, max_element is a macro (or function, whatever) in <algorithm.h>. Is that correct? If it is, it'd really help me.