Project logo with cheetah


Appendix B: Code

Main


/*
AiS Challenge 05-06
Team 6
Karalyn Baca
Franklin Orndorff-Plunkett
Punit Shah
*/
//Please note any text following '//' or between '/*' and '*/' is a comment
#include <iostream.h>
#include <stdlib.h>
#include "organism_h.h"
 
 
 
int totalfemale;
int totalmale;
int totalcreatures;
int matingprogram ();
int main ()
{
int initialnumberfemale;
int initialnumbermale;
int total;
cout<< "Prevention of Inbreeding AiS 2005-06"<<endl;
cout<<""<<endl;
 
//females
cout<<"Enter the initial number of females"<<endl;
cin>>initialnumberfemale;
cout<<initialnumberfemale<<" Females"<<endl;
//males
cout<<"Enter the initial number of males"<<endl;
cin>>initialnumbermale;
cout<<initialnumbermale<<" Males"<<endl;
//max number of organisms
cout<<"What is the maximum number of the population you wish to simulate?"<<endl;
cin>>total;
 
 
//arrays to hold males and females
organism arrayfemale [total];
organism arraymale [total];
//genotypes of organisms
int hdomfirst;//homozygous dominant
int hrecfirst;//homozygous recessive
int hetfirst;//heterozygous
int hdomsecond;
int hrecsecond;
int hetsecond;
 
do{
//first trait
cout<<"First trait:"<<endl;
cout<<"How many organisms will be homozygous dominant?"<<endl;
cin>>hdomfirst;
cout<<"How many will be homozygous recessive?"<<endl;
cin>>hrecfirst;
cout<<"How many will be heterozygous?"<<endl;
cin>>hetfirst;
//second trait
cout<<"Second trait:"<<endl;
cout<<"How many organisms will be homozygous dominant?"<<endl;
cin>>hdomsecond;
cout<<"How many will be homozygous recessive?"<<endl;
cin>>hrecsecond;
cout<<"How many will be heterozygous?"<<endl;
cin>>hetsecond;
} while ((hdomfirst+ hrecfirst+hetfirst) !=total)
//note, this checks numbers entered
totalfemale = initialnumberfemale;
totalmale = initialnumbermale;
 
//assigning genotypes
for (int a=0; a++; a>=(hdomfirst/2))
{
for (int b= 0; b++, b>=(hetsecond/2))
{
organism creature(1,1,0,1, 1);//female
totalfemale = totalfemale +1;
arrayfemale[b]= creature;
}
}
 
for (int a=0; a++; a>=(hdomfirst/2))
{
for (int b= 0; b++; b>=(hetsecond/2))
{
organism creature(1,1,0,1,0);//male
totalmale = totalmale +1;
arraymale[b]=creature;
}
}
////////////
for (int a1=0; a1++; a1>=(hrecfirst/2))
{
 
for (int b= 0; b++; b>=(hdomsecond/2))
{
organism creature(1,1,0,1, 1);//female
totalfemale = totalfemale +1;
arrayfemale[(hetsecond/2)+b]=creature;
}
}
 
for (int a=0; a++; a>=(hrecfirst/2))
{
 
for (int b=0; b++; b>=(hdomsecond/2))
{
organism creature(1,1,0,1,0);//male
totalmale = totalmale +1;
arraymale[(hetsecond/2) +b] = creature;
}
}
 
/////////////////
 
for (int a=0;a++; a>=(hetfirst/2))
{
 
for (int b=0; b++; b>=(hrecsecond/2))
{
organism creature(1,1,0,1,1);//female
totalfemale = totalfemale +1;
arrayfemale[(hdomsecond/2)+ (hetsecond/2) +b]= creature;
}
}
 
for (int a2=0; a2++; a2>=(hetfirst/2))
{
 
for (int b=0; b++; b>=(hrecsecond/2))
{
organism creature(1,1,0,1,0);//male
totalmale = totalmale +1;
arraymale[(hdomsecond/2)+ (hetsecond/2) +b]= creature;
}
}
 
 
 
do
{
matingprogram();
}
while (totalcreatures<=total);
 
return 0;
}
 
 
 
//Functions////
///
///
 
int matingprogram ()
{
//mating
//randomly choose a male and female
 
int y;
y = ( rand()% (totalfemale+1));
 
int k;
k = ( rand()% (totalmale+1));
 
//mother= arrayfemale[y]
//father= arraymale[k]
 
int pf;
int qf;
int rf;
int sf;
 
arrayfemale[y].oarray[0]=pf;
arrayfemale[y].oarray[1]=qf;
arrayfemale[y].oarray[2]=rf;
(arrayfemale[y]).oarray[3]=sf;
 
int pm;
int qm;
int rm;
int sm;
 
arraymale[k].oarray[0]=pm;
arraymale[k].oarray[1]=qm;
arraymale[k].oarray[2]=rm;
arraymale[k].oarray[3]=sm;
 
//gender
int q;
q= rand () % 2;//either 0 or 1
//another random number to determine which allele is passed from each parent
// 1 allele from each parent for each characteristic
int a;
a= rand () % 2;//either 0 or 1
 
 
int m,n,o,p;
if (a==0)
{
m=pm;
n=qf;
o=rm;
p=sf;
}
else
{
m=pf;
n=qm;
o=rf;
p=sm;
}
creature.mother = ((arrayfemale[y]).idnumber);
creature.father = ((arraymale[k]).idnumber);
if (q==1)
{
arrayfemale[totalfemale] = (organism creature(m,n,o,p,q));
totalfemale = totalfemale +1;
}
else
{
arraymale[totalmale]= = (organism creature(m,n,o,p,q));
totalmale = totalmale+1;
}
 
int totalcreatures;
totalcreatures = (totalfemale+totalmale);
return 0;
}


Organism. cpp:


#include "organism_h.h"
#include <iostream.h>
#include <stdlib.h>
 
 
organism::organism(int a, int b, int c, int d, int e ) //genotype, last is gender
{
 
idnumber = (idgenerator());
 
//organism's array, contains alleles
 
oarray[0] = a;
oarray[1] = b;
oarray[2]= c;
oarray[3] = d;
 
gender= e;
 
}
 
 
long organism::idgenerator()
{
int id;
id= (10+ rand() %4000);
 
//need to check to ensure id number is unique
 
// if it isn't, assign new number
 
for (int a= 0; a++; a>=(totalmale))
if (id==arraymale[a].idnumber)
{
id = (20+ rand()% 5032);
}
for (int b = 0; b++; b>=(totalfemale))
if (id ==arrayfemale[b].idnumber)
id = (15 + rand()% 3033);
}
 
return id;
}


organism.h:


#ifndef ORGANISM_H
#define ORGANISM_H
 
class organism
{
public: //functions
 
organism(int, int, int, int, int);
long idgenerator();//generates random id number
 
int oarray[4]; //contains alleles, 0 is recessive, 1 is dominant
//first two are for first trait, second two for second
int gender; // 0 is male, 1 is female
 
long idnumber;
long mother;//id number of each parent
long father;
 
 
};
#endif

← Previous | Next →


Contact Us | Albuquerque Academy | New Mexico Supercomputing Challenge
Site Design © 2006 Punit Shah
Project © 2006 Punit Shah, Franklin Orndorff-Plunkett, and Karalyn Baca
Google logo trademark of Google Inc.
Valid XHTML 1.0 Transitional Valid CSS!