Meiosis C++ Program

#include<iostream.h>

#include<stdlib.h>

#include<math.h>

#include<fstream.h>

// function prototype

//function to find a random number (1,2,3,4)

int n_rand();

//function to find a random number (picking 2 from 1,2,3,4)

int n2_rand();

//function to find a random number (1 or 2)

int n3_rand();

//function to check the random numbers in the array to make sure not

// duplicated

void check_random(int[],int&);

// function to check the random numbers 1 or 2 are duplicated

void check_xandy (int&, int&);

//function to search to see if the new chromosome has a clone from a

// previous match

int search_clone (int[], int[],int&);

//

// function to decide if duplicate or original

void duplicate(int[],int&);

ofstream outfile ("times.dat");

ofstream outfile2 ("clone.dat");

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

// main program

void main()

{

// a cell with 4 chromosomes under goes meiosis.

// Chromosomes duplicate.

// the similar ones then pair up ( male with duplicate_male)

// (female with duplicate_female

int male[4];

int female[4];

int i,k;

int key,size;

for (int t=0;t<=50;t++)

{

cout <<" run # "<<t<<endl;

size = 1;

key = 0;

// The doubled pairs separate and move to two opposite sides of the cell

// The first division of meiosis occurs.

while( (size<5000)&&(key!=1))

{

for (i=1;i<5;i++)

{

male[i]= n_rand();

check_random(male,i);

female[i]=n_rand();

check_random(female,i);

}

// the sister chromatids in the two cells separate

// the cell divides

// the four resulting cells thus get one chromosome of each pair--

// one original and duplicate

// this loop and function decides if original or duplicate

for (i=1;i<5;i++)

{

duplicate(male,i);

duplicate(female,i);

}

cout<<"male female"<<endl;

for (i=1;i<5;i++)

{

cout<<male[i]<<" "<<female[i]<<endl;

outfile2<<male[i]<<endl;

}

outfile2<<endl;

for (i=1;i<5;i++)

{

cout<<male[i]<<" "<<female[i]<<endl;

outfile2<<female[i]<<endl;

}

outfile2<<endl;

key=(search_clone(male, female, size));

size =size+1;

}

}

}

//*******************************************************

//function nrand to generate a random integer between 1 and 4 - inclusive

int n_rand()

{

const double a=1.0,b=5.0;

double x;

int y;

x= a+double(rand())*((b-a)/RAND_MAX);

y=int (x);

return(y);

}

//*******************************************************

//*******************************************************

//function n3_rand to generate a random integer

// between 1 and 2 - inclusive

int n3_rand()

{

const double a=1.0,b=3.0;

double x;

int y;

x= a+double(rand())*((b-a)/RAND_MAX);

y=int (x);

return(y);

}

//***********************************************************

// function to check for duplicates

void check_random (int array[], int& count)

{

for (int x = 1;x<count;++x)

{

if (array[count]== array[x])

{

array[count]= n_rand();

check_random(array, count);

}

}

}

//*************************************************************

// function to check for duplicates between 2 numbers

void check_xandy (int& a, int& b)

{

for (int w= 1;w<2;++w)

{

if (a==b)

{

b= n_rand();

check_xandy(a, b);

}

}

}

// function to decide if original or duplicate

// Each of the two new cells receives one member of each original pair

// Each member consists of 2 chromotids

// the value of x and y will be the two pairs of original

// chromtid and their duplicate

// if duplicate, then it will multiply by 100... if original, it will

// remain a one digit number

void duplicate(int array[], int& cc)

{

int x;

x = n3_rand();

if (x==1)

{

array[cc]=array[cc]*100;

}

}

//*************************************************************

//function to search for a duplicated value in an array

//***********************************************************

// function to check for duplicates

int search_clone (int array1[],int array2[], int& count)

{

int found = 0;

for (int x = 1;x<count;x++)

{

if ((array1[count] == array1[x])&&(array2[count]==array2[x]))

{

cout<<"Duplicate found after "<<count<<"chronosomes."<<endl;

outfile<< count<<endl;

found =1;

}

}

return (found);

}