K
kittykat
Basically, what I am trying to do is the user is required to enter a
"pattern" which is a combination of the following letters: a, c, t, g. so,
for example, the user can enter agt, or acc, or tgc...and so on.
for now, im assiuming that the user will ONLY enter a combination of these
four letters. When they do, then:
If letter = a, go to first vector.
If letter = c, go to second vector.
If letter = g, go to third vector
If letter = t, go to fourth vector.
Enter 1 for the position in the order that the user enters the pattern.
For example, if the user enters the letters tcg…then this is how it will
be stored in a vector of vectors. assume each row is a vector: (the
numbers at the top are the positions of the elements)
0 1 2
0 0 0
0 1 0
0 0 1
1 0 0
am i making sense?? I hope so.
Ok…so here is my code which I *think* does what I explained above.
#include< ... >
using namespace std;
typedef vector<int> row;
int main()
{
vector<char> DNApattern;
string codon;
cout << "Enter pattern: " << endl;
getline(cin, codon,'\n');
for ( int i=0; i < codon.length(); ++i)
{
DNApattern.push_back(codon);
}
//Testing output for DNApattern Vector
for ( int i = 0; i < DNApattern.size(); i++ )
{
cout << "Letter at position " << i << " is " << DNApattern <<
endl;
}
unsigned int position = codon.length();
row initialisedRow(position, 0);
unsigned int numRows = 4;
vector<row> Data (numRows, initialisedRow);
for (int idx = 0; idx < codon.length(); ++idx)
{
int letterNum = 0;
row& currentRow = Data[letterNum];
int& currentValue = row[idx];
currentValue = currentValue + 1;
}
system("PAUSE");
return 0;
}
My questions:
1) How shall I fix the following error message which says
“primary-expression expected before ‘[‘”, and it is referring to
int& currentValue = row[idx];
2) Is what I’ve written correct?
3) I would also like to know if there is a more efficient or a simpler way
of doing this?
"pattern" which is a combination of the following letters: a, c, t, g. so,
for example, the user can enter agt, or acc, or tgc...and so on.
for now, im assiuming that the user will ONLY enter a combination of these
four letters. When they do, then:
If letter = a, go to first vector.
If letter = c, go to second vector.
If letter = g, go to third vector
If letter = t, go to fourth vector.
Enter 1 for the position in the order that the user enters the pattern.
For example, if the user enters the letters tcg…then this is how it will
be stored in a vector of vectors. assume each row is a vector: (the
numbers at the top are the positions of the elements)
0 1 2
0 0 0
0 1 0
0 0 1
1 0 0
am i making sense?? I hope so.
Ok…so here is my code which I *think* does what I explained above.
#include< ... >
using namespace std;
typedef vector<int> row;
int main()
{
vector<char> DNApattern;
string codon;
cout << "Enter pattern: " << endl;
getline(cin, codon,'\n');
for ( int i=0; i < codon.length(); ++i)
{
DNApattern.push_back(codon);
}
//Testing output for DNApattern Vector
for ( int i = 0; i < DNApattern.size(); i++ )
{
cout << "Letter at position " << i << " is " << DNApattern <<
endl;
}
unsigned int position = codon.length();
row initialisedRow(position, 0);
unsigned int numRows = 4;
vector<row> Data (numRows, initialisedRow);
for (int idx = 0; idx < codon.length(); ++idx)
{
int letterNum = 0;
row& currentRow = Data[letterNum];
int& currentValue = row[idx];
currentValue = currentValue + 1;
}
system("PAUSE");
return 0;
}
My questions:
1) How shall I fix the following error message which says
“primary-expression expected before ‘[‘”, and it is referring to
int& currentValue = row[idx];
2) Is what I’ve written correct?
3) I would also like to know if there is a more efficient or a simpler way
of doing this?