I had to look up Punnett on the web.
and found it. Your software is an interesting problem so I played around with the idea a little.
You have a nice beginning but it's not very general and would be hard to modify.
One thing I always try and keep in mind is make it general and make it expandable. I've included a short program that would be easy to improve. It's currently hard-coded for a 4x4 dihybrid cross. Easy modification would be to make a generalized input. Do other types of cross than dihybrid. Make the structures classes. Create an output class for printing.... the list goes on. However, it's just a start and a simple demo... thanks for the problem I hope you find this program helpfull
take care and happy computing.
it's a win32 program comprised of three files doPair.h , doPair.cpp and punn.cpp
Code:
//include file doPair.h
typedef struct {
int mixed;
int recessive;
int dominant;
int homogeneous;
}stats;
typedef struct {
char g1[5];
}gene;
class doPair
{
public:
doPair(char*, char*, char*, stats*);
virtual ~doPair(void);
};
//class doPair.cpp
#include "StdAfx.h"
#include ".\dopair.h"
#define ISLOWER(x) ((x >='a' && x<='z') ? 1 : 0)
#define ISUPPER(x) ((x >='A' && x<='Z') ? 1 : 0)
/*
Pair member function
takes advantage of the pairing of the genes
makes some simple calculation and saves in a status struct
indexed by the gene index
*/
doPair::doPair(char* g1, char* g2, char* r1, stats* s1)
{
int i;
char temp;
char* rs = r1;
*r1++ = *g2++;
*r1++ = *g1++;
*r1++ = *g2;
*r1++ = *g1;
*r1 = 0;
//correct for caps in front
//do some simple summing... just place holders to demo the idea
//
for(i=0;i<2;i++)
{
if( rs[i] != rs[i+1] && rs[i] > rs[i+1])
{//mixed
temp = rs[i];
rs[i] = rs[i+1];
rs[i+1] = temp;
s1->mixed++;
}
else if(rs[i] == rs[i+1])
{
s1->homogeneous++; //homogen
if( ISLOWER(rs[i]) )
{
s1->recessive++; //recessive
}
else
{
s1->dominant++; //dom
}
}
}
}
doPair::~doPair(void)
{
}
//main function *********************************8
// punn.cpp : Punnett Square
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include "doPair.h"
using namespace std;
//globals
gene Gamates[16];
stats geneInfo[16];
int _tmain(int argc, _TCHAR* argv[])
{
int i,j;
char gene1[] = "RYRyrYry";
char gene2[] = "RYRyrYry";
char *g1 = gene1;
char *g2 = gene2;
char* r1;
stats* s1;
//generate the 16 groups
for(i=0; i<16; )
{
for(j=0; j<4; j++) //number of gene groups
{
s1 = &geneInfo[i];
r1 = &Gamates[i].g1[0];
::doPair( g1, g2, r1, s1);
g2++;
g2++;
i++;
}
g2 = gene2;
g1++;
g1++;
}
//do output
for(i=0;i<16;i++)
{
s1 = &geneInfo[i];
r1 = &Gamates[i].g1[0];
cout << r1;
cout << " info: ";
cout << " mixed: ";
cout << s1->mixed;
cout << " recessive: ";
cout << s1->recessive;
cout << " dominant: ";
cout << s1->dominant;
cout << " homogeneous: ";
cout << s1->homogeneous;
cout << "\n";
}
return 0;
}