Hi there. I need to be able to use the front and back commands in vectors in order to modify only the first and last nucleotide of my input into my array...
What would be the easiest way to make this transition? Here's my code:
#include <iostream>
#include <vector>
usingnamespace std;
int main ()
{
float sum = 0; //Initial sum is 0.
char DNAbases[] = "aAcCgGtT"; // These are uppercase and lowercase abbreviations of base pairs (DNA)
float values[] =
{
313.21,313.21,289.18,289.18,329.21,329.21,304.20,304.20, //These are the assigned masses to corresponding base pairs above
};
string sequence;
std::cout << "Please enter a DNA sequence (up to 100 letters): "; // Input sequence
std::cin >> sequence;
std::cout << "Size of sequence: "
<< sequence.size() << " nucleotides" //Display size of sequence
<< std::endl;
for ( int i = 0; sequence[i] != '\0'; i++ ) // for loop, go through sequence until terminal
{
for ( int j = 0; DNAbases[j] != '\0'; j++ ) //within that loop, assign the correct mass
{
if ( sequence[i] == DNAbases[j] )
{
std::cout << DNAbases[j] << " mass:" << values[j] << ' '; //displays masses of base pairs entered
sum = sum + values[j];
}
}
cout << "partial sum: " << sum << endl; //displays masses of base pairs entered
}
std::cout<<"Your total sum is: " << sum; // Output sum
}
Edit: If you do need to use a vector, I do think it would be a vector<char>. In this case, it isn't so easy to switch over. You will have to change your input method and for loop conditions. You don't really want to put a null terminator, because then you wont be able to use push_back() so easy. There is no straight forward way (nothing like cout >> stringVariable) to output the contents of a vector.
Don't really understand what you want with that code, but if you have a vector you can use the array syntax to manipulate the first and last object in a vector.
1 2 3 4 5 6 7 8 9 10 11 12 13
vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
v[0] = 100;//first
v[2] = 300; //last
v[v.size()-1] = 3000;//last element (for when the vector size is variable)
//if the vector size is fixed (you don't add or remove elements from it)
int size = v.size();
v[size-1] = 3;
I'm trying to be able to subtract 75 from only the first and last numerical values, which were assigned based off the letter that they typed in (a,c,g,t) ... These numbers correlate to the masses of the DNA nucleotides... The first and last nucleotides of a synthetic piece of DNA have a different mass than the rest (because it's synthetic DNA) and I'm trying to figure out how to account for that...
Essentially, I'm not trying to use pushback, I'm trying to use back etc... Pointers could presumibly do the same thing.
Maybe I'll try pointers and remain in arrays... What do you think?