Programming in C ++
Practice 6: Programming Exercise - Bingo
General conditions
Important! Read the conditions for completing the assignments on the module website! Tasks are submitted via the form on the module website. Solutions will not be accepted by email. If you have any questions, please contact the subject list or the lab supervisor.
There are 14 days to solve the assignment.
Deadline: 01.05.2022 23:59:59
General requirements
As part of this lab, you will need to develop a program to play Bingo. The tasks are shown below, but in contrast to other assignments, there is no source code. Use the folder structures of the previous labs and update the Makefile accordingly. If you are using Qt, use the Qt project structure.
It is entirely up to you to decide what to do. You can use everything you have learned and learn more from the free materials. Write a C++ program that matches the task description. If you use additional frameworks, include them with the program code so that the instructor can also run your program on your computer.
Note: When developing, keep in mind the good development practices we have learned (comments, memory management, negativity checks). Since everyone solves the task differently and in their own way, we also evaluate the general quality of the solutions.
Example of a test application in pseudocode:
Bingo bingopilet = {}; // A new Bingo object is created and a 5x5 correct board is generated. bingopilet.genereeriVoiduNumbrid(); // Winning numbers will be generated for the corresponding ticket. std::cout << "Winning numbers: " << bingopilet.voiduNumbrid() << std::endl; // Winning numbers are displayed std::cout << bingopilet << std::endl; // The game board (ostream) is displayed std::cout << "Corner game: " << bingopilet.nurkadeMang() << std::endl; // Is it a corner game? (T/F) std::cout << "Diagonal game: " << bingopilet.diagonaalideMang() << std::endl; // Is it a diagonal game? (T/F) std::cout << "Full game: " << bingopilet.taisMang() << std::endl; // Is it a full game? (T/F)
Note: When developing, create a test application or reuse the code of previous labs. You can change the feature names, display order, and strategy, it's important that the content reaches the user. For Qt, running the program and the graphical interface should be user friendly.
Task 1 - General structure (2 points)
Create a data structure (for example class Bingo
) that holds one Bingo ticket. The class should hold all kinds of variables (game table, winning numbers, auxiliary variables, size, etc.) and the required functions (constructor / destructor / ostream). The bingo table must be printable or otherwise displayed in the output stream (Qt window).
Create a test application where you can test the functionality of the Bingo functionality and at the end also demo the program. The test application should be built and run the command make test
as in previous practices. A Qt application does not require a test application.
Note: The size of the game board can be fixed to a 5x5 square matrix.
Task 2 - Generate a game board (3 points)
Construct a function genereeriManguLaud
that takes as an argument the size of a table (5) and create a 5x5 square matrix in which each element is an integer from 1 to 75, and store it in a Bingo class. All according to the rules of Bingo. You can use this function in the constructor. Thus, when a Bingo class is created, the constructor automatically generates a valid 5x5 Bingo field and stores that Bingo class.
For a Bingo field to be correct, the numbers in the leftmost column must be in the range 1 to 15, the numbers in the next column in range 16 to 30, and so on, until the last column contains only the numbers in range 61 to 75. For simplicity, the task assumes that all the numbers in this table are unique, i.e. no number appears more than once in the table. If you are interested, also try to check the uniqueness of the numbers so that a table that otherwise complies with the rules but contains two identical numbers is not considered correct.
Examples of correct and incorrect Bingo tables (Python):
>>> on_bingo_tabel([[1, 30, 34, 55, 75], [10, 16, 40, 50, 67], [5, 20, 38, 48, 61], [4, 26, 43, 49, 70], [15, 17, 33, 51, 66]]) True >>> on_bingo_tabel([[1, 30, 34, 55, 76], [10, 16, 40, 50, 67], [5, 20, 38, 48, 61], [4, 26, 43, 49, 70], [15, 17, 33, 51, 66]]) False
If necessary, you can get inspiration from the help video if necessary.
Task 3 - Draw numbers (2 points)
Create a Bingo class functionality to draw winning numbers. For example, the function bingolaud.loosiNumbrid()
generates and stores the winning numbers in a suitable data structure. It should be possible to display the winning numbers to the user.
We cannot follow the correct Bingo Loto rules for drawing numbers here, so we drew numbers as follows:
Generate 35 winning numbers between 1 and 75 using random numbers.
Task 4 - Have we won? (3 points)
There are now all the prerequisites for creating three functions:
- bool cornersMang () - checks if the ticket won a corner game;
- bool diagonalsMang () - checks if the ticket won a diagonal game;
- bool taisMang () - checks if the ticket won a full game.
The functions return a true value according to whether the winning numbers previously drawn randomly filled the corners, diagonals or full play on the playing field.
Additional task 5 - Lottery Wednesday (1 additional point)
At the moment, every Bingo picket lives forever. The Bingo class generates one winning number for thousands of tickets. Create a class hierarchy in which the Bingo class covers the entire game with one or more Bingo tickets, similar to the previous task. Create Bingo class methods that allow you to generate 100 tickets to the game, for example, and methods that can check if there were winners among those tickets.
Tips
- C++ pseudo-randomness - https://www.cplusplus.com/reference/cstdlib/rand/
- Create an auxiliary function that returns a unique sequence of numbers in some range (a, b) of size c.