Question
Data Structure C++ language 1. Write and test a function that fills an int vector of size m with unique random numbers between 1 and
Data Structure C++ language 1. Write and test a function that fills an int vector of size m with unique random numbers between 1 and n. Make sure that m is not greater than n.
The function prototype is
vector
Unique randomFill, without the unique looks like
#include "stdafx.h"
#include
#include
#include
#include
using namespace std;
vector
uniform_int_distribution
default_random_engine *dre;
int main()
{
dre = new default_random_engine(time(nullptr));
for (int i = 1; i <= 9; i++)
{
uid = new uniform_int_distribution
vector
copy(v.begin(), v.end(), ostream_iterator
cout << endl;
}
return 0;
}
vector
{
vector
for(int i = 0; i < m; i++)
v[i] = (*uid)(*dre);
return v;
}
2. Write a function that compares 2 int vectors. The function returns true if at least k of the vectors elements equal one another.
The function prototype is
bool kEqual(const vector
Make sure the functions parameters make sense. For example, k cannot be greater than a vectors size. Note: equal elements do not have to appear at the same position in the vectors.
For example,
Vector v
Vector v
Vector v
Vector v
Vector v
Vector v
3. Using uniqueRandomFill, write a function that generates unique random vectors until a generated vector equals the functions vector parameter. equal means that the parameter vector contains the same elements as a generated vector. The function returns the number of vectors it generated until a match appeared. The functions prototype is
int gamble(const vector
where m and n have the same meaning as uniqueRandomFills m and n.
4.Test the function for m = 1 to 9 and let n = 9. Note n = 9 satisfies the condition that m <= n.
Use the following loop to test your function.
for i = 1 to 9
{
vector
cout << i << << gamble(v, i, 9);
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started