Click here to Skip to main content
15,901,035 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: An easy one for you pro's... Pin
Christian Graus5-Dec-02 6:35
protectorChristian Graus5-Dec-02 6:35 
GeneralRe: An easy one for you pro's... Pin
Nick Parker5-Dec-02 1:44
protectorNick Parker5-Dec-02 1:44 
GeneralRe: An easy one for you pro's... Pin
Christian Graus5-Dec-02 6:37
protectorChristian Graus5-Dec-02 6:37 
GeneralRe: An easy one for you pro's... Pin
Nick Parker5-Dec-02 6:42
protectorNick Parker5-Dec-02 6:42 
GeneralRe: An easy one for you pro's... Pin
Tim Smith5-Dec-02 2:19
Tim Smith5-Dec-02 2:19 
GeneralRe: An easy one for you pro's... Pin
Brent Lamborn5-Dec-02 5:05
Brent Lamborn5-Dec-02 5:05 
GeneralRe: An easy one for you pro's... Pin
Christian Graus5-Dec-02 6:38
protectorChristian Graus5-Dec-02 6:38 
GeneralRe: An easy one for you pro's... Pin
Brent Lamborn5-Dec-02 7:16
Brent Lamborn5-Dec-02 7:16 
Damn ..I still can't get it to compile.. If you can tell me what the heck I'm doing wrong I'll buy you lunch..Here's part of what's in main..

const int iColSize = 20;

//Seed rand function
srand((unsigned)time(NULL));

int iNumChroms;

cout << "Artificial Life Simulator 1.0\n\n"
<< "Enter the number of pairs of chromosomes in each organism: ";

cin >> iNumChroms;

for(int i = 0; i < iColSize; i++)
Organism aOrgArray[i] = {new Organism (iNumChroms)};

And this is my Organism class definition:

#ifndef ORGANISM_H
#define ORGANISM_H

class Organism {
friend class Chromosomes;
public:
//Constructor: iChromo is number of chromosome pairs
Organism(int iChromo = 1);
~Organism();
//Calc fitness value of single organism called on
void calcFitVal();
//Prints fitness value of single organism called on
void printFitVal() const;
//Mutate a random chromosome
void mutate();
private:
//Fitness value of each organism
int iFitVal;
//Number of pairs of chromosomes in each organism
const int iNumOfChromoPairs;
//Pointer to array of Chromosomes (chromosome pairs)
Chromosomes* pChromoArray;
};

#endif

And if this helps here are the member functions:


// File: Organism.cpp
// Defines member functions of class Organism

#include <iostream>
#include "Organism.h"
#include "Chromosomes.h"

using std::cout;
using std::endl;

Organism::Organism (int iChromo) : iNumOfChromoPairs (iChromo)
{

//Declare array of chromosome for each organism
pChromoArray = new Chromosomes[iNumOfChromoPairs];
}

Organism::~Organism()
{
//Release memory to the O.S.
delete [] pChromoArray;
}

void Organism::calcFitVal()
{
//Set fitness value to 0 on organism called
iFitVal = 0;

//Loop counts number of true chromosomes in each organism
for(int i = 0; i < iNumOfChromoPairs; ++i) {

if(pChromoArray->bChrom0 == true)
++iFitVal;

if(pChromoArray->bChrom1 == true)
++iFitVal;

++pChromoArray;
}

//Move pointer back to the beginning of the array
for (; i != 0; --i)
--pChromoArray;

}

void Organism::printFitVal() const
{
//Print fitness value for each organism
cout << iFitVal << endl;
}


void Organism::mutate()
{
//Pick a random pair of chromosomes in the organism
int iRanPair = rand() % iNumOfChromoPairs;

//Pick a random chromosome in that pair and mutate it
if(rand() % 2 == 0){
if(pChromoArray[iRanPair].bChrom0 == true)
pChromoArray[iRanPair].bChrom0 = false;
else
pChromoArray[iRanPair].bChrom0 = true;
}


else {
if(pChromoArray[iRanPair].bChrom1 == true)
pChromoArray[iRanPair].bChrom1 = false;
else
pChromoArray[iRanPair].bChrom1 = true;
}
}
GeneralRe: An easy one for you pro's... Pin
Christian Graus5-Dec-02 7:30
protectorChristian Graus5-Dec-02 7:30 
GeneralRe: An easy one for you pro's... Pin
Brent Lamborn5-Dec-02 9:30
Brent Lamborn5-Dec-02 9:30 
GeneralRe: An easy one for you pro's... Pin
Christian Graus5-Dec-02 9:39
protectorChristian Graus5-Dec-02 9:39 
GeneralHelp with an Array of Controls and message maps Pin
VanHlebar4-Dec-02 13:47
VanHlebar4-Dec-02 13:47 
GeneralRe: Help with an Array of Controls and message maps Pin
Roger Allen5-Dec-02 1:27
Roger Allen5-Dec-02 1:27 
GeneralRe: Help with an Array of Controls and message maps Pin
VanHlebar5-Dec-02 1:48
VanHlebar5-Dec-02 1:48 
GeneralRe: Help with an Array of Controls and message maps Pin
Roger Allen5-Dec-02 3:13
Roger Allen5-Dec-02 3:13 
GeneralRe: Help with an Array of Controls and message maps Pin
VanHlebar5-Dec-02 11:07
VanHlebar5-Dec-02 11:07 
GeneralChanging the toolbar Pin
Rand Al'thor4-Dec-02 12:40
Rand Al'thor4-Dec-02 12:40 
GeneralRe: Changing the toolbar Pin
Rand Al'thor4-Dec-02 15:23
Rand Al'thor4-Dec-02 15:23 
GeneralAdd grid control to a dialog Pin
peter ho4-Dec-02 12:35
peter ho4-Dec-02 12:35 
GeneralRe: Add grid control to a dialog Pin
Christian Graus4-Dec-02 15:29
protectorChristian Graus4-Dec-02 15:29 
GeneralRe: Add grid control to a dialog Pin
Kannan Kalyanaraman4-Dec-02 19:18
Kannan Kalyanaraman4-Dec-02 19:18 
GeneralDisabled Pin
Larsson4-Dec-02 12:29
Larsson4-Dec-02 12:29 
GeneralRe: Disabled Pin
tongc4-Dec-02 14:34
tongc4-Dec-02 14:34 
GeneralRe: Disabled Pin
Larsson5-Dec-02 4:03
Larsson5-Dec-02 4:03 
QuestionUtility to scan for unused headers? Pin
Andrew Welch4-Dec-02 12:22
Andrew Welch4-Dec-02 12:22 

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.