C++: Complete the following program which determines if the user has a winning lottery ticket. The user will input a 5-digit number which is the winning number. The program will compare that number to the list of numbers the user has and determine if they won. The method must use a linear search to find the number and return a Boolean true if the user is a winner and false otherwise. Use the code below:
#include <iostream>
using namespace std;
// Function prototype
bool searchList(const long[], int, long);
// Constant for array size
const int SIZE = 10;
int main()
{
// Array of numbers that are always played
long ticket[SIZE] = {13579, 26791,
26792, 33445,
55555, 62483,
77777, 79422,
85647, 93121};
// This variable will hold the winning number.
long winningNum;
// Get this week's winning number.
cout << "Please enter this week's 5-digit winning lottery number: ";
cin >> winningNum;
// Search for the winning number.
if (searchList(ticket, SIZE, winningNum))
{
// If searchList returned true, then
// the player has a winning ticket.
cout << "You have a winning ticket." << endl;
}
else
{
cout << "You did not win this week." << endl;
}
return 0;
}
/********************************************************
The searchList function accepts as arguments an array
of numbers, the size of the array, and the number to
search for. It determines if the number to search for
is in the set of stored numbers using a linear search.
It returns true if the number is found, otherwise it
returns false.
Pseudo Code:
Declare found as boolean default to false - return value
For count = 0 to size of array and not found increment by 1
If element at count equals search value
Set found to true
End If
End For
Return found
********************************************************/
bool searchList(const long list[], int numElems, long value)
{
}