From 94b226257b9d5be6026fd993c75b6186e5164a79 Mon Sep 17 00:00:00 2001 From: Leaced Date: Sun, 2 Apr 2017 15:59:33 +0200 Subject: [PATCH] =?UTF-8?q?3=20Programme=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- InsertionSort.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++ SelectionSort.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++ Zahlen Raten.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 InsertionSort.cpp create mode 100644 SelectionSort.cpp create mode 100644 Zahlen Raten.cpp diff --git a/InsertionSort.cpp b/InsertionSort.cpp new file mode 100644 index 0000000..779ad67 --- /dev/null +++ b/InsertionSort.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +#include + +int main() +{ + std::string input; + unsigned short amount; + + std::cout << "Gib die Anzahl der Zahlen ein: "; + getline(std::cin, input); + std::stringstream(input) >> amount; + + std::cout << "\n"; + + long double array[amount]; + + for(unsigned short idx = 0; idx < amount; idx++) + { + std::cout << "Gib die " << idx+1 << ". Zahl ein: "; + getline(std::cin,input); + std::stringstream(input) >> array[idx]; + } + + std::cout << "\n"; + + for(unsigned short idx = 0; idx=0 && array[idx2]>temp) array[idx2+1] = array[idx2--]; + + array[idx2+1] = temp; + + for(unsigned short idx =0; idx +#include +#include +#include + +int main() +{ + std::string input; + unsigned short amount; + + std::cout << "Gib die Anzahl der zahlen ein: "; + getline(std::cin, input); + std::stringstream(input) >> amount; + + std::cout << "\n"; + + long double array[amount]; + + for(unsigned short idx = 0; idx> array[idx]; + } + + std::cout << "\n"; + + for(unsigned short idx =0; idx +#include +#include +#include +#include +#include +using namespace std; +int main() +{ + bool again = true; + + while(again==true) + { + short randNumber = 0, tries = 0, number = 0; + std::string input; + + std::cout << "Errate die richtige Zahl zwischen 1 und 100: "; + + srand(time(NULL)); + randNumber = rand()%100+1; + + while(number!=randNumber) + { + tries++; + getline(std::cin, input); + stringstream(input) >> number; + + if(numberrandNumber) + { + std::cout << "\nDie eingegebene Zahl ist zu gro\xE1! Versuche es erneut: "; + } + } + + number = 0; + + //Zusatzaufgabe: Berechne die minimal notwendige Anzahl an Versuchen + std::cout << "\nTreffer! Du hast " << tries << " Versuche gebraucht.\nWenn du ein 2. mal spielen m\x94 \bchtest, gib \"1\" ein. Zum beenden w\x84hle eine beliebige Eingabe: "; + getline(std::cin, input); + stringstream(input) >> randNumber; + std::cout << endl << endl; + if(randNumber == 1) again = randNumber; + } + + return(0); +}