Click here to Skip to main content
15,920,508 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: My thead application gets hang Pin
Mark Salsbery2-May-07 5:34
Mark Salsbery2-May-07 5:34 
QuestionCan this generate a memory leak? Pin
Joan M30-Apr-07 23:40
professionalJoan M30-Apr-07 23:40 
AnswerRe: Can this generate a memory leak? Pin
Stephen Hewitt1-May-07 1:21
Stephen Hewitt1-May-07 1:21 
GeneralRe: Can this generate a memory leak? Pin
Joan M1-May-07 1:27
professionalJoan M1-May-07 1:27 
AnswerRe: Can this generate a memory leak? Pin
James R. Twine1-May-07 2:29
James R. Twine1-May-07 2:29 
QuestionSplitbars in VC++ Pin
neha.g3030-Apr-07 23:05
neha.g3030-Apr-07 23:05 
QuestionRe: Splitbars in VC++ Pin
Mark Salsbery1-May-07 5:57
Mark Salsbery1-May-07 5:57 
Questionthis code runnig in DOS C++, but don't running borland C++ 6 Pin
oz-gur30-Apr-07 23:01
oz-gur30-Apr-07 23:01 
please help me this code logic
where make I the mistake this code
It is running console wizard in C++ but I trasformation to form enviroment borland C++ 6.0

i hope to your find to my mistake

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
#include "Unit1D.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
#define MAXPOP 25

struct gene {
int alleles[4];
int fitness;
float likelihood;

// Test for equality.
operator==(gene gn) {
for (int i=0;i<4;i++) {
if (gn.alleles[i] != alleles[i]) return false;
}

return true;
}

};
class CDiophantine {
public:
CDiophantine(int, int, int, int, int);
int Solve();
gene GetGene(int i) { return population[i];}

protected:
int ca,cb,cc,cd;
int result;
gene population[MAXPOP];
int Fitness(gene &);
void GenerateLikelihoods();
float MultInv();
int CreateFitnesses();
void CreateNewPopulation();
int GetIndex(float val);

gene Breed(int p1, int p2);

};
CDiophantine::CDiophantine(int a, int b, int c, int d, int res) : ca(a), cb(b), cc(c), cd(d), result(res) {}

int CDiophantine::Solve() {
int fitness = -1;

srand((unsigned)time(NULL));

for(int i=0;i<maxpop;i++) {
="" for="" (int="" j="0;j<4;j++)" population[i].alleles[j]="rand()" %="" (result="" +="" 1);
="" }
="" }

="" if="" (fitness="=" createfitnesses())="" return="" fitness;
="" int="" iterations="0;
" while="" !="0" ||="" <="" 50)="" generatelikelihoods();
="" createnewpopulation();
=""
="" iterations++;
="" -1;
}
int="" cdiophantine::fitness(gene="" &gn)="" float="" total="ca" *="" gn.alleles[0]="" cb="" gn.alleles[1]="" cc="" gn.alleles[2]="" cd="" gn.alleles[3];

="" gn.fitness="abs(total" -="" result);
}

int="" cdiophantine::createfitnesses()="" avgfit="0;
" fitness="0;
" for(int="" i="0;i<MAXPOP;i++)" 0)="" i;
="" 0;
}
="" cdiophantine::multinv()="" sumi="0;
" k="10;
" {

="" k;
="" sumi;
}
void="" cdiophantine::generatelikelihoods()="" multinv="MultInv();

" last="1;
" aktr="1;
" ((1="" (population[i].fitness)="" multinv)="" 100);
="" last+="last;
" }
}
int="" cdiophantine::getindex(float="" val)="" (last="" &&="" val="" else="" 4;
}
gene="" cdiophantine::breed(int="" p1,="" p2)="" crossover="rand()" 3+1;
="" first="rand()" 100;

="" gene="" child="population[p1];

" initial="0," final="3;
" (first="" {="" child.alleles[i]="population[p2].alleles[i];
" (rand()="" 101="" 5)="" child;
}

void="" cdiophantine::createnewpopulation()="" temppop[maxpop];

="" parent1="0," parent2="0," while(parent1="=" population[parent1]="=" population[parent2])="" 101));
="" (++iterations=""> 25) break;
}

temppop[i] = Breed(parent1, parent2); // Create a child.
}

for(int i=0;i<maxpop;i++) population[i]="temppop[i];
}
//---------------------------------------------------------------------------
__fastcall" tform1::tform1(tcomponent*="" owner):="" tform(owner)
{
}
="" ---------------------------------------------------------------------------

void="" __fastcall="" tform1::button1click(tobject="" *sender)
{
int="" solve();
int="" fitness;

edit1-="">Text=StrToInt(fitness);

}
//---------------------------------------------------------------------------


void __fastcall TForm1::Button2Click(TObject *Sender)
{
CDiophantine dp(1,2,3,4,30);
gene gn;
int ans;
ans = dp.Solve();
if (ans == -1) {
//cout << "No solution found." << endl;
} else {
gene gn = dp.GetGene(ans);

Memo1->Text= gn.alleles[0];

}

}
//---------------------------------------------------------------------------
AnswerRe: this code runnig in DOS C++, but don't running borland C++ 6 Pin
toxcct30-Apr-07 23:27
toxcct30-Apr-07 23:27 
QuestionDoes virtual function really influence the performance? Pin
code_discuss30-Apr-07 22:38
code_discuss30-Apr-07 22:38 
AnswerRe: Does virtual function really influence the performance? Pin
Arman S.1-May-07 1:30
Arman S.1-May-07 1:30 
QuestionHow we can make a tooltip for a button Pin
mt_samiei30-Apr-07 21:41
mt_samiei30-Apr-07 21:41 
AnswerRe: How we can make a tooltip for a button Pin
Hamid_RT30-Apr-07 21:47
Hamid_RT30-Apr-07 21:47 
GeneralRe: How we can make a tooltip for a button Pin
mt_samiei30-Apr-07 22:05
mt_samiei30-Apr-07 22:05 
QuestionAVI file to play using Animation control Pin
YUANGE30-Apr-07 20:51
YUANGE30-Apr-07 20:51 
AnswerRe: AVI file to play using Animation control Pin
Hamid_RT30-Apr-07 21:34
Hamid_RT30-Apr-07 21:34 
GeneralRe: AVI file to play using Animation control Pin
YUANGE30-Apr-07 21:52
YUANGE30-Apr-07 21:52 
GeneralRe: AVI file to play using Animation control Pin
Hamid_RT1-May-07 5:29
Hamid_RT1-May-07 5:29 
GeneralRe: AVI file to play using Animation control Pin
Mark Salsbery1-May-07 6:01
Mark Salsbery1-May-07 6:01 
GeneralRe: AVI file to play using Animation control Pin
YUANGE2-May-07 7:02
YUANGE2-May-07 7:02 
GeneralRe: AVI file to play using Animation control Pin
Mark Salsbery2-May-07 9:40
Mark Salsbery2-May-07 9:40 
QuestionDisplay Bitmap By adding resource VC++ 2003 MFC Pin
YUANGE30-Apr-07 20:36
YUANGE30-Apr-07 20:36 
AnswerRe: Display Bitmap By adding resource VC++ 2003 MFC Pin
John R. Shaw30-Apr-07 21:14
John R. Shaw30-Apr-07 21:14 
GeneralRe: Display Bitmap By adding resource VC++ 2003 MFC Pin
YUANGE30-Apr-07 21:27
YUANGE30-Apr-07 21:27 
AnswerRe: Display Bitmap By adding resource VC++ 2003 MFC Pin
Hamid_RT30-Apr-07 21:28
Hamid_RT30-Apr-07 21:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.