How do I solve this type of exercise in pseint

2

Based on the statement, you must present a modular algorithm (without using fixes) that satisfies the objectives indicated below. STATEMENT: To capture the names and ages of 10 people fulfilling the following objectives: 1.- Implement cycle While

2.- Determine and show the average age of all people

3.- Determine and show the percentage of minors

4.- Determine and show the younger age and the name of the 1st person who has it

5.- Determine and show the oldest age and the name of the 1st person who has it

The condition is that it does not use an array, but that everything is with several threads using a cycle while

Algoritmo MayorMenor
Entrada(nombre,edad,acum)
PromedioEdad(edad,acum,prom)
FinAlgoritmo
SubProceso Entrada(nombre por referencia, edad por referencia,cont por referencia)
i=1
cont=0
Mientras i<=3 
    Mostrar "Ingrese el nombre de la ",i "°persona: " Sin Saltar
    Leer nombre
    Mostrar "Ingrese la edad de la ",i "°persona: " Sin Saltar
    Leer edad
    i=i+1
    acum=acum+edad
FinMientras
FinSubProceso

SubProceso PromedioEdad(edad,acum,prom Por Referencia)
prom=acum/3
FinSubProceso
    
asked by Luis Troya 06.10.2018 в 03:46
source

1 answer

0

First of all you must understand the difference between step by value and step by reference.

If the value of a variable you plan to change later, use the step by reference, if you do not use step by value.

I'm using the profile FCA-UNAM which is a bit more strict than the one you have, so I hope it will help you to become clearer in pseudo.

The accumulated age will be used for subsequent calculations, so we pass that value by reference when reading it, so when leaving the subprocess we will not lose that value.

The names as you will see are irrelevant in the other steps, so we reduce their scope so that the names live only in the sub-process input and leaving that sub-process are deleted.

Algoritmo MayorMenor
    definir acum Como Entero;
    acum=0;
    Entrada(acum);
    PromedioEdad(acum);
FinAlgoritmo

SubProceso Entrada(acum por referencia)
    Definir nombre como Cadena;
    Definir edad como Entero;
    Definir i como Entero;
    i=1;
    Mientras i<=3 
        Mostrar "Ingrese el nombre de la ",i "°persona: " Sin Saltar;
        Leer nombre;
        Mostrar "Ingrese la edad de la ",i "°persona: " Sin Saltar;
        Leer edad;
        i=i+1;
        acum=acum+edad;
    FinMientras
FinSubProceso

SubProceso PromedioEdad(acum)
    Definir prom Como Real;
    prom=acum/3;
    Escribir "el promedio de edades es " prom;
FinSubProceso

Other things that you can notice in this advance, is that I am defining name and age outside of the cycle while, this is not coincidence, it is an optimization to avoid creating new objects within a cycle, which in a real program will save you the time to dynamically reserve memory for your variables in each iteration.

Another tip that you can perceive is that the parameters of the methods are minimalist, do not pass more than necessary, that will allow you to visualize the subprocesses as if they were mathematical functions and not as a tedious routine.

    
answered by 25.12.2018 в 09:49