Buch Cover Buch Cover Buch Cover Buch Cover

Web-Code: - Webcode Help

Hitzeindex (Anweisungen und Abfolgen)

An heißen Tagen fühlen wir oft nicht diejenige Temperatur, welche vom Thermometer angezeigt wird. Dieses Gefühl hängt mit der relativen Luftfeuchtigkeit zusammen. Je feuchter die Luft, umso mehr nehmen wir die Temperatur wahr.

Um dieses Phänomen zu beschreiben, wurde der sog. "Hitzeindex" eingeführt.

Dieser empirische Hitzeindex wird angewendet für Temperaturen > 27 Grad Celsius und einer relativen Luftfeuchtigkeit von über 40%.

Ihr Programm nimmt Temperatur (T in Grad C) und relative Luftfeuchtigkeit (p in %) entgegen und berechnet den Hitzeindex (hi) nach folgender Formel:

   hi = c1 +
          c2*T + c3*p +
          c4*T*p + c5*T*T + c6*p*p +
          c7*T*T*p + c8*T*p*p +
          c9*T*T*p*p

Dabei sind:

    c1 = -8.784695,
    c2 =  1.61139411,
    c3 =  2.338549,
    c4 = -0.14611605,
    c5 = -1.2308094e-2,
    c6 = -1.6424828e-2,
    c7 =  2.211732e-3,
    c8 =  7.2546e-4,
    c9 = -3.582e-6

0 Kommentare

Bitte melde dich an um einen Kommentar abzugeben

10 Lösung(en)

package ch.programmieraufgaben.sequenz;

import java.util.Scanner;

/**
 * @author Philipp Gressly (phi AT gressly DOT ch)
 */
public class Hitzeindex {
  public static void main(String[] args) {
    new Hitzeindex().top();
  }
  
  Scanner sc = new Scanner(System.in);
  double einlesenDouble(String wert) {
    System.out.println("Bitte " + wert + " eingeben: ");
    String eingabe = sc.next();
    try { return Double.parseDouble(eingabe); }
    catch (Exception ex) { System.out.println("Eingabefehler:" + eingabe); return 0; }
  }
  
  double
    c1 = -8.784695,
    c2 =  1.61139411,
    c3 =  2.338549,
    c4 = -0.14611605,
    c5 = -1.2308094e-2,
    c6 = -1.6424828e-2,
    c7 =  2.211732e-3,
    c8 =  7.2546e-4,
    c9 = -3.582e-6;
  
  void top() {
     // Temperatur in Celsius:
     double T = einlesenDouble("Temperatur (>27 Grad)");
     // relative Luftfeuchtigkeit in % (0..100);
     double p = einlesenDouble("Relative Luftfeuchtigkeit (> 40%)");
     double hi; // Hitzeindex
     hi = c1 + 
          c2*T + c3*p + 
          c4*T*p + c5*T*T + c6*p*p + 
          c7*T*T*p + c8*T*p*p + 
          c9*T*T*p*p;
     double hiGerundet = ( (int)(hi*100.0)) / 100.0;
     System.out.println("Gefühlte Hitze: " + hiGerundet);
  }
  
} // end of class Hitzeindex
                

Lösung von: Philipp G. Freimann (BBW (Berufsbildungsschule Winterthur) https://www.bbw.ch)

#include <windows.h>
#include <stdio.h>
#include <conio.h>

using namespace std;

double hindex(double T, double p) {
	double c1 = -8.784695;
	double c2 =  1.61139411;
	double c3 =  2.338549;
	double c4 = -0.14611605;
	double c5 = -1.2308094e-2;
	double c6 = -1.6424828e-2;
	double c7 =  2.211732e-3;
	double c8 =  7.2546e-4;
	double c9 = -3.582e-6;
    
    double hi = c1 + c2*T + c3*p + c4*T*p + c5*T*T + c6*p*p + c7*T*T*p + c8*T*p*p + c9*T*T*p*p;
    
    return hi;
}

int main() {
	double T = 0;
	double p = 0;
	while (T < 27 || p < 40) {
		system("cls");
		printf("%s", "Temperatur: ");
		scanf ("%lf", &T);
		printf("%s", "Relative Luftfeuchtigkeit: ");
		scanf ("%lf", &p);
		if (T < 27 || p < 40) {
			system("cls");
			printf("%s", "Falsche Eingabe!");
			getch();
		}
	}
	
	double hitze = ((int)(hindex(T, p) * 100.0)) / 100.0;
	
	printf("\n%s%g\n", "Die gef\x81hlte Temperatur betr\x84gt: ", hitze);
	
	getch();
	return 0;
}
                

Lösung von: Name nicht veröffentlicht

c1 = -8.784695
c2 =  1.61139411
c3 =  2.338549
c4 = -0.14611605
c5 = -1.2308094e-2
c6 = -1.6424828e-2
c7 =  2.211732e-3
c8 =  7.2546e-4
c9 = -3.582e-6

def hitzeindex():
    T = float(input("Temperatur eingeben(> 28° C): "))
    p = float(input("Luftfeuchtigkeit eingeben in %: "))
    hi =float(c1+(c2*T)+(c3*p)+(c4*T*p)+(c5*T*T)+(c6*p*p)+(c7*T*T*p)+(c8*T*p*p)+ (c9*T*T*p*p))
    print("Hitzeindex: ", hi)

hitzeindex()
                

Lösung von: Py Thon ()

program Hitzeindex (input, output);
{ berechnet anhand der Eingaben (Temp. in Celsius u. Luftfeuchte in %) die
* gefuehlte Temperatur (den Hitzeindex) }

    const
    C1 = -8.784695;
    C2 =  1.61139411;
    C3 =  2.338549;
    C4 = -0.14611605;
    C5 = -1.2308094e-2;
    C6 = -1.6424828e-2;
    C7 =  2.211732e-3;
    C8 =  7.2546e-4;
    C9 = -3.582e-6;

    type
    tProzent = 0..100;

    var
    Temperatur,
    GefTemp:    double;
    Luftf:      tProzent;

begin
    write('Bitte Temperatur in Grad Celsius eingeben: ');
    readln(Temperatur);
    write('Bitte Luftfeuchte in Prozent eingeben: ');
    readln(Luftf);

    GefTemp := C1 +
               C2*Temperatur + C3*Luftf +
               C4*Temperatur*Luftf + C5*Temperatur*Temperatur +
               C6*Luftf*Luftf + C7*Temperatur*Temperatur*Luftf +
               C8*Temperatur*Luftf*Luftf + C9*Temperatur*Temperatur*Luftf*Luftf;
    writeln;
    writeln('Die gefuehlte Temperatur ist: ', GefTemp:4:2, ' Grad C.');
end. { Hitzeindex }

                

Lösung von: Patrick Reif ()

! FORTRAN 90
PROGRAM hitzeindex
      ! Variabeldeklaration
      REAL :: c1, c2, c3, c4, c5, c6, c7, c8, c9, hi
      INTEGER :: T, p

      ! Variabelbefuellung
      c1 = -8.784695
      c2 = 1.61139411
      c3 = 2.338549
      c4 = -0.14611605
      c5 = -1.2308094e-2
      c6 = -1.6424828e-2
      c7 = 2.211732e-3
      c8 = 7.2546e-4
      c9 = -3.582e-6

      
      DO
            PRINT *, 'Geben Sie die Temperatur ein:'
            READ *, T
            IF (T > 27) THEN
                    EXIT
            END IF
      END DO
      DO
            PRINT *, 'Geben Sie die Luftfeuchtigkeit ein:'
            READ *, p
            IF (p > 40) THEN
                    EXIT
            END IF
      END DO

      hi = c1 + c2*T + c3*p + c4*T*p + c5*T*T + c6*p*p + c7*T*T*p + &
      c8*T*p*p + c9*T*T*p*p

      PRINT *, hi
END PROGRAM hitzeindex
                

Lösung von: Name nicht veröffentlicht

package Hitzeindex;
use strict;
use warnings;
use diagnostics;
use 5.010;
use utf8;

sub GetTemp {
	# Handling arguments given to the module
	my $temp = shift;
	my $luftf = shift;
	
	# Creating constants
	*C1 = \-8.784695; our $C1;
	*C2 = \1.61139411; our $C2;
	*C3 = \2.338549; our $C3;
	*C4 = \-0.14611605; our $C4;
	*C5 = \-1.2308094e-2; our $C5;
	*C6 = \-1.6424828e-2; our $C6;
	*C7 = \2.211732e-3; our $C7;
	*C8 = \7.2546e-4; our $C8;
	*C9 = \-3.582e-6; our $C9;
	
	# Calculate
	my $hitzeindex = $C1 + $C2 * $temp + $C3 * $luftf + $C4 * $temp * $luftf + $C5 * $temp * $temp + $C6 * $luftf * $luftf + $C7 * $temp * $temp * $luftf + $C8 * $temp * $luftf * $luftf + $C9 * $temp * $temp * $luftf * $luftf;
	
	# Return result
	return $hitzeindex;
}

1;
                

Lösung von: Name nicht veröffentlicht

function heatIndex(t, p) {
   var t2 = Math.pow(t, 2), p2 = Math.pow(p, 2);   
   if (t > 27 && p > 40) 
      return eval(
         /*c1*/-8.784695     +            
         /*c2*/ 1.61139411   * t +        
         /*c3*/ 2.338549     * p +        
         /*c4*/-0.14611605   * t * p +    
         /*c5*/-1.2308094e-2 * t2 +       
         /*c6*/-1.6424828e-2 * p2 +       
         /*c7*/ 2.211732e-3  * t2 * p +   
         /*c8*/ 7.2546e-4    * t * p2 +   
         /*c9*/-3.582e-6     * t2 * p2    
      ); 
   return undefined;
}

console.log(heatIndex(
   prompt("Temperatur (°C):"), 
   prompt("Relative Luftfeuchtigkeit (%):")
).toFixed(2));
                

Lösung von: Lisa Salander (Heidi-Klum-Gymnasium Bottrop)

// NET Core 3.x

using System;
using System.Collections.Generic;
using System.Linq;

namespace CS_MDL_CORE_Hitzeindex
{
    class Program
    {
        private const int RoundDigits = 2;

        private static readonly List<(double c, double ti, double pi)> _lst = new List<(double c, double ti, double pi)>
        {
            (-8.784695,     0,  0), (1.61139411,    1,  0), (2.338549,      0,  1),
            (-0.14611605,   1,  1), (-1.2308094e-2, 2,  0), (-1.6424828e-2, 0,  2),
            (2.211732e-3,   2,  1), (7.2546e-4,     1,  2), (-3.582e-6,     2,  2),
        };

        static void Main(string[] args)
        {
            Console.Write("Temperatur in °C: ");
            double.TryParse(Console.ReadLine(), out var t);
            Console.Write("Luftfeuchte in %: ");
            double.TryParse(Console.ReadLine(), out var p);
            Console.Write($"Hitzeindex: { HeatIndex(t, p) }");
        }

        static double HeatIndex(double t, double p) => t > 27 && p > 40 ? Math.Round(_lst.Select(x => x.c * Math.Pow(t, x.ti) * Math.Pow(p, x.pi)).Sum(), RoundDigits) : 0;
    }
}
                

Lösung von: Jens Kelm (@JKooP)

// C++ 11

#include <iostream>
#include <tuple>
#include <vector>
#include <iomanip>
using namespace std;

vector<tuple<double, double, double>> params = {
    { -8.784695,        0,  0 },    { 1.61139411,       1,  0 },
    { 2.338549,         0,  1 },    { -0.14611605,      1,  1 },
    { -1.2308094e-2,    2,  0 },    { -1.6424828e-2,    0,  2 },
    { 2.211732e-3,      2,  1 },    { 7.2546e-4,        1,  2 },
    { -3.582e-6,        2,  2 }
};

double heat_index(double t, double h)
{
    if (t <= 27 || h <= 40) return 0.0;
    auto sum{ 0.0 };

    for (auto p : params)
        sum += get<0>(p) * pow(t, get<1>(p)) * pow(h, get<2>(p));

    return sum;
}

int main()
{
    auto t { 0.0 };
    auto p { 0.0 };
    locale::global(locale("German_germany.UTF-8"));

    cout << "Temperatur in °C: ";
    cin >> t;
    cout << "Luftfeuchte in %: ";
    cin >> p;
    cout << "Hitzeindex: " << fixed << setprecision(2) << heat_index(t, p) << endl;
}
                

Lösung von: Jens Kelm (@JKooP)

' als VBA-Funktion für Excel

Const C1# = -8.784695
Const C2# = 1.61139411
Const C3# = 2.338549
Const C4# = -0.14611605
Const C5# = -0.012308094
Const C6# = -0.016424828
Const C7# = 0.002211732
Const C8# = 0.00072546
Const C9# = -0.000003582

Public Function HeatIndex(temperature As Double, humidity As Double, Optional roundDigits As Integer = 2) As Double

    Set w = WorksheetFunction
    t# = temperature: h# = humidity
    t2# = t ^ 2: h2# = h ^ 2
    
    HeatIndex = w.Round(IIf(temperature > 27 And humidity > 40, _
    w.Sum(C1, C2 * t, C3 * h, C4 * t * h, C5 * t2, C6 * h2, _
    C7 * t2 * h, C8 * t * h2, C9 * t2 * h2), 0), roundDigits)

End Function
                

Lösung von: Jens Kelm (@JKooP)

Verifikation/Checksumme:

28 Grad / 85% -> Hitzeindex = 32.89

Aktionen

Bewertung

Durchschnittliche Bewertung:

Eigene Bewertung:
Bitte zuerst anmelden

Meta

Zeit: 0.5
Schwierigkeit: Leicht
Webcode: w680-nfkr
Autor: Philipp G. Freimann (BBW (Berufsbildungsschule Winterthur) https://www.bbw.ch)

Download PDF

Download ZIP

Zu Aufgabenblatt hinzufügen