|
You mean array of integers?
Then, int a[3][4];
|
|
|
|
|
how to create random real number matrix 3x4?thanks
Li Zhiyuan
5/10/2006
|
|
|
|
|
li zhiyuan wrote: random real number matrix
I didnt get you...
You mean elements as real numbers?
If so float a[3][4];
And for getting random numebrs you can use rand(). But it is returning integer values. So you have to convert it to real. For example,
float f = ( rand() % 1000 ) / 1000;
|
|
|
|
|
NS17 wrote: float f = ( rand() % 1000 ) / 1000; // random number between 0 and 1
the above always evaluates to
float f = 0;
Moreover, the best way to produce statistically meaningful random values inside a range is (see http://msdn2.microsoft.com/en-us/library/398ax69y.aspx[^])
int u = (double)rand() / (RAND_MAX + 1) * (range_max - range_min) + range_min;
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
CPallini wrote: the above always evaluates to
float f = 0;
Yes. I forgot about the casting...
It has to be
float f = ( rand() % 1000 ) / 1000.0;
|
|
|
|
|
for instance:
const double MIN_RANGE = 3.0;
const double MAX_RANGE = 1200.0;
int i,j;
double m[3][4];
for (i=0; i<3; i++)
{
for (j=0; j<4; j++)
{
m[i][j] = (double)rand() / (RAND_MAX + 1) * (MAX_RANGE - MIN_RANGE) + MIN_RANGE;
}
}
see MSDN http://msdn2.microsoft.com/en-us/library/398ax69y.aspx[^]
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
CPallini wrote: m[i][j] = (double)rand() / (RAND_MAX + 1) * (MAX_RANGE - MIN_RANGE) + MIN_RANGE;
why (RAND_MAX + 1) is needed?
|
|
|
|
|
const double MIN_RANGE = 3.0;
const double MAX_RANGE = 1200.0;
// change the range to fit your needs, of course keep MAX_RANGE > MIN_RANGE
int i,j;
double m[3][4];
for (i=0; i<3; i++)
{ for (j=0; j<4; j++)
{ m[i][j] = (double)rand() / (RAND_MAX + 1) * (MAX_RANGE - MIN_RANGE) + MIN_RANGE;
}
}
however i couldn't get m=3x4 matrix yet, please can give me detail..i did in IDE.
the reslut is 0013fecc..
thanks a lot
Li Zhiyuan
3/1/2008
|
|
|
|
|
Hi,
I am mainframe programmer as such its been really difficult to make the transition to OO way of thinking anyway....
I have a table or a structure which I would like to make dynamic
meaning I can add an entry to it and just re-compile and re-build it
IS DLL export/import they way to go meaning when I define the structure add dllexport to the defination
and make the structure a DLL and get the address of the table with GetProcAddress
Thankx
|
|
|
|
|
1. Lets say I have a MFC SDI with a dialog containing 5 edit boxes.
2. I want to left click on any of the five edits and generate "Hello" in it.
3. I have reached the point where I can click anywhere on the dialog and generate "Hello" into one single edit box.
4. I haven't figured out how to determine if the click is in one of the edit boxes rather than anywhere in the dialog.
5. Then I need to know which edit box.
So, I need advice on #4 and #5. Here is what I have:
CTest.h
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
CTest.cpp
BEGIN_MESSAGE_MAP(CTest, CDialog)<br />
ON_WM_LBUTTONDOWN()<br />
END_MESSAGE_MAP()<br />
...<br />
void CTest::OnLButtonDown(UINT nFlags, CPoint point) <br />
{ <br />
CDialog::OnLButtonDown(nFlags, point);
GetDlgItem(IDC_EDIT_C1L1)->SetWindowText("Hello");
}
Thanks
modified on Tuesday, January 01, 2008 7:07:59 PM
|
|
|
|
|
Try as follows...
BOOL CTestDlg::PreTranslateMessage(MSG* pMsg)
{
if( pMsg->message == WM_LBUTTONDOWN )
{
if(( pMsg->hwnd == GetDlgItem( IDC_EDIT1 )->m_hWnd ) ||
( pMsg->hwnd == GetDlgItem( IDC_EDIT2 )->m_hWnd ))
{
::SetWindowText( pMsg->hwnd, "Hello" );
}
}
return CDialog::PreTranslateMessage(pMsg);
}
|
|
|
|
|
When you click on an edit control, the message goes to the
edit control window, not to the dialog window.
You could derive a class from CEdit and use that class to
subclass the edit controls. When your CEdit-derived class gets a
WM_LBUTTONDOWN message, it could notify its parent by posting an
app-specific message.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi all
please how i can convert integer number to string text like this
(i entered 7 in keyboard and the output will be seven)
thank's for all
-*-*-*-*-*-*-*-*-*
To Be Or Not To Be
(KARFER)
-*-*-*-*-*-*-*-*-*
|
|
|
|
|
you may use the function sprintf function, for instance
int i;
char buffer[20];
i=7;
sprintf(buffer,"%d", i);
or, if you prefer the CString class
int i;
CString str;
i=7;
str.Format("%d", i);
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
O.K
Thank's For all
I'll Be There
|
|
|
|
|
CP holds some articles on number-to-text conversion.
|
|
|
|
|
|
If I understood you well, you are asking how to get the name of the number, not the number itself inside a string.
So you are not asking for:
int iNumberSeven = 7;<br />
CString csAux = "";<br />
csAux.Format("%i",iNumberSeven);
you are asking for something like:
if (iNumberSeven == 7)<br />
{<br />
csAux = "seven";<br />
}
If you meant the second option, the only way I can think of is to try to generate the numbers programmatically. And this would mean to study the way the numbers are formed and of course having some basic strings in a vault in order to be able to use them.
|
|
|
|
|
Thank's For all
Never put off till tomorrow what can be done today
|
|
|
|
|
I am trying, with no luck, to get a simple windows application to have XP/Vista style buttons. I am running Vista and vc2005.
I go into vc2005 and create a new Win32 application and have it auto generate the basic code. I compile it and select the "About Box" and the "OK" button in in the old win2000 style.
I followed the direction in this link:
http://codeproject.com/script/Forums/View.aspx?fid=1647&msg=2355190
and I get errors when it links.
What gives? How do I get an application that has the new button styles? Why is this so hard? What is Microsoft thinking here?
Can anyone help?
Tankko
|
|
|
|
|
Is this a UNICODE application? If not, check your stdafx.h file - for some warped reason known only to Microsoft, the inclusion of the manifest in the generated stdafx.h has an #ifdef UNICODE around it. I've always had to only remove the #ifdef from that file (and no other changes) to get the XP style controls.
Judy
|
|
|
|
|
In OnMouseLeave method which is invoked when the WM_MOUSELEAVE message arrives I would like to determine the mouse button states too. Any idea how to do this? Do we have something like GetAsyncKeyState method which is for keyboard state?
Thanks,
Abyss
|
|
|
|
|
Abyss wrote: In OnMouseLeave method
Wrong forum?
Abyss wrote: WM_MOUSELEAVE ?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
I'm not sure why do you think this is in wrong forum. It is a windows message (WINAPI) and used in C++ code. My application uses MFC to route this message.
Which forum do you recommend for this question?
|
|
|
|
|
Sure? I cannot find any reference to WM_MOUSELEAVE on MSDN and OnMouseLeave is typically a method of .NET Framework controls.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
modified on Tuesday, January 01, 2008 11:13:41 AM
|
|
|
|