There are plenty of SO questions on weighted random, but all of them rely on the the bias going to the highest number. I want to bias towards the lowest.
My algorithm at the moment, is the randomly weighted with a bias towards the higher values.
double weights[2] = {1,2};
double sum = 0;
for (int i=0;i<2;i++) {
sum += weights[i];
}
d...
Hi,
I'm trying to compile a C++ project (Hello World) in windows 7 using Eclipse Helios. After creating the project the console shows me the next message:
Internal Builder is used for build **
g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\hello.o ..\src\hello.cpp
g++ -ohello.exe src\hello.o
c:/mingw/bin/../lib/gcc/mi...
I wrote a php extension but couldn't find the reason why it reported segmentation fault.
related code:
char *tkey = (char *)emalloc(sizeof(char)*(result_pair[num-1].length+1));
std::memcpy(tkey, (text+i),result_pair[num-1].length);
tkey[result_pair[num-1].length]='\0';
if ...
fstream file;
Patient Obj("XXX",'M',"XXX");
file.open("Patients.dat",ios::in|ios::out|ios::app);
file.seekg(ios::end);
file.write((char*)&Obj,sizeof(Obj));
file.seekg(ios::beg);
Patient x;
file.read((char*)&x,sizeof(x));
x.printallInfo();
file.close();
...
How can I add zlib to an existing installation of Qt. I m pretty new in this so please give me detailed description!
Thanks for your help in advance!
...
http://www.codeproject.com/KB/IP/SocketFileTransfer.aspx?artkw=socket%20send%20a%20file
I don't clearly understand this line :
// get the file's size first
cbLeftToReceive = sizeof( dataLength );
do
{
BYTE* bp = (BYTE*)(&dataLength) + sizeof(dataLength) - cbLeftToReceive;
cbBytesRet = sockClient.Receive( bp, cbLeftToReceive );...
Possible Duplicate:
Difference between a Structure and a Union in C
I could understand what a struct means. But, i am bit confused with the difference between union and struct. Union is like a share of memory. What exactly it means.?
...
One of my pet hates of C-derived languages (as a mathematician) is that
(-1) % 8 // comes out as -1, and not 7
fmodf(-1,8) // fails similarly
What's the best solution?
C++ allows the possibility of templates and operator overloading, but both of these are murky waters for me. examples gratefully received.
...
#include <boost/ptr_container/ptr_vector.hpp>
#include <iostream>
using namespace std;
class Derived
{
public:
int i;
Derived() {cout<<"Constructed Derived"<<endl;}
Derived(int ii):i(ii) {cout<<"Constructed Derived"<<i<<endl;}
~Derived() {cout<<"* Destructed Derived"<<i<<endl;}
};
int main()
{
boost::...
Hi there,
I have a process that continuously needs to write information. Furthermore, there is a second process which sometimes connects to the "information channel" of the writing process and should read the information that are written since it's connected. This process might also deconnect and reconnect several times again.
I am cur...
Hi, i have some vars live:
int foo1;
int foo2;
..
and i want to reach them from:
for (int i = 1;i<=2;i++)
{
// howto get foo1 and foo2?
}
how to get them?
EDIT, end what when it will be no int but a Opject *pointer;?
...
I'm developing a slot machine game. The player insert amount of money and makes a bet to play. And the goal of the game is to obtain as many rows, columns, and diagonals as possible of the same symbol. In the above example, obtained a profit when the upper and lower line have equal symbols, partly 2x lines. Depending on the number of ro...
I wrote this code in C++ as part of a uni task where I need to ensure that there are no duplicates within an array:
// Check for duplicate numbers in user inputted data
int i; // Need to declare i here so that it can be accessed by the 'inner' loop that starts on line 21
for(i = 0;i < 6; i++) { // Check each other number in the ...
Are there any good handwriting API's out there?
A search gives a 1991 project by Sun HRE API.
C/C++ APIs preferred!
...
Hello everyone.
I'm working on my task in computer vision course. One of sub-tasks is gradient direction computation based on image brightness. I've made a matrix bright[width][height] containing brightness values for every pixel of the image. And i have two such functions:
double Image::grad_x(int x,int y){
if(x==width-1 || x==0) ...
In the winAPI, how do I change the window background colour?
For example,
wc.hbrBackground = ....;
is for setting the window background initially, but how do I change it there after?
Thanks.
...
I am developing a game where the user plays a slot machine. The slot machine needs to randomise the 3 different symbols in nine pieces fields, for example the symbols:
A A A
O A O
X X X
I am using a two-dimensional array but I don't know how to randomise the array?
The second problem. I don't know how to compare the symbols in the ...
I am attempting to complete a homework assignment and would like to make an array of data structure and initialise it with names. However, when I try to compile my code I get the following error:
**error C2440: '=' : cannot convert from 'const char [13]' to 'const char'**
I am including my code below. Please advise me what I might be ...
I'm currently seeing a lot of questions which are tagged C++ and are about handling arrays.
There even are questions which ask about methods/features for arrays which a std::vector would provide without any magic.
So I'm wondering why so much developers are chosing arrays over std::vector in C++?
...
This compiles and runs okay, but the results are totally different from what they should be.
I've snipped irrelavent code:
bool grid[1280][1024]; // hardcoded to my screen res for now
for (int x = 0; x<1280; x++) //init grid to false
{
for (int y = 0; y<1024; y++)
{
grid[x][y] = false;
}
}
grid[320][120] = tru...