Hi all.
Trying to move on and create a simple Mutation operator for the string that was created and then edited in the first two functions.
Basically a for loop which checks each element in the array Output.
Then comes my attempt at random numbers.
RandMax was defined as 100 so it is like 100%.
Basically starts off with i think, initializing variable Mut1 to random number.
If Mut1 > 80
{
//Then mutate but now choose what to mutate to.
If Mut2 > 50
{
then Output[index] = 1
}
else
{
Output[index] = 0
}
as you can prb see better in the code i wanted it to check each element then produce a random number to see if it would get changed, the problem is this needs to be done for each loop, each time it loops the variable Mut1 and Mut2 need to be random/ differant then last time so to speak.
Reinitialised with new numbers.
This is where i think i'am going wrong and was wondering if anyone knew a better way of getting it to work.
Thank you for any help.Code:#include <iostream>
#include <stdio.h>
#include <string>
#define RAND_MAX 100
using namespace std;
using std::string;
using std::cout;
using std::endl;
using std::cin;
void GetUserInput(string &Input)
{
cout << "Please enter Amino Acid Sequence \"H,P\": " << endl;
cin >> Input;
cin.get();
}
void GetSetupString(string theInput, int (&Output)[50])
// To declare an Array as a reference from Main, syntax is differant then other
// references, ie: Type (&ArryName)[Size], try finding that in any tutorial :)
{
int index;
for (index = 0; index < theInput.length(); ++index)
{
switch (theInput[index])
{
case 'H':
Output[index] = 1;
break;
case 'P':
Output[index] = 0;
break;
default:
break;
}
cout << Output[index] ;
}
cin.get();
}
int GetMutation (int (&Output)[50])
{
int index;
for ( index = 0; index < 49; ++index)
{
int Mut1;
Mut1 = rand();
int Mut2;
Mut2 = rand();
if (Mut1 > 80)
{
if ( Mut2 > 50)
{
Output[index] = 0;
}
else
{
Output[index] = 1;
}
}
else
{
//do nothing
}
cout << Output[index] ;
}
cin.get();
}
int main ()
{
string Input;
int Output[50];
GetUserInput(Input);
GetSetupString(Input, Output);
GetMutation(Output);
}