Menu

Arraybased Application Programming

0 Comment

General description: A tiny Lotto system allows up to 1000 people play “lotto”. This system provides some functions to facilitate lotto players to check their game status and get more information of lotto playing statistics. To simplify the system, we generate random data to mimics the lotto drawing, and we also use random data instead of real game data taken from lotto players. The lotto drawing is a process when the system randomly generates winning numbers, which is a list of 8 distinct integers from a barrel of 30 integer numbers (i.e., all numbers are between 1 and 30, inclusive). These 8 winning numbers are divided into two parts: the first part consists of the first 6 winning numbers in sequence, called Primary Winning Numbers (PWNs), and the second part consists of the last two winning numbers, called Supplementary Winning Numbers (SWNs). One example of the lotto drawing result may look like (see Figure 1): PWNs SWNs 14, 18, 22, 9, 29, 6 17, 30 Figure 1. Format of PWNs & SWNs For simplicity, we assume that each player is assigned an ID number, k (1 k 1000). We sometimes use the ID number to identify a player (e.g., player i, k, etc.). We also restrict that one player can only play one set of game numbers. That is, each player can choose one set of 6 distinct integer numbers as his/her game-numbers, each of which is also from a barrel of 30 numbers (i.e., all game numbers are integers between 1 and 30, inclusive). All players’ game-numbers are stored in a tiny “database” which, in this case, is implemented/replaced by a two-dimensional array (or list), lotto[0…999][0…5]. More specifically, for each player i, his/her game-numbers are stored in the array of lotto[i-1][0…5. The array lotto[0…999][0…5] can be represented, indicatively, as below (see Figure 1, note that the data inside the array is illustrative only): Player’s ID, i Player i’s game numbers 0 12 5 27 10 11 3 1 6 3 22 19 25 30 … 999 12 15 8 15 8 28 Figure 2. Format of game data in the array of lott[ ][ ] There is a total of 4 classes/levels of lotto winners. To be a winner, a player’s game-numbers must meet the winning conditions/criteria, which are described as: • A 1st class winner is one whose game-numbers match/contain all 6 PWNs; • A 2nd class winner is one whose game-numbers contain any 5 PWNs; • A 3rd class winner is one whose game-numbers contain any 4 PWNs; • A 4th class winner is one whose game-numbers contain any 3 PWNs, or contain the two SWNs. Note: As a general rule, if a player is a winner, he/she is considered as a winner of his/her highest class only, not a winner of any lower classes (e.g., if p is 1st class winner, p will not be considered as a 2 nd, or 3rd, or 4th class winner, although his/her game-numbers may still meet the winning conditions of lower classes)14/05/202030computerscience