Code:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
/***************************************************/
/* CLASSES */
/***************************************************/
/***************************************************/
/* class gene */
/***************************************************/
class gene
{
public:
gene(){name = ""; identifier = 0;};
void setgene(string genename, int geneidentifier)
{name = genename; identifier = geneidentifier;};
string getgenename(){return name;};
int getgeneidentifier(){return identifier;};
void printgene(void){cout << "\t" << name << endl;};
~gene(){};
private:
string name;
int identifier;
};
/***************************************************/
/* class condition */
/***************************************************/
class condition
{
public:
condition(){name = ""; identifier = 0;};
void setcondition(string conditionname, int conditionidentifier)
{name = conditionname; identifier = conditionidentifier;};
string getconditionname(){return name;};
int getconditionidentifier(){return identifier;};
void printcondition(void){cout << "\t" << name << endl;};
~condition(){};
private:
string name;
int identifier;
};
/***************************************************/
/* class cell */
/***************************************************/
class cell
{
public:
cell(){name = ""; identifier = 0;};
void setcell(string cellname, int cellidentifier)
{name = cellname; identifier = cellidentifier;};
string getstringname(){return name;};
int getstringidentifier(){return identifier;};
void printcell(void){cout << "\t" << name << endl;};
~cell(){};
private:
string name;
int identifier;
};
/***************************************************/
/* class gene expression */
/***************************************************/
class geneexp
{
public:
geneexp(){temporal = 0; spacial = 0; row = 0; col = 0;};
void setnumberofgenes(int);
void setnumberofconditions(int);
void setnumberofcells(int);
void setgenes(string genename, int i)
{genes[i].setgene(genename, i + 1);};
void setconditions(string conditionname, int i)
{conditions[i].setcondition(conditionname, i + 1);};
void setcells(string cellname, int i)
{cells[i].setcell(cellname, i + 1);};
void settemporal(void){temporal = 1;};
void setspacial(void){spacial = 1;};
void setmatrix(double**);
int getrow(void){return row;};
int getcol(void){return col;};
void removegene(int);
void printmatrix(void);
void printgenes(void);
void printconditions(void);
void printcells(void);
~geneexp(){};
private:
int temporal;
int spacial;
gene *genes;
condition *conditions;
cell *cells;
int row;
int col;
double **element;
};
/***************************************************/
/* END OF CLASSES */
/***************************************************/
/***************************************************/
/* METHODS */
/***************************************************/
/***************************************************/
/* class gene expression methods */
/***************************************************/
void geneexp::setnumberofgenes(int temprows)/*temprows = 4 is passed*/
{
row = temprows;
cout << "in setnumberofgenes, row = " << row << endl;/*4 printed*/
genes = new gene[temprows];
cout << "in setnumberofgenes, row = " << row << endl;/*0 is printed!!*/
}
void geneexp::setnumberofconditions(int tempcolumns)
{
col = tempcolumns;
conditions = new condition[tempcolumns];
}
void geneexp::setnumberofcells(int tempcolumns)
{
col = tempcolumns;
cells = new cell[tempcolumns];
}
void geneexp::setmatrix(double **tempmatrix)
{
int i, j;
/*perform dynamic memory allocatin for element[][]*/
element = new double *[row];
for(i = 0; i < row; ++i)
element[i] = new double[col];
/*copy values from tempmatrix[][]*/
for(i = 0; i < row; ++i)
for(j = 0; j < col; ++j)
element[i][j] = tempmatrix[i][j];
}
void geneexp::removegene(int geneidentifier)
{
int i;
genes[geneidentifier].setgene("", 0);
/*if experiment is temporal, remove values of conditions*/
if(temporal == 1)
{
for(i = 0; i < col; i++)
conditions[i].setcondition("", 0);
}
/*if experiment is spacial, remove values of cells*/
else if(spacial == 1)
{
for(i = 0; i < col; i++)
cells[i].setcell("", 0);
}
}
void geneexp:: printgenes(void)
{
int i;
for(i = 0; i < row; ++i)
genes[i].printgene();
}
void geneexp:: printconditions(void)
{
int i;
for(i = 0; i < col; i++)
conditions[i].printcondition();
}
void geneexp:: printcells(void)
{
int i;
for(i = 0; i < col; i++)
cells[i].printcell();
}
void geneexp:: printmatrix(void)
{
int i, j;
for(i = 0; i < row; i++)
{
for(j = 0; j < col; j++)
{
cout.setf(ios::left);
cout.width(15);
cout << "\t" << element[i][j];
}
cout << endl;
}
}
/***************************************************/
/* END OF METHODS */
/***************************************************/