Docsity

Programming - Extraordinary exam June 2019: gymnastics problem (solved), Exámenes de Programación Informática

Toggle sidebar
bg1
UNIVERSIDAD CARLOS III DE MADRID
PROGRAMMING. AEROSPACE INGENIERING DEGREE
Extraordinary Exam. June 2019.
Surname(s) : _________________________________________________
Name:______________________________________________________
NIA:__________________________________
Exercise (7.5 points) Duration: 90 minutes
The main committee of the Women's World Championship of Artistic Gymnastics requires developing a
MATLAB program for the management of the teams’ competition. To solve the exercise, consider that 8
teams will participate and the number of gymnasts in each team is 5, so there will be a total of 40 gymnasts
competing. In addition, each gymnast performs 1 exercise of each of the 4 modalities of this sport: Vault,
Uneven Bars, Balance Beam, and Floor Exercise.
It is required:
1. [1 point]. Define and declare the data structures necessary to store the information related to each
team and each gymnast.
For each team, the following information will be stored:
• Country Name (string)
• 3-letter code (e.g. ESP, USA, RUS)
• Position in the world ranking (integer)
• Score achieved by the team in the championship (float)
For each gymnast the following information will be stored:
• Team Identifier (integer between 1 and 8).
• Name (string)
• Surname (string)
• Age (integer)
• Height in cm (integer).
• Number of previous world championships in which she has participated (integer)
• Execution: Vector that will store the average mark given by the 5 judges to the gymnast in
each of the exercises of the 4 modalities of this sport. (float)
• Difficulty: Vector in which, for each of the 4 exercises performed by the gymnast, a decimal
value between 0 and 1 will be stored, which reflects the difficulty of that exercise. (float)
• Errors: Vector in which the errors made in each of the 4 exercises are stored. (integer)
• Score: Vector that stores the score of the gymnast in each of the 4 exercises. This score will
be calculated based on the values of the 3 previous vectors according to the following
formula: Score = execution * difficulty- (errors * 0.2)
2. [1 point]. Write a function called registrar, which fills in and initializes the data of the teams and
gymnasts participating in the Championship based on the data structures defined in the previous
section. The data that can be filled out will be requested to the user using the keyboard, the
remaining data pieces must be initialized with the appropriate values. The data of all the teams
must be requested and filled firstly, and then the information of all the gymnasts. The format of
this function must be:
function [equipos, gimnastas]=registrar (nunEquipos, numGimnastas, numModalidades)
pf3
pf4
pf5

Vista previa parcial del texto

¡Descarga Programming - Extraordinary exam June 2019: gymnastics problem (solved) y más Exámenes en PDF de Programación Informática solo en Docsity!

UNIVERSIDAD CARLOS III DE MADRID

PROGRAMMING. AEROSPACE INGENIERING DEGREE

Extraordinary Exam. June 2019.

Surname(s) : _________________________________________________

Name:______________________________________________________

NIA:__________________________________

Exercise (7.5 points) Duration: 90 minutes

The main committee of the Women's World Championship of Artistic Gymnastics requires developing a

MATLAB program for the management of the teams’ competition. To solve the exercise, consider that 8

teams will participate and the number of gymnasts in each team is 5, so there will be a total of 40 gymnasts

competing. In addition, each gymnast performs 1 exercise of each of the 4 modalities of this sport: Vault,

Uneven Bars, Balance Beam, and Floor Exercise.

It is required:

1. [1 point]. Define and declare the data structures necessary to store the information related to each

team and each gymnast.

For each team, the following information will be stored:

• Country Name (string)

• 3 - letter code (e.g. ESP, USA, RUS)

• Position in the world ranking (integer)

• Score achieved by the team in the championship (float)

For each gymnast the following information will be stored:

• Team Identifier (integer between 1 and 8).

• Name (string)

• Surname (string)

• Age (integer)

• Height in cm (integer).

• Number of previous world championships in which she has participated (integer)

• Execution: Vector that will store the average mark given by the 5 judges to the gymnast in

each of the exercises of the 4 modalities of this sport. (float)

• Difficulty: Vector in which, for each of the 4 exercises performed by the gymnast, a decimal

value between 0 and 1 will be stored, which reflects the difficulty of that exercise. (float)

• Errors: Vector in which the errors made in each of the 4 exercises are stored. (integer)

• Score: Vector that stores the score of the gymnast in each of the 4 exercises. This score will

be calculated based on the values of the 3 previous vectors according to the following

formula: Score = execution * difficulty- (errors * 0.2)

2. [1 point]. Write a function called registrar, which fills in and initializes the data of the teams and

gymnasts participating in the Championship based on the data structures defined in the previous

section. The data that can be filled out will be requested to the user using the keyboard, the

remaining data pieces must be initialized with the appropriate values. The data of all the teams

must be requested and filled firstly, and then the information of all the gymnasts. The format of

this function must be:

function [equipos, gimnastas]=registrar (nunEquipos, numGimnastas, numModalidades)

3. [2 points]. Write a function called realizarEjercicio in which, after performing an exercise of a

specific modality, the score achieved in that exercise must be assigned. To obtain the score of the

exercise, the following criteria is applied:

  • 5 judges value the execution of the exercise with a decimal value between 0 and 10. These

five values are entered using the keyboard. The mark of the execution corresponds to the

average of the evaluation given by the judges.

  • Each exercise has a difficulty level (value between 0.5 and 1.0) that will be provided using

the keyboard.

  • Finally, the number of errors that the gymnast made during the exercise will be read on the

keyboard.

  • The score assigned to the gymnast is calculated as follows: score = execution * difficulty -

(errors * 0.2)

The format of this function must be:

function gimnasta=realizarEjercicio (gimnasta,modalidad)

When implementing this function consider that all the values entered by keyboard are valid (they are

into the valid range), so it is not necessary to include additional validations in the solution.

4. [2 points] Write a function called calcularPuntuacionEquipo that calculates the score obtained

by a team. This score corresponds to the sum of the score obtained by each gymnast in each of the

modalities. The format of this function mustl be:

function equipo=calcularPuntuacionEquipo (equipo, idEquipo, gimnastas, numGimnastas, numModalidades)

5. [1 point]. Write a function called mostrarEquipos that shows on the screen the data of the teams

participating in the championship. The format of this function must be:

function mostrarEquipos (equipos, nEquipos)

6. [ 1 point]. Write a function called obtenerClasificacionEquipos, which will order the teams from

highest to lowest score using the bubble sort method. The format of this function must be:

function clasificacion = obtenerClasificacionEquipos (equipos, nEquipos)

7. [2 points]. Write the main program that simulates the World Championship of Artistic Gymnastics

according to the following specifications:

  • Register the teams and gymnasts participating in the Championship
  • For each modality (Vault, Uneven Bars, Balance Beam, and Floor Exercise), the gymnasts

will perform the corresponding exercise and will be scored.

  • Once all the exercises of all the modalities have been executed, the score of each team will

be calculated.

  • Next, the team ranking will be obtained (teams ordered by score in the championship) and

this ranking will be shown on the screen.

  • Finally, the teams in the medal table will be shown, that is, the three teams with the highest

score.

equipos(i).posicion = input('Introduce la posicion que ocupa en el ranking este equipo:\n'); equipos(i).puntuacion = 0.0; end for (j=1:numGimnastas) fprintf('Introduzca los datos del gimnasta nº %d\n', j); gimnastas(j).ID_Equipo = input('Introduce el códiGo de equipo al que pertenece:\n'); gimnastas(j).nombre = input('Introduce el nombre:\n','s'); gimnastas(j).apellidos = input('Introduce el apellido:\n','s'); gimnastas(j).edad = input('Introduce la edad:\n'); gimnastas(j).estatura = input('Introduce la estatura:\n'); gimnastas(j).num_mundiales = input('Introduce el numero de mundiales que ha disputado:\n'); gimnastas(j).ejecucion = zeros(1,numModalidades); gimnastas(j).dificultad = zeros(1,numModalidades); gimnastas(j).errores = zeros(1,numModalidades); gimnastas(j).puntuacion = zeros(1,numModalidades); end end % Fin Apartado 2 % Apartado 3 function gimnasta=realizarEjercicio (gimnasta, modalidad) promedio = 0; jueces = 5; for (i=1:jueces) fprintf('Introduce la nota del juez %d para la modalidad %d:\n', i, modalidad); nota = input(''); promedio = promedio + nota; end gimnasta.ejecucion(modalidad) = promedio / i; gimnasta.dificultad(modalidad) = input('Introduce la dificultad para este ejercicio:\n'); gimnasta.errores(modalidad) = input('Introduce el número de errores cometido en este ejercicio:\n'); gimnasta.puntuacion(modalidad) = gimnasta.ejecucion(modalidad)gimnasta.dificultad(modalidad) - (gimnasta.errores(modalidad)0.2); end % Fin Apartado 3 % Apartado 4 function equipo=calcularPuntuacionEquipo (equipo, idEquipo, gimnastas, numGimnastas, numModalidades) totalPuntos = 0; for (i=1:numGimnastas) if (gimnastas(i).ID_Equipo == idEquipo) for (j=1:numModalidades) totalPuntos = totalPuntos + gimnastas(i).puntuacion(j); end end end equipo.puntuacion = totalPuntos; end % Fin Apartado 4 % Apartado 5 function mostrarEquipos (equipos, nEquipos) for (i=1: nEquipos)

fprintf('\nEstos son los datos del equipo %d:\n', i); fprintf('================================\n', i); fprintf('Nombre: %s\n', equipos(i).nombre); fprintf('Código: %s\n', equipos(i).codigo); fprintf('Posicion: %d\n', equipos(i).posicion); fprintf('Puntuación: %f\n', equipos(i).puntuacion); end end % Fin Apartado 5 % Apartado 6 function clasificacion = obtenerClasificacionEquipos (equipos, nEquipos) clasificacion = equipos; for i = 1:(nEquipos - 1) for j = 1:(nEquipos - i) % comparison index^th with (index + 1)^th if ( clasificacion(j).puntuacion < clasificacion(j+1).puntuacion ) % swap the content of the two positions equipo = clasificacion(j); clasificacion(j) = clasificacion(j+1); clasificacion(j+1) = equipo; end end end end % Fin Apartado 6