Commit 1c84bcaf authored by Tony Cheung's avatar Tony Cheung

Upload New File

parent aee1d9a6
#include <iostream>
#include <time.h>
using namespace std;
class Sequence
{
private:
char* ary = nullptr;
public:
Sequence(int length);
~Sequence();
void InitialiseSequence(int length);
void PrintSequence(int length);
};
Sequence::Sequence(int length)
{
ary = new char[length];
for (int i = 0; i < length; i++)
ary[i] = NULL;
}
Sequence::~Sequence()
{
delete[] ary;
ary = nullptr;
}
void Sequence::InitialiseSequence(int length)
{
/* initialize random seed: */
srand(time(NULL));
int randnumber = 0;
for (int i = 0; i < length; i++)
{
randnumber = rand() % 4 + 1;
if (randnumber == 1)
ary[i] = 'A';
else if (randnumber == 2)
ary[i] = 'T';
else if (randnumber == 3)
ary[i] = 'C';
else
ary[i] = 'G';
}
}
void Sequence::PrintSequence(int length)
{
cout << "The Sequence is :" << endl;
for (int i = 0; i < length; i++)
cout << ary[i];
cout << endl;
}
int main()
{
// creating an object of Sequence
int l = 10;
Sequence s(l); // parameterized constrcutor
/* creating a pointer of Sequence type &
assigning address of s to this pointer */
Sequence* ptr = &s;
/* Initialsie sequence by using pointer
ptr to call the method InitialiseSequence()
*/
ptr->InitialiseSequence(l);
/* Display sequence by using pointer
ptr to call the method PrintSequence()
*/
ptr->PrintSequence(l);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment