Skip to content

anonymous /P5P5
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
{ // Open scope block for part 6
cout << "\n\nStarting part 6 ...\n\n";
cout << "Input the minimum and maximum random int: ";
int minRange, maxRange;
cin >> minRange >> maxRange;
cout << "Input the length of the vector: ";
int vectorLength;
cin >> vectorLength;
vector<int> hasRepeats(vectorLength);
cout << " Vector beforehand: \t";
for (int i = 0; i < vectorLength; i = i + 1)
{ hasRepeats[i] = minRange + rand()%(maxRange - minRange + 1);
cout << hasRepeats[i] << " ";
}
cout << "\n";
////////////////////////////////////////////
// Your code for part 6 gets patched in here
// take out all multiples
//check if v[i] is equal to previous ones
//IF DUPLICATE, set to maxRange + 1 and then pop_back number of duplicates
int counter = 0;
for(int i = 0; i < vectorLength; i++)
{
for(int j = 0; j <= vectorLength ;j++)
{
if(hasRepeats[i] == hasRepeats[j])
{
hasRepeats[i] = maxRange + 1;
counter = counter + 1;
}
if(counter > 0)
{
for(int k = 0; k < counter; k++)
{
hasRepeats.pop_back();
}
}
}
}
////////////////////////////////////////////
cout << " Vector afterhand: \t";
for (int i = 0; i < hasRepeats.size(); i = i + 1)
{ cout << hasRepeats[i] << " ";
}
cout << "\n";
} // close the scope block for part 6
//////////////////////////////// End of Program ////////////////////////////////
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.