mirror of
https://inf-git.fh-rosenheim.de/studavrije7683/cplusplus-training.git
synced 2026-06-29 01:23:21 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,188 @@
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void ausgabeKaltWarm(string,int);
|
||||
void jahresDurchschnitt(int[]);
|
||||
int waermsterMonatImJahr(int[]);
|
||||
void sortieren(string[], int[]);
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
string monat[] = {"Januar", "Februar", "M\204rz", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"};
|
||||
int temperatur[] = {-1, 0, 4, 8, 13, 17, 21, 24, 19, 11, 9, 5};
|
||||
int eingabe = 1;
|
||||
int tmp = 0;
|
||||
|
||||
while(eingabe != 0)
|
||||
{
|
||||
system("cls");
|
||||
cout << "[1] Temperatur vom Monat ausgeben (Texteingabe)" << endl;
|
||||
cout << "[2] Temperatur vom Monat ausgeben (Auswahl)" << endl;
|
||||
cout << "[3] Durchschnittstemperatur ausgeben" << endl;
|
||||
cout << "[4] W\204rmster Monat ausgeben" << endl;
|
||||
cout << "[5] Temperatur sortiert ausgeben" << endl;
|
||||
cout << "[0] Beenden" << endl << endl;
|
||||
cout << "Treffen Sie Ihre Auswahl: ";
|
||||
|
||||
cin >> eingabe;
|
||||
|
||||
switch(eingabe)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
system("cls");
|
||||
|
||||
string eingabe_monat;
|
||||
tmp = 0;
|
||||
|
||||
cout << "Bitte geben Sie einen Monat ein: ";
|
||||
cin >> eingabe_monat;
|
||||
|
||||
for(int i = 0; i < 12; i++)
|
||||
{
|
||||
if(eingabe_monat == monat[i])
|
||||
{
|
||||
tmp = 1;
|
||||
|
||||
ausgabeKaltWarm(monat[i],temperatur[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(tmp != 1)
|
||||
{
|
||||
cerr << endl << "Monat nicht gefunden" << endl << endl;
|
||||
}
|
||||
|
||||
system("pause");
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
system("cls");
|
||||
|
||||
for(int i = 0; i < 12; i++)
|
||||
{
|
||||
cout << "[" << i+1 << "]" << monat[i] << endl;
|
||||
}
|
||||
|
||||
cout << endl << "Treffen Sie Ihre Auswahl: ";
|
||||
cin >> tmp;
|
||||
|
||||
if(tmp > 12 || tmp < 1)
|
||||
{
|
||||
cerr << endl << "Monat nicht gefunden" << endl << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
ausgabeKaltWarm(monat[tmp-1],temperatur[tmp-1]);
|
||||
}
|
||||
system("pause");
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
system("cls");
|
||||
jahresDurchschnitt(temperatur);
|
||||
system("pause");
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
system("cls");
|
||||
tmp = waermsterMonatImJahr(temperatur);
|
||||
cout << "Der w\204mste Monat im Jahr ist " << monat[tmp] << " mit " << temperatur[tmp] <<" Grad" << endl << endl;
|
||||
system("pause");
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
system("cls");
|
||||
sortieren(monat, temperatur);
|
||||
system("pause");
|
||||
break;
|
||||
}
|
||||
case 0:
|
||||
{
|
||||
cout << endl << "Auf Wiedersehen!" << endl;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
cout << endl << "Falsche Eingabe!" << endl << endl;
|
||||
system("pause");
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ausgabeKaltWarm(string eingabe_monat, int temperatur)
|
||||
{
|
||||
cout << endl << "Im " << eingabe_monat << " war es im Durchschnitt " << temperatur << " Grad";
|
||||
|
||||
if(temperatur > 0)
|
||||
cout << " warm";
|
||||
else if(temperatur < 0)
|
||||
cout << " kalt";
|
||||
|
||||
cout << endl << endl;
|
||||
}
|
||||
|
||||
void jahresDurchschnitt(int temp[])
|
||||
{
|
||||
float summe = 0;
|
||||
for(int i = 0; i < 12; i++)
|
||||
{
|
||||
summe = summe + temp[i]; //summe += temp[i]
|
||||
}
|
||||
cout << "Die Durchschnittstemperatur im Jahr betr\204gt " << (summe / 12) << " Grad" << endl << endl;
|
||||
}
|
||||
|
||||
int waermsterMonatImJahr(int temp[])
|
||||
{
|
||||
int max = 0;
|
||||
int z = 0;
|
||||
for(int i = 0; i < 12; i++)
|
||||
{
|
||||
if(temp[i] > max)
|
||||
{
|
||||
max = temp[i];
|
||||
z = i;
|
||||
}
|
||||
}
|
||||
return z;
|
||||
}
|
||||
|
||||
void sortieren(string mon[], int temp[])
|
||||
{
|
||||
string tmp_monat;
|
||||
int tmp_temperatur;
|
||||
|
||||
for(int i = 0; i < 12; i++)
|
||||
{
|
||||
for(int j = (i+1); j < 12; j++)
|
||||
{
|
||||
if(temp[i] > temp[j])
|
||||
{
|
||||
tmp_monat = mon[i];
|
||||
mon[i] = mon[j];
|
||||
mon[j] = tmp_monat;
|
||||
|
||||
tmp_temperatur = temp[i];
|
||||
temp[i] = temp[j];
|
||||
temp[j] = tmp_temperatur;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int x = 0;
|
||||
do
|
||||
{
|
||||
cout << temp[x] << " Grad im Monat " << mon[x] << endl;
|
||||
x++;
|
||||
}
|
||||
while(x<12);
|
||||
|
||||
cout << endl;
|
||||
}
|
||||
Reference in New Issue
Block a user