Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please do this in C++ and follow all directions. Problem1: You have four identic

ID: 3889758 • Letter: P

Question



please do this in C++ and follow all directions.

Problem1: You have four identical prizes to give away and a pool of 25 finalists. The finalists are assigned numbers from i to 25. Write a program to randomly select the numbers of 4 finalists to receive a prize. Make sure not to pick the same number twice. For example, picking finalists 3, 15, 22, and 14 would be valid but picking 3, 3, 31, and 17 would be d, because finalist number 3 is listed twice and 3 1 is not a valid finalist number. Print the numbers of the four finalists. At the beginning, ask the user to enter an integer which you pass in to the sran function. Do not use srand(time(NULL) as this will generate random output which not pass the test cases. See the posted template on ZyBooks. cout

Explanation / Answer

c++ code:

#include<bits/stdc++.h>
using namespace std;
//function check if new_number is allready generated or not?
bool validRandomNumber(int new_number, vector<int> finalists)
{
if( find(finalists.begin(), finalists.end(), new_number ) == finalists.end())
{
  return true;
}
else
{
  return false;
}
}

int main()
{
cout << "Enter integer for srand" << endl;
int randonNum = 0;
cin >> randonNum;
int valid_numbers = 0;
vector<int> finalists;
srand(randonNum);

while(valid_numbers != 4)
{
    int new_number = rand()%25 + 1;             //generate new number
    if(validRandomNumber(new_number,finalists))    //check if new_number is allready generated or not?
    {
      valid_numbers += 1;
      finalists.push_back(new_number);
    }
}
//print all finalists
cout << "All the finalists are: ";
for (int i = 0; i < finalists.size(); ++i)
{
  cout << finalists[i] << endl ;
}

return 0;
}

Sample Output:

1)

Enter integer for srand
1
All the finalists are:
17
18
10
1

2)
Enter integer for srand
2
All the finalists are:
21
17
24
10