Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need it in C++ having trouble getting it to output! Given integer inputs howMany and maxNum, generate a vector of howMany unique random integers from

Need it in C++ having trouble getting it to output!

Given integer inputs howMany and maxNum, generate a vector of howMany unique random integers from 0 to maxNum (exclusive).

The structure of the program is:

  • main() calls UniqueRandomInts() with arguments howMany, and maxNum.
  • UniqueRandomInts() returns a vector of howMany unique random integers.
  • The required output is already provided in main() and PrintNums().

Complete UniqueRandomInts(), which generates random integers until howMany unique integers have been collected in vector nums.

Hint: If a generated number is new, add the number to vector nums and set alreadySeen. If the number has been seen before, increment the global variable retries and generate another random integer.

Note: For testing purposes, the random number generator is seeded with a fixed value (641) in main().

Ex: When the input is: 5 8

the output is 5 4 0 1 6 [2 retries]

---------------------------------------------------------------------------------------------------------------------------------------------------------

#include #include #include using namespace std; void PrintNums(vector nums, int size) { for (int i = 0; i cout } } int retries; vector UniqueRandomInts(unsigned int howMany, int maxNum) { int nextRand; retries = 0; set alreadySeen; vector nums;

/* Type your code here. */

}

int main() { unsigned int howMany; unsigned int maxNum;

cin >> howMany; cin >> maxNum; vector uniqueInts;

srand(641);

uniqueInts = UniqueRandomInts(howMany, maxNum); PrintNums(uniqueInts, howMany); cout return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Entrepreneurship

Authors: Andrew Zacharakis, William D Bygrave

5th Edition

9781119563099

Students also viewed these Programming questions

Question

z = 1.1 for H a : Answered: 1 week ago

Answered: 1 week ago

Question

Defi ne HR planning and outline the HR planning process. LO1

Answered: 1 week ago