Concetti Chiave

  • Il programma permette di inserire il nome di tre città e le rispettive temperature massime e minime.
  • Utilizza array per memorizzare i nomi delle città e le temperature, consentendo l'iterazione tramite un ciclo for.
  • Include procedure per visualizzare le temperature massime e minime di ogni città memorizzata.
  • Calcola la media delle temperature massime e minime di tutte le città inserite.
  • Offre un menu interattivo che permette di scegliere tra inserimento, visualizzazione, e calcolo della media delle temperature.

Inserire il nome della città, la temperature massima e la temperature minima. Visualizzare la temperatura massima e minima di ogni città e calcolare la media delle temperature massime e minime di ogni città.

program es;

uses crt;

const n=3;

var citta:array[1..n]of string;

var min:array[1..n]of real;

var max:array[1..n]of real;

var i,numero,opz:integer;

var tempmax,tempmin,m1,m2:real;

Insertion Procedure

PROCEDURE INSERIMENTO;

BEGIN

tempmax:=0;

tempmin:=0;

for i:=1 to n do

begin

writeln('nome ' , i , '^ citt…:');

readln(citta);

writeln('temperatura massima:');

readln(max);

writeln('temperatura minima:');

readln(min);

tempmax:=tempmax+max;

tempmin:=tempmin+min;

end;

END;

Temperature Display

PROCEDURE VISUALIZZA;

BEGIN

for i:=1 to n do

begin

writeln('la citt… ' , citta , ' ha temperatura massima di ' , max:0:2, 'ø e temperatura minima di ' , min:0:2 , 'ø');

readln;

end;

END;
PROCEDURE MEDIA;

BEGIN

for i:=1 to n do

begin

m1:=tempmax/n;

m2:=tempmin/n;

end;

END;

Average Display

PROCEDURE VISUALIZZA_MEDIA;

BEGIN

writeln(' la media delle temperature massime di tutte le citt… Š ' , m1:0:2,'ø ');

writeln('la media delle temperature minime di tutte le citt… Š ' , m2:0:2, 'ø');

readln;

END;
{PROGRAMMA PRINCIPALE}

BEGIN

CLRSCR;

writeln('inserisci numero citt…:');

readln(numero);

REPEAT

WRITELN('INSERIMENTO');

WRITELN('VISUALIZZA');

WRITELN('MEDIA');

WRITELN('VISUALIZZA_MEDIA');

WRITELN('INSERISCI OPZIONE');

READLN(OPZ);

CASE OPZ OF

1:INSERIMENTO;

2:VISUALIZZA;

3:MEDIA;

4:VISUALIZZA_MEDIA;

END;

UNTIL (OPZ=5)

END.

Domande da interrogazione

  1. How does the program handle the input of city names and their respective temperatures?
  2. The program uses a procedure called INSERIMENTO to input the names of cities and their maximum and minimum temperatures. It iterates over a predefined number of cities, prompting the user to enter the city name, maximum temperature, and minimum temperature, which are then stored in arrays.

  3. What is the purpose of the VISUALIZZA procedure in the program?
  4. The VISUALIZZA procedure is designed to display the maximum and minimum temperatures for each city. It iterates through the list of cities and prints out the city name along with its corresponding maximum and minimum temperatures formatted to two decimal places.

  5. How does the program calculate and display the average temperatures?
  6. The program calculates the average maximum and minimum temperatures using the MEDIA procedure, which divides the total of the maximum and minimum temperatures by the number of cities. The VISUALIZZA_MEDIA procedure then displays these averages, formatted to two decimal places, to the user.

Domande e risposte

Hai bisogno di aiuto?
Chiedi alla community