Design and implement a C++ program that generates 15 random non-repeating positive integer numbers from 1 to 999 (lottery numbers) and takes a single input from the user and checks the input against the 15 lottery numbers. The user wins if her/his input matches one of the lottery numbers. Your implementation must have a level of modularity (using functions)
Functions you need to implement:
Hint: Array elements are assigned 0, which is outside of lottery numbers' range, to distinguish elements that have not been given lottery numbers yet.
Passing an array as a parameter and its initialization is done the way I showed you in class.
Hint: Looking for the match is similar to looking for the minimum.
Hint: Use srand(), rand() and time() functions that we studied earlier to generate appropriate random numbers from 1 to 999 and fill the array. Before the selected number is entered into the array lotterNumbers, call function check() to make sure that the new number is not already in the array. If it is already there, ignore it and select another number.
The pseudocode for your generate() function may be as follows:
1.declare a variable "number of selected lottery numbers so far", and
2.initialize this variable to zero
3.while (the_number_of_selected_elements is less than the array size)
3.1. select a new random number
3.2. call check() to see if this random number is already in the array
3.3. if the new random number is not in the array
3.3.1. increment the number of selected elements
3.3.2. add the newly selected element to the array
The pseudocode your function main() should be as follows:
main(){
declare array and other variables
initialize (...) // fill array with 0
generate(...) // select 15 non-repeating random numbers
input (...) // get user input
use check () to compare user input against lottery numbers
and output whether the user won
printOut(...) // outputs selected lottery numbers
}
Note: A program that processes each element of the array separately (i.e. accesses all 15 elements of the array for assignment or comparison outside a loop) is inefficient and will result in a poor grade.
Note 2: For your project, you should either pass the array size (15) to the functions as a parameter or use a global constant to store it. Hard-coding the literal constant 15 in function definitions that receive the array as a parameter is a poor style. It should be avoided.
using namespace std;
#define size 15
void initialize(int*);
void generate(int *);
int check(int *,int);//to check duplicate lotterNumber
int input();
bool check1(int *,int);
void printOut(int *,int);
int main()
{
int lotterNumbers[15],num;
bool decision;
initialize(lotterNumbers);
cout<<"\nInitially displaying the lotterNumbers:\n";
for(int i=0;i<size;i++)
{
cout<<" "<<lotterNumbers[i];
}
generate(lotterNumbers);
cout<<"\n\nDisplaying the lottersNumbers:\n";
for(int i=0;i<size;i++)
{
cout<<" "<<lotterNumbers[i];
}
num=input();
decision=check1(lotterNumbers, num);
if(decision==true)
{
cout<<"\nYou have won!!!";
printOut(lotterNumbers,num);
}
else
cout<<"\nYou lost!!";
return 0;
}
void initialize(int *p)
{
int i=0;
for(i=0;i<size;i++)
{
*p=0;
*p++;
}
}
void generate(int *p)
{
int n,c,flag;
c=1;
int *p1=p;
do
{
n=rand()%1000 + 1;
flag= check(p1,n);
if(flag==1)
{
*p=n;
*p++;
c++;
}
else
continue;
}while(c<=size);
}
int check(int *p,int n)
{
int i,flag=1;
for(i=0;i<size;i++)
{
if(*p==n)
{
flag=0;
break;
}
*p++;
}
if(flag==1)
return 1;
else
return 0;
}
int input()
{
int num;
cout<<"\n\nEnter your lotter Number:=";
cin>>num;
return num;
}
bool check1(int *p,int n)
{
int i,flag=0;
for(i=0;i<size;i++)
{
if(*p==n)
{
flag=1;
}
*p++;
}
if(flag==1)
return true;
else
return false;
}
void printOut(int *p,int n)
{
int i;
for(i=0;i<size;i++)
{
if(*p==n)
{
cout<<"\nThe lottery number which matches your number is: "<<*p;
}
*p++;
}
}

Lottery Game (15 Numbers). Design and implement a C++ program that generates 15 random non-repeating positive...
Using C++ create a lotto program Lottery Design a program that simulates a lottery. Requirements: The program should have an array of 5 integers named lottery and should generate a random number in the range of 1 through 99 for each element of the array. The user should enter five digits, which should be stored in an integer array named user. The program is to compare the corresponding elements in the two arrays and keep a count of the digits that...
Write a C++ program that simulates a lottery game. Your program should use functions and arrays. Define two global constants: - ARRAY_SIZE that stores the number of drawn numbers (for example 5) -MAX_RANGE that stores the highest value of the numbers ( for example 9 ) The program will use an array of five integers named lottery, and should generate a random number in the range of 0 through 9 for each element of the array. The user should enter...
Write a C++ program that simulates playing the Powerball game. The program will generate random numbers to simulate the lottery terminal generated numbers for white balls and red Powerball. The user will have the option to self-pick the numbers for the balls or let the computer randomly generate them. Set the Grand Prize to $1,000,000,000.00 in the program. Project Specifications Input for this project: Game mode choice – self pick or auto pick Five numbers between 1 and 69 for...
Design a program using Python and using from flask Import flask that generates a lottery number but in a website.. The program should have an Integer array with 9 elements. Write a loop that steps through the array, randomly generating a number in the range of 0 through 42 for each element. (Use the random function) Then write another loop that displays the contents of the array. Each number should be displayed as a list, the numbers should be generated...
C++ exercise: Lottery Number Generator Design a program that generates a 7-digit lottery number. The program should have an Integer array with 7 elements. Write a loop that steps through the array, randomly generating a number in the range of 0 through 9 for each element. (Use the random function that was discussed in Chapter 6.) Then write another loop that displays the contents of the array.
5.4 Java Create a program that generates SuperLotto lottery numbers. Create a class called SuperLottoPlus.java Create a method called generateSuperLottoNumbers() that returns an array of 6 random SuperLotto lottery numbers. The first 5 numbers must be from the range 1 to 47 The 6th number (the MEGA) must be from 1 to 27. Create a method called printTicket() that takes an integer array as an parameter it will loop through the integer array and print out the data Display the...
Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a one-dimensional array with the first 30 Fibonacci numbers using a calculation to generate the numbers. Note: The first two Fibonacci numbers 0 and 1 should be generated explicitly as in -long[] series = new long[limit]; //create first 2 series elements series[0] = 0; series[1] = 1; -But, it is not permissible to fill the array explicitly with the Fibonacci series’ after the first two...
Rules to follow are:Declare an array with 1000 elements of type intThen in a loop generate 1000 random numbers and assign one to each element in the arrayThe random numbers should be between 1 and 50do not use rand or srand, use code is providedThen, prompt the user to enter a number, store this number in a local variable, the number should be safety checked using the GetInteger() functionThen, iterate through the array and determine how many times the user's...
PYTHON: Using Lists and Arrays! 3. Design a program that generates a seven-digit lottery number. The program should generate seven random numbers, each in the range of 0 through 9, and assign each number to a list element. (Random numbers were discussed in Chapter 5.) Then write another loop that displays the contents of the list.
2. Write a C++ program, that generates a set of random integers and places them in an array. The number of values generated and their range are entered by the user. The program then continually prompts the user for one of the following character commands: a: display all the values I: display the values less than a given value g display the values greater than a given value e: display all odd values o: display all even values q: quit...