Tasks studies - laboratory
Choose one of the tasks below.
After completing the colloquium, pack the files into a .zip archive and submit using the form.
Write a function genPassword()
that takes 3 parameters: number of letters in the password, number of digits in the password, number of special characters in the password.
The function prints a randomly generated password in the console containing a specified number of characters. e.g. 3 letters 2 digits 1 special character
A4?yH0
The position of letters, digits and special characters is random.
In the main()
method, implement the menu:
1. Generate a new password.
2. Exit the program.
The program should run until the option to exit the program is selected. After selecting the Generate new password option, the user is asked about the number of letters in the password, the number of digits in the password and the number of special characters. After entering the data, the password is displayed in the console. Sample session:
1. Generate a new password.
2. Exit the program.
Select options: 1
How many letters: 1
How many digits: 1
How many special characters: 1
z!4
1. Generate a new password.
2. Exit the program.
Select options: 1
How many letters: 2
How many digits: 0
How many special characters: 2
*a#Z
1. Generate a new password.
2. Exit the program.
Select options: 2
Exit the program.
Create the program db_macierzodleglosci
.
Write a function allocate_2d_array()
that dynamically allocates memory space for a floating-point array of the size passed as function parameters. The function returns a pointer to this array.
Write a function free_2d_array()
that frees memory space for the array passed as a function parameter.
In a comment, describe what the function parameters are for if their name does not suggest it.
Write a function print_matrix()
that prints the contents of the array to the console in the following form:
| 0.00 | 0.10 |
| 1.00 | 4331.10 |
| 2.00 | 42.10 |
Create a function euclidDistance()
that accepts two arrays of any length as function parameters. The function calculates the Euclidean distance based on the values of the arrays according to the formula:
Create the function distnaceMatrix()
which calculates the distances between successive rows of the matrix passed as a function parameter and enters the calculated values into a new matrix. e.g. having the matrix:
| 0.00 | 0.00 |
| 0.00 | 1.00 |
| 0.00 | 2.00 |
the result of the operation will be a 3x3 matrix where in cell [1,1] is the distance between row 1 and 1, in cell [1,2] the distance between row 1 and 2, in cell … in cell [3,3] the distance between row 3 and 3:
| 0.00 | 1.00 | 2.00 |
| 1.00 | 0.00 | 1.00 |
| 2.00 | 1.00 | 0.00 |
In the main() method create the following menu:
1. Enter matrix
2. Display matrix
3. Distance matrix
4. Output
After selecting option 1 the program asks the user for the size of the matrix, allocates space for this matrix and then the user fills the matrix with data.
1 selected - Enter matrix.
Enter number of rows: 2
Enter number of columns: 2
tab[1][1] = 1
tab[1][2] = 3
tab[2][1] = 3
tab[2][2] = 2
After selecting option 2, the program displays the matrix using the print_matrix() function
After selecting option 3, the program displays the distance matrix of the matrix currently stored in memory.
The program should run until the exit option is selected. The memory should be freed at the appropriate moment.
Create the bdb_TicTacToe
program
Create an Array
structure that stores a dynamically allocated square matrix that stores characters. The structure should contain data about the size of the matrix.
Create the initArray()
function that returns an instance of the Array
structure. The function creates a new instance of the Array
structure and stores a matrix with a specified number of rows and columns passed as function parameters. By default, the matrix is filled with \0
values.
Create the freeArray()
function that takes as a parameter a pointer to the Array structure. The function deallocates space that stores the dynamically allocated space for the matrix. If everything goes well, the function returns true.
Create the makeMove()
function that takes as a parameter the Array
structure, the row number, column number, and the player’s symbol. If the move is valid (we do not exceed the range of the array and the field is free - it contains the symbol \0), the function writes the symbol in the appropriate place and returns 1. Otherwise, the function returns -1. If the array is completely filled, the function returns 2 (a tie)
Create the printArray()
function that takes as a parameter the Array
structure.
The function prints the contents of the matrix in the following format:
X O X X
X X X
X X
O
Create a function checkBoard()
that accepts an instance of the Array
structure. In the body of the function, implement a check to see if one of the players has filled a row, column or diagonal with their symbol. If so, the function returns this symbol.
In the main()
method, create a menu in which the user is asked about:
Example session:
Enter board size: 2
Enter number of players: 2
Enter symbol Player 1: X
Enter symbol Player 2: X
Symbol occupied, Enter symbol Player 2: O
= ...
===============================================
Player O's move
Enter row and column number (e.g. 1 1): 2 1
= ...
= ...