Initial commit

This commit is contained in:
studavrije7683
2021-10-15 08:36:02 +02:00
commit d3138a4b13
89 changed files with 2898 additions and 0 deletions
@@ -0,0 +1,64 @@
#include <iostream>
using namespace std;
void printTableFor();
void printTableWhile();
void printTableDoWhile();
int main(int argc, char** argv)
{
printTableFor();
cout << endl;
printTableWhile();
cout << endl;
printTableDoWhile();
return 0;
}
void printTableFor()
{
int max = 10;
for(int i = 1; i <= max; i++)
{
for(int j = 1; j <= max; j++)
{
cout << (i*j) << "\t";
}
cout << endl;
}
}
void printTableWhile()
{
int max = 10;
int i = 1, j = 1;
while(i <= 10)
{
while(j <= 10)
{
cout << (i*j) << "\t";
j++;
}
j = 1;
cout << endl;
i++;
};
}
void printTableDoWhile()
{
int max = 10;
int i = 1, j = 1;
do
{
do
{
cout << (i*j) << "\t";
j++;
}while(j <= 10);
j = 1;
cout << endl;
i++;
} while(i <= 10);
}
@@ -0,0 +1,56 @@
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
float fahrenheit;
float tmp;
float celsius;
int schrittweite = 20;
int maximum = 300;
do
{
cout << "Fahrenheit: ";
cin >> fahrenheit;
}while(fahrenheit<=0);
tmp = fahrenheit;
cout << "Schrittweite: ";
cin >> schrittweite;
cout << "Maximum: ";
cin >> maximum;
cout << endl;
for(fahrenheit=tmp; fahrenheit <= maximum; fahrenheit+=schrittweite)
{
celsius = ((fahrenheit - 32) * 5) / 9;
cout << "Fahrenheit: " << fahrenheit << "\t| Celsius: " << celsius << endl;
}
cout << endl;
fahrenheit = tmp;
while(fahrenheit <= maximum)
{
celsius = (((fahrenheit - 32) * 5) / 9);
if( celsius <= 10)
{
cout << "Es hat " << celsius << " \tGrad und es ist kalt" << endl;
}
else if(celsius <= 20)
{
cout << "Es hat " << celsius << " \tGrad und es ist angenehm" << endl;
}
else
{
cout << "Es hat " << celsius << " \tGrad und es wird heiss" << endl;
}
fahrenheit += schrittweite;
}
return 0;
}
@@ -0,0 +1,34 @@
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main ()
{
int zahl, eingabe, versuche=0;
srand (time(NULL));
zahl = rand()%100 + 1; //Zufallszahl zwischen 0 und 99 wird generiert, daher +1, damit die Zahl zwischen 1 und 100 ist
do
{
cout << "Zahl eingeben: ";
cin >> eingabe;
if(eingabe > zahl)
cout << "Zu gross!" << endl;
if(eingabe < zahl)
cout << "Zu klein!" << endl;
versuche ++;
}
while(eingabe != zahl && versuche < 6);
if (eingabe == zahl)
cout << "Erraten!" << endl;
else
cout << "Verloren! Die gesuchte Zahl war " << zahl << endl;
system("pause");
return 0;
}
@@ -0,0 +1,37 @@
#include <cstdlib>
#include <iostream>
using namespace std ;
int main ()
{
float z1, z2, erg;
char op;
cout << "2 Zahlen mit Operator dazwischen [+ - * / ]: ";
cin >> z1 >> op >> z2 ;
cout << z1 << op << z2 << "=";
switch (op)
{
case '+':
erg = z1 + z2;
cout << erg << endl;
break ;
case '-':
cout << z1 - z2 << endl;
break ;
case '*':
cout << z1 * z2 << endl;
break ;
case '/':
if ( z2 ==0)
cout << " Division durch 0 geht nicht" << endl;
else
cout << z1 / z2 << endl;
break ;
default :
cout << " Den Operator kenne ich nicht." << endl;
}
system("pause");
return 0;
}
@@ -0,0 +1,123 @@
#include <iostream>
#include <cstdlib>
using namespace std;
int Tiernummer;
string Art;
float Gewicht;
float Einnahme;
float Tagespreis;
bool Bestand;
//Prototypen
void TierAnlegen(void);
void TierAnzeigen(void);
void TierVerkaufen(int);
// Funktion zum Anlegen
void TierAnlegen(void)
{
cout << "Bitte geben Sie die Tiernummer ein: ";
cin >> Tiernummer;
cout << endl;
cout << "Bitte geben Sie die Tierart ein: ";
cin >> Art;
cout << endl;
cout << "Bitte geben Sie das Gewicht des Tieres an: ";
cin >> Gewicht;
cout << endl;
Bestand = true; //Tier ist im Bestand
} ;
// Funktion um Daten anzuzeigen
void TierAnzeigen(void)
{
cout << "Tiernummer: " << Tiernummer << endl;
cout << "Tierart: " << Art << endl;
cout << "Gewicht: " << Gewicht << endl;
cout << "Noch im Bestand? (1 = ja, 0 = nein): " << Bestand << endl;
};
void TierVerkaufen(int nr)
{
if(Tiernummer == nr && Bestand == 1)
{
cout << "Wie steht der Tagespreis?"<< endl;
cin >> Tagespreis;
Einnahme = Einnahme + (Gewicht*Tagespreis);
cout << "Gesamteinnahmen: " << Einnahme << endl;
Bestand = false;
cout << endl << endl;
}
else if (Tiernummer == nr && Bestand == 0)
{
cout << "Tier mit der Nummer " << nr << " nicht im Bestand." << endl;
}
else
{
cout << "Tier mit der Nummer " << nr << " nicht vorhanden." << endl;
}
} ;
int main(void)
{
int s = 0, eing, nr; // deklariert integer s auf Null, wird für das Menü werwendet
cout << "Herzlich willkommen bei der Bauernhofverwaltung" << endl << endl << "Bitte treffen Sie Ihre Auswahl im Menue..." << endl << endl << endl;
// Do-While-Schleife, die das Menü ausgibt und Untermenüs aufruft
do
{
system("cls");
//Das Menü
cout << "[1] Tier anlegen" << endl;
cout << "[2] Tier anzeigen" << endl;
cout << "[3] Tier verkaufen" << endl;
cout << "[0] Beende" << endl<<endl;
cout << "Treffen Sie Ihre Auswahl: ";
cin >> eing;
//Switch-Abfrage lädt in die einzelnen Menüpunkte
switch(eing)
{
case 1:
{
system("cls");
TierAnlegen(); // Funktion zur Anlage eines Tieres
cout << "Tier wurde angelegt: " << endl;
system("pause");
break;
}
case 2:
{
system("cls");
TierAnzeigen();
system("pause");
break;
}
case 3:
{
system("cls");
cout << "Tiernummer eingeben: " << endl;
cin >> nr;
TierVerkaufen(nr);
system("pause");
break;
}
}
}while (eing != 0);
cout << endl << "Auf Wiedersehen!" << endl;
system("pause");
return 0;
};
@@ -0,0 +1,22 @@
#include <iostream>
using namespace std;
int main()
{
for (int num=0; num<=100; num++)
{
/ * Dies bedeutet, dass wenn der Wert von
        * num nicht durch 2 teilbar ist, dann wird die
        * continue-Anweisung ausgeführt, wodurch die aktuelle Iteration übersprungen
        * wird und und somit die nächste Iteration stattfindet.
        * /
if (num % 2 == 1) // Ist nicht durch die Zahl 2 teilbar
{
continue;
}
cout << num << " ";
}
return 0;
}