Write a C++ program Program to choose a series of numbers Write a program that w
ID: 3826267 • Letter: W
Question
Write a C++ program Program to choose a series of numbers Write a program that will choose five numbers between and including 1 and 75. It then will choose a sixth number between 1 and 15. The program should be structured as follows: a) A separate function should choose the first five numbers and also check that there are no repeats. You must make sure there are no repeats!!! If a repeat occurs the system will then re-choose that number but now you must make sure it was not one of the previous numbers chosen as well. b) A separate function will then print out the list of six numbers in a one row, an example is shown below. c) The main section of the program should request the user enter how many sets of numbers would you like to be displayed. The program would then generate that many sets of numbers.Explanation / Answer
The first 2 parts are the main in the above questions , the random number generation below is latest in c++11 standards it is a Mersenne Twister pseudo-random generator of 32-bit numbers with a state size of 19937 bits. The random generator always generate the unique numbers using the registers addresses, hence to deal with the repeation of the nimbers is not there, so no need to deal with these cases. Below code is made exactly according to the output.
mt19937 type is the Mersenne Twister pseudo-random generator of 32-bit .
Hope this will help you to complete the question ,
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <random>
using namespace std;
/* function main begins program execution */
int selectSixthNum();
int selectFiveNum();
int main(void) {
selectFiveNum();
selectSixthNum();
return 0;
}
int selectFiveNum(){
std::random_device rd; // obtain a random number from hardware
std::mt19937 eng(rd());
std::uniform_int_distribution<> distr(1, 75);
for(int n=0; n<5; ++n)
std::cout << distr(eng) << ' ';
return 0;
}
int selectSixthNum(){
std::random_device rd; // obtain a random number from hardware
std::mt19937 eng(rd());
std::uniform_int_distribution<> distr(1, 15);
std::cout << distr(eng) << ' ';
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.