|
Hi everybody,
My question is how to convert this c++ code to javascript or html that can generate the result random number?
#include <cstdlib>
#include <ctime>
#include <iostream>
using std::cout;
int main( ) {
srand( ( unsigned )time( 0 ) );
int randomKey = rand() % 4013;
cout << "Your random key is: " << ( 10016486 + ( randomKey * 22423 ) ) << "\n";
system( "PAUSE" );
return 0;
}
Thanks for any help
|
|
|
|
|
Googling "javascript random" yields this[^] as the first result...
|
|
|
|
|
Hi,
i have developed COM componet,its a custom Component,it supports ConnectionPoints,the Conntection interface is dervied from IUnknown.In the Client Side i have imported tlb file,I have wrote class CSink:_ISampleEvents
CSink psink;
psink = new CSink;
the following error is occuring
error C2259: : cannot instantiate abstract class
why..? how to avoid it,what could be the reason?
Thanks in before
james
|
|
|
|
|
CSink psink; //should be CSink* psink?
you'd better check the class CSink and make sure that
the CSink impliment all the virtual functions whose it's drivied from
hi
|
|
|
|
|
An abstract class is one that has one or more pure virtual functions defined. The intent is that you derive from that class and provide actual implementations for each of these functions. You can't instantiate a class that has a pure virtual function defined (since if you called it, the computer wouldn't knnow what to do) so the error message you're getting indicates that you've missed (at least) one.
0 bottles of beer on the wall, 0 bottles of beer, you take 1 down, pass it around, 4294967295 bottles of beer on the wall.
Awasu 2.2.2 [^]: A free RSS/Atom feed reader with support for Code Project.
|
|
|
|
|
yeah i have overridden all the pure virtual function`s in the derived class,and wrote their implementation,even then i am getting error..
|
|
|
|
|
You have to check all the way up the hierarchy. Maybe you're deriving from a class that is derived from a class that is derived from a class that still has a pure virtual function
The error message is definitely caused by this (although vecodo_doon's comment may well be the cause as well).
0 bottles of beer on the wall, 0 bottles of beer, you take 1 down, pass it around, 4294967295 bottles of beer on the wall.
Awasu 2.2.2 [^]: A free RSS/Atom feed reader with support for Code Project.
|
|
|
|
|
Have you implemented all of IUnknown 's methods?
If you're using ATL's support by deriving from CComObjectRoot(Ex), the class you declare is not complete - it still has some abstract methods. You have to make use of the CComObject family of templates (CComObject, CComAggObject, CComPolyObject, CComObjectStack) to actually create an instance. The ATL implementation of the class factory does this for you, depending on which DECLARE_AGGREGATABLE macro you used.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
if i want to get connected with server what r the minimum requirment.Other then port number what should i need.From where to start....
|
|
|
|
|
This is such an open-ended question it's hard to know what to do with it. What protocol do you want to use? What sort of server?
The only link I can give you is the Winsock Programmer's FAQ[^], which might help a little.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
|
You can connect to a remote machine (e.g., server) with a UNC path. Since you give no supporting information, a more detailed answer is not possible.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hello,
I have a problem with more than one graph creation.
I added an element:
<br />
m_Graph.AddElement();<br />
than I wrote this line
<br />
m_Graph.PlotXY( i , pointsArray[i] ,arrIndex);<br />
the arrIndex=1
But it says that the element not found!
Here is a link to the article:
http://www.codeproject.com/miscctrl/ntgraph_activex.asp[^]
SnaidiS(Semion)
-- modified at 6:46 Sunday 16th July, 2006
|
|
|
|
|
please, I need some help
SnaidiS(Semion)
|
|
|
|
|
why nobody helps me?
SnaidiS(Semion)
|
|
|
|
|
Hi,
I've got a BITMAP object that i want to save on the disc.
Does anybody know how it can be done?
Cheers in advance.
|
|
|
|
|
if you have a bitmap handle you can Attach this handle to CImage class and use from Save
whitesky
|
|
|
|
|
A versatile approach for images would be to use the GDI+ Image class (or it's derived types Bitmap, Metafile) for all your imaging needs.
Image::Save will save bitmaps to IStream or file.
|
|
|
|
|
|
See the example here and here.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi everybody!
I'm making a routing algo simulator using MFC and GDI+.
I have created three function that are the three steps the algo does: ElectCluster(); FindMember(); StartSteadyState();.
Now the StartSteadyState() creates a thread for each node of the network that has been elected Cluster head (p->ch).
<br />
void CSimDlg::StartSteadyState(void)<br />
[...].br />
for (int i=0; i<m_vecNodes.size(); i++)<br />
{<br />
NODE* p = m_vecNodes[i];<br />
<br />
if(p->ch)<br />
{<br />
ThreadParam* pParam = new ThreadParam;<br />
pParam->m_pDialog = this;<br />
pParam->m_nNodeIndex = i;<br />
_beginthread(StaticTx, 0, (void*)pParam);<br />
counter++;<br />
}<br />
}<br />
[...].
and:
void CSimDlg::StaticTx(void * param)<br />
{<br />
ThreadParam* pParam = (ThreadParam*)param;<br />
pParam->m_pDialog->Tx(pParam->m_nNodeIndex);<br />
delete pParam;<br />
}<br />
<br />
void CSimDlg::Tx(int nNodeIndex)<br />
{<br />
[simulate transmission]<br />
[graphic: draw nodes and color lines of the link used]<br />
}
Now my problem is that I would like to make different rounds:
<br />
void CSimDlg::OnBnClickedStart()<br />
{<br />
for(int i=0; i < NumberOfRounds; i++)<br />
{<br />
ElectCluster();<br />
FindMember();<br />
StartSteadyState();<br />
}<br />
}
This obviosly doesn't work because "for" doesn't wait for all the thread created by StartSteadyState();
I have tried to solve using:
<br />
hThread = (HANDLE)_beginthread(StaticTx, 0, (void*)pParam);<br />
WaitForSingleObject(hThread,INFINITE);<br />
It seems to work but doesn't shows the graphic. I have tried to put a MessageBox before WaitForSingleObject and for as long as I don't press the ok button I see that the links and nodes are coloring. pressing ok the graphic part stops.
What am I doing wrong?
Do you have any advices or suggestion?
modified 11-Mar-21 21:01pm.
|
|
|
|
|
The general solution is following:
1. Create thread with attribute "normal" and then suspend it (somehow the creation in suspendedstate does not work well.
2. activate thread when needed.
Serge Chychkan
|
|
|
|
|
First of all thankyou for your fast reply.
Hum... you mean create a thread for each cluster head and suspend it, than resume all at the same time after the for(... if(p->ch) ) ?
I have tryed using SuspendThread(hThread); and ResumeThread(hThread); .. the thread works but the graphic part is not shown again.
modified 11-Mar-21 21:01pm.
|
|
|
|
|
blpdone wrote: hThread = (HANDLE)_beginthread(StaticTx, 0, (void*)pParam);
WaitForSingleObject(hThread,INFINITE);
This is a very expensive way of making a function call. You are practically just making a call to StaticTx(0, (void*) pParam) since your function won't return until the StaticTx function has returned. This is definately incorrect. You should never block the main GUI thread as it is needed to handle window messages to the application.
I'm not sure why you need a thread for each node, and I hope that you are drawing only in response to WM_PAINT or have a good reason for not doing so.
|
|
|
|
|
Thankyou for your reply.
what do you suggest to do instead?
I have made a thread for each Cluster Head [CH] node because they have to make the same action at the same time. The Tx(int nNodeIndex) function is used by all CH node to activate, one at the time, the node that has to trasmit (coloring the link, redrawing all the nodes on the IDC_PLOT control). The same thing is done by all the CH at the same time managing all the nodes each CH has under its control.
Everythig seems to work fine for one round but if I increase it I have to "tell" the function to wait all the thread of the StartSteadyState(void) to end before restarting everything with the ElectCluster(void) .
Any advice on how to solve it? Or some ideas on other ways to do the same thing?
Thankyou Again
modified 11-Mar-21 21:01pm.
|
|
|
|