Resolviendo ejercicios del examen de C++

Ayer tuve un examen de programación en el lenguaje de programación c++ este examen fue en papel con lápiz y goma de borrar lo cual resultó terriblemente difícil el examen porque tengo una manera de resolver las cosas y esto fue muy anticuentadora pero respeto la manera de tomar exámenes de cada lugar y bueno.
En el examen había tres ejercicios y una pregunta de teoría afortunadamente logré hacer la mayoría de las cosas y estoy seguro que llegaría la nota que necesito pero por las dudas después de hacer el examen tomé mi computadora y resolví ese ejercicio con código.

Yesterday I had a C++ programming exam. It was a paper-based exam with pencil and eraser, which made it incredibly difficult because I have a specific way of solving problems, and this was very counterproductive. However, I respect the way exams are administered in different places.
The exam consisted of three exercises and one theory question. Fortunately, I managed to complete most of the exercises, and I'm confident I'll get the grade I need. But just in case, after the exam, I used my computer to solve the exercise with code.

examen1.png
Ejercicio no era muy complicado simplemente avisaba que se tenía una lista de difuntos y la enfermedad por la cual falleció dicha persona en lo cual se necesitaba hacer una cuenta en el caso de que llegara un nuevo difunto a la morgue para tener una lista de la cantidad de muertos según el tipo de enfermedad y en el caso de que murieran por alguna de la enfermedad que no se encuentra en la lista esta enfermedad se asignara a la lista y a la vez creara un contador partiendo con el número uno para tener en cuenta que apareció un nuevo caso con esa enfermedad.

The exercise wasn't very complicated; it simply stated that there was a list of deceased persons and the disease from which they died. It was necessary to keep track of the number of deaths by disease as each new person arrived at the morgue. If someone died from a disease not on the list, that disease would be added to the list, and a counter starting at one would be created to indicate that a new case of that disease had appeared.

examen2.png
Para resolverlo decidí utilizar dos vectores porque en ese momento la cabeza no me estaba funcionando bien de tanto escribir y fue la solución más rápida que se me ocurrió por lo que simplemente tengo dos vectores uno que maneja los nombres de las enfermedades y otro que maneja el contador de dicha enfermedad vinculándolos a cada uno por el índice en el índice 1 se encuentra la enfermedad de cierto nombre y en el índice 1 del otro vector se encuentra el contador de esa enfermedad luego el ejercicio solo pedía que aplique algunas funciones lo cual utilice una función que maneja tres parámetros el nombre de la enfermedad esos dos vectores e itera con alguno de los vectores y como tienen el mismo índice para vincularse prácticamente verifica nombre de enfermedad y aumenta el contador y en caso contrario agrega esa enfermedad y agrega un número más al contador en la posición final.

To solve this, I decided to use two vectors because my brain wasn't working properly at that moment from so much writing, and it was the quickest solution I could think of. So, I simply have two vectors: one that handles the names of the diseases and another that handles the counter for that disease, linking them to each other by index. At index 1, the disease with a certain name is found, and at index 1 of the other vector, the counter for that disease is found. Then, the exercise only asked me to apply some functions, so I used a function that takes three parameters: the name of the disease, and those two vectors. It iterates with one of the vectors, and since they have the same index for linking, it essentially checks the disease name and increments the counter; otherwise, it adds that disease and adds one more number to the counter at the final position.

examen3.png
Lo había resuelto bastante bien por lo visto pero me olvidé de colocar un símbolo en los parámetros de la función el cual hace referencia a que dichos parámetros tienen que estar referenciados al vector que le estoy pasando como parámetro y al no agregar ese símbolo lo que estaba haciendo mi código es crear dos vectores nuevos en memoria por lo tanto el contador funcionaba pero se sentía como que sí los vectores los estuviera inicializando en cero así que planteo quedó bien hecho pero un símbolo y el no poder probar el código en tiempo real hizo que el ejercicio esté mal con mucha suerte me darán gran parte de ejercicio bien hecho.

I had solved it quite well, it seemed, but I forgot to put a symbol in the function's parameters, which indicates that those parameters have to be referenced to the vector I'm passing as a parameter. Without adding that symbol, my code was creating two new vectors in memory, so the counter was working, but it felt like it was initializing the vectors to zero. So, the problem was solved, but that missing symbol and the inability to test the code in real time meant the exercise was wrong. With any luck, I'll get a good grade for a large part of the exercise.



0
0
0.000
1 comments
avatar

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

Consider setting @stemsocial as a beneficiary of this post's rewards if you would like to support the community and contribute to its mission of promoting science and education on Hive. 
 

0
0
0.000