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

Define THREE functions prototypes to declare the initialize(), bingo() and getRa

ID: 3546761 • Letter: D

Question

 Define THREE functions prototypes to declare the initialize(), bingo() and getRandomInRange() . The functions must not contain any "cout" statement, except for main(). 
 Have the bingo() function call the getRandomInRange() function. 
 The getRandomInRange() function should have TWO arguments and return a number. 
 The getRandomInRange() calls the C++ library rand() function to obtain a random number within the range value as specified by the 2 arguments. 
 DO NOT call the C++ library rand() from the bingo() function directly. 
 The  initialize() function in the code is set to seed for the random number generator using the current computer clock.
 The initialize() function must be called only once from main() and does not have any return value.
  //#include <iostream> // Three function prototypes go here
 int main() {    initialize();    cout << "Bingo with B ->" << bingo('B') << endl;    cout << "Bingo with I ->" << bingo('I') << endl;    cout << "Bingo with N ->" << bingo('N') << endl;    cout << "Bingo with G ->" << bingo('G') << endl;    cout << "Bingo with O ->" << bingo('O') << endl;    cout << "Bingo with X ->" << bingo('X') << endl;    cout << "Bingo with Z ->" << bingo('Z') << endl;    
return 0; } // Three functions defined

Explanation / Answer

#include<iostream>
using namespace std;

int getRandomInRange(int max,int min){

int randnum = rand()%(max-min + 1) + min;
return randnum;
}

int bingo(char c){

int num =getRandomInRange(2,10) ;
return num;
}

void initialize(){
srand (time(NULL));
}

int main()
{
   initialize();
   cout << "Bingo with B ->" << bingo('B') << endl;
   cout << "Bingo with I ->" << bingo('I') << endl;
   cout << "Bingo with N ->" << bingo('N') << endl;
   cout << "Bingo with G ->" << bingo('G') << endl;
   cout << "Bingo with O ->" << bingo('O') << endl;
   cout << "Bingo with X ->" << bingo('X') << endl;
   cout << "Bingo with Z ->" << bingo('Z') << endl;
  

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote