3 Programme hinzugefügt
This commit is contained in:
parent
ca822e81fc
commit
94b226257b
3 changed files with 144 additions and 0 deletions
46
InsertionSort.cpp
Normal file
46
InsertionSort.cpp
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
#include<iostream>
|
||||||
|
#include<conio.h>
|
||||||
|
#include<string>
|
||||||
|
#include<sstream>
|
||||||
|
|
||||||
|
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<amount-1; idx++) std::cout << array[idx] <<", ";
|
||||||
|
std::cout << array[amount-1] << "\n";
|
||||||
|
|
||||||
|
for(unsigned short idx = 1; idx < amount; idx++)
|
||||||
|
{
|
||||||
|
int temp = array[idx];
|
||||||
|
int idx2 = idx - 1;
|
||||||
|
|
||||||
|
while(idx2>=0 && array[idx2]>temp) array[idx2+1] = array[idx2--];
|
||||||
|
|
||||||
|
array[idx2+1] = temp;
|
||||||
|
|
||||||
|
for(unsigned short idx =0; idx<amount-1; idx++) std::cout << array[idx] << ", ";
|
||||||
|
std::cout << array[amount-1] << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
getch();
|
||||||
|
return(0);
|
||||||
|
}
|
49
SelectionSort.cpp
Normal file
49
SelectionSort.cpp
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
#include<iostream>
|
||||||
|
#include<conio.h>
|
||||||
|
#include<string>
|
||||||
|
#include<sstream>
|
||||||
|
|
||||||
|
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<amount-1; idx++) std::cout << array[idx] << ", ";
|
||||||
|
std::cout << array[amount-1] << "\n";
|
||||||
|
|
||||||
|
for(unsigned short idx = 0; idx<amount-1; idx++)
|
||||||
|
{
|
||||||
|
unsigned short indexMin = idx;
|
||||||
|
for(unsigned short idx2 = idx+1; idx2<amount; idx2++) if(array[idx2]<array[indexMin]) indexMin = idx2;
|
||||||
|
|
||||||
|
if(indexMin!=idx)
|
||||||
|
{
|
||||||
|
long double temp = array[idx];
|
||||||
|
array[idx] = array[indexMin];
|
||||||
|
array[indexMin] = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(unsigned short idx =0; idx<amount-1; idx++) std::cout << array[idx] << ", ";
|
||||||
|
std::cout << array[amount-1] << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
getch();
|
||||||
|
return(0);
|
||||||
|
}
|
49
Zahlen Raten.cpp
Normal file
49
Zahlen Raten.cpp
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
#include<stdlib.h>
|
||||||
|
#include<time.h>
|
||||||
|
#include<iostream>
|
||||||
|
#include<conio.h>
|
||||||
|
#include<string>
|
||||||
|
#include<sstream>
|
||||||
|
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(number<randNumber)
|
||||||
|
{
|
||||||
|
std::cout << "\nDie eingegebene Zahl ist zu klein! Versuche es erneut: ";
|
||||||
|
}
|
||||||
|
if(number>randNumber)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
Reference in a new issue