neu strukturiert
This commit is contained in:
parent
ec0238ccc6
commit
e9dc6c0f6e
6 changed files with 41 additions and 89 deletions
|
@ -14,7 +14,7 @@ int main()
|
|||
std::cout << "F\x81ge deiner Eingabe \"\xF8\" hinzu um einen Winkel im Gradma\xE1 einzugeben.\n\nGib Seite a oder Winkel alpha ein: ";
|
||||
do
|
||||
{
|
||||
a = 0; alpha = 0;
|
||||
a = 0, alpha = 0;
|
||||
getline(std::cin, input);
|
||||
for(char cha : input) if(cha=='\xF8') a++;
|
||||
|
||||
|
@ -35,7 +35,7 @@ int main()
|
|||
std::cout << "\nGib Seite b oder Winkel beta ein: ";
|
||||
do
|
||||
{
|
||||
b = 0; beta = 0;
|
||||
b = 0, beta = 0;
|
||||
getline(std::cin, input);
|
||||
for(char cha : input) if(cha=='\xF8') b++;
|
||||
|
||||
|
@ -56,7 +56,7 @@ int main()
|
|||
std::cout << "\nGib Seite c oder Winkel gamma ein: ";
|
||||
do
|
||||
{
|
||||
c = 0; gamma = 0;
|
||||
c = 0, gamma = 0;
|
||||
getline(std::cin, input);
|
||||
for(char cha : input) if(cha=='\xF8') c++;
|
||||
|
||||
|
@ -80,33 +80,10 @@ int main()
|
|||
|
||||
if(alpha!=0 && beta!=0 || alpha!=0 && gamma!=0 || beta!=0 && gamma!=0) //WSW
|
||||
{
|
||||
if(alpha==0)
|
||||
{
|
||||
alpha = PI-beta-gamma;
|
||||
b = a*sin(beta)/sin(alpha);
|
||||
c = a*sin(gamma)/sin(alpha);
|
||||
}
|
||||
|
||||
if(beta==0)
|
||||
{
|
||||
beta = PI-alpha-gamma;
|
||||
a = b*sin(alpha)/sin(beta);
|
||||
c = b*sin(gamma)/sin(beta);
|
||||
}
|
||||
|
||||
if(gamma=0)
|
||||
{
|
||||
gamma = PI-alpha-beta;
|
||||
a = c*sin(alpha)/sin(gamma);
|
||||
b = c*sin(beta)/sin(gamma);
|
||||
}
|
||||
|
||||
if(alpha==beta && beta==gamma) //fängt den Sondefall eines gleichseitigen Dreiecks ab, welcher mit der obigen Methode nicht exakt berechnet wird.
|
||||
{
|
||||
a = a+b+c;
|
||||
b = a;
|
||||
c = b;
|
||||
}
|
||||
if(alpha==0) alpha = PI-beta-gamma, b = a*sin(beta)/sin(alpha), c = a*sin(gamma)/sin(alpha);
|
||||
if(beta==0) beta = PI-alpha-gamma, a = b*sin(alpha)/sin(beta), c = b*sin(gamma)/sin(beta);
|
||||
if(gamma=0) gamma = PI-alpha-beta, a = c*sin(alpha)/sin(gamma), b = c*sin(beta)/sin(gamma);
|
||||
if(alpha==beta && beta==gamma) a = a+b+c, b = a, c = b; //fängt den Sondefall eines gleichseitigen Dreiecks ab, welcher mit der obigen Methode nicht exakt berechnet wird.
|
||||
}
|
||||
|
||||
if(c==0 || b==0 || a==0) //SWS berechnet 3. Seite für SSS
|
||||
|
|
|
@ -46,10 +46,7 @@ int main()
|
|||
else if(input=="-") speed -= 5;
|
||||
}
|
||||
|
||||
if(position>ULLONG_MAX)
|
||||
{
|
||||
std::cout << "ERROR: Begegnung kann nicht berechnet werden.";
|
||||
}
|
||||
if(position>ULLONG_MAX) std::cout << "ERROR: Begegnung kann nicht berechnet werden.";
|
||||
|
||||
std::cout << "PROGRAMMENDE!";
|
||||
|
||||
|
|
|
@ -17,11 +17,7 @@ int main()
|
|||
}while(depth<2);
|
||||
|
||||
|
||||
for(long long idx = 0; idx<depth*depth; idx++)
|
||||
{
|
||||
if(idx%depth==0) std::cout << "\n";
|
||||
std::cout << "*";
|
||||
}
|
||||
for(long long idx = 0; idx<depth*depth; std::cout << "*") if(idx++%depth==0) std::cout << "\n";
|
||||
|
||||
|
||||
std::cout << "\n";
|
||||
|
@ -30,7 +26,6 @@ int main()
|
|||
for(long long idx = 0; idx<depth; idx++)
|
||||
{
|
||||
std::cout << "\n";
|
||||
|
||||
for(long long idx2 = 0; idx2<idx; idx2++) std::cout << " ";
|
||||
for(long long idx2 = 0; idx2<depth*2-1-2*idx; idx2++) std::cout << "*";
|
||||
}
|
||||
|
@ -39,24 +34,18 @@ int main()
|
|||
std::cout << "\n\n";
|
||||
|
||||
|
||||
for(long long idx = 0; idx<depth-1; idx++)
|
||||
for(long long idx = 0; idx<depth-1; std::cout << "\n")
|
||||
{
|
||||
for(long long idx2 = 0; idx2<depth-idx-1; idx2++) std::cout << " ";
|
||||
|
||||
std::cout << "*";
|
||||
|
||||
for(long long idx2 = 0; idx2<2*idx-1; idx2++) std::cout << " ";
|
||||
if(idx>0) std::cout << "*";
|
||||
|
||||
std::cout << "\n";
|
||||
if(idx++>0) std::cout << "*";
|
||||
}
|
||||
for(long long idx = 0; idx<2*depth-1; idx++) std::cout << "*";
|
||||
for(long long idx = 0; idx<depth-2; idx++)
|
||||
{
|
||||
std::cout << "\n*";
|
||||
|
||||
for(long long idx2 = 0; idx2<2*depth-3; idx2++) std::cout << " ";
|
||||
|
||||
std::cout << "*";
|
||||
}
|
||||
std::cout << "\n";
|
||||
|
|
|
@ -23,18 +23,17 @@ int main()
|
|||
{
|
||||
int *array = new int[amount];
|
||||
srand(time(0));
|
||||
for(unsigned short idx = 0; idx < amount; idx++) array[idx] = rand()%1000;
|
||||
for(unsigned short idx = 0; idx < amount; array[idx++] = rand()%1000);
|
||||
BubbleSort(array, amount);
|
||||
delete[] array;
|
||||
}
|
||||
else
|
||||
{
|
||||
long double *array = new long double[amount];
|
||||
for(unsigned short idx = 0; idx < amount; idx++)
|
||||
for(unsigned short idx = 0; idx < amount; std::stringstream(input) >> array[idx++])
|
||||
{
|
||||
std::cout << "Gib die " << idx+1 << ". Zahl ein: ";
|
||||
getline(std::cin,input);
|
||||
std::stringstream(input) >> array[idx];
|
||||
}
|
||||
BubbleSort(array, amount);
|
||||
delete[] array;
|
||||
|
@ -60,9 +59,7 @@ void BubbleSort(int *array, unsigned short amount)
|
|||
for(unsigned short idx2 = amount-1; idx2>idx; idx2--) if(array[idx2]<array[idx2-1])
|
||||
{
|
||||
int temp = array[idx2-1];
|
||||
array[idx2-1] = array[idx2];
|
||||
array[idx2] = temp;
|
||||
changed = true;
|
||||
array[idx2-1] = array[idx2], array[idx2] = temp, changed = true;
|
||||
}
|
||||
|
||||
for(unsigned short idx2 = 0; idx2+1<amount; idx2++) std::cout << array[idx2] << ", ";
|
||||
|
@ -86,9 +83,7 @@ void BubbleSort(long double *array, unsigned short amount)
|
|||
for(unsigned short idx2 = amount-1; idx2>idx; idx2--) if(array[idx2]<array[idx2-1])
|
||||
{
|
||||
int temp = array[idx2-1];
|
||||
array[idx2-1] = array[idx2];
|
||||
array[idx2] = temp;
|
||||
changed = true;
|
||||
array[idx2-1] = array[idx2], array[idx2] = temp, changed = true;
|
||||
}
|
||||
|
||||
for(unsigned short idx2 = 0; idx2+1<amount; idx2++) std::cout << array[idx2] << ", ";
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
#include<cstdlib>
|
||||
#include<ctime>
|
||||
|
||||
void InsertionSort(long double *ptr, unsigned short amount);
|
||||
void InsertionSort(int *ptr, unsigned short amount);
|
||||
void InsertionSort(long double *array, unsigned short amount);
|
||||
void InsertionSort(int *array, unsigned short amount);
|
||||
|
||||
int main()
|
||||
{
|
||||
|
@ -23,18 +23,17 @@ int main()
|
|||
{
|
||||
int *array = new int[amount];
|
||||
srand(time(0));
|
||||
for(unsigned short idx = 0; idx < amount; idx++) array[idx] = rand()%1000;
|
||||
for(unsigned short idx = 0; idx < amount; array[idx++] = rand()%1000);
|
||||
InsertionSort(array, amount);
|
||||
delete[] array;
|
||||
}
|
||||
else
|
||||
{
|
||||
long double *array = new long double[amount];
|
||||
for(unsigned short idx = 0; idx < amount; idx++)
|
||||
for(unsigned short idx = 0; idx < amount; std::stringstream(input) >> array[idx++])
|
||||
{
|
||||
std::cout << "Gib die " << idx+1 << ". Zahl ein: ";
|
||||
getline(std::cin,input);
|
||||
std::stringstream(input) >> array[idx];
|
||||
}
|
||||
InsertionSort(array, amount);
|
||||
delete[] array;
|
||||
|
@ -44,42 +43,40 @@ int main()
|
|||
return(0);
|
||||
}
|
||||
|
||||
void InsertionSort(long double *ptr, unsigned short amount)
|
||||
void InsertionSort(long double *array, unsigned short amount)
|
||||
{
|
||||
std::cout << "\n";
|
||||
|
||||
for(unsigned short idx = 0; idx<amount-1; idx++) std::cout << ptr[idx] <<", ";
|
||||
std::cout << ptr[amount-1] << "\n"; //Ausgabe des unsortierten Arrays
|
||||
for(unsigned short idx = 0; idx<amount-1; idx++) std::cout << array[idx] <<", ";
|
||||
std::cout << array[amount-1] << "\n"; //Ausgabe des unsortierten Arrays
|
||||
|
||||
for(unsigned short idx = 1; idx < amount; idx++)
|
||||
{
|
||||
int temp = ptr[idx];
|
||||
int idx2 = idx - 1;
|
||||
int temp = array[idx], idx2 = idx-1;
|
||||
|
||||
while(idx2>=0 && ptr[idx2]>temp) ptr[idx2+1] = ptr[idx2--];
|
||||
ptr[idx2+1] = temp;
|
||||
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 << ptr[idx] << ", ";
|
||||
std::cout << ptr[amount-1] << "\n"; //Ausgabe des Arrays nach jedem Sortierungsschritt
|
||||
for(idx2 = 0; idx2<amount-1; idx2++) std::cout << array[idx2] << ", ";
|
||||
std::cout << array[amount-1] << "\n"; //Ausgabe des Arrays nach jedem Sortierungsschritt
|
||||
}
|
||||
}
|
||||
|
||||
void InsertionSort(int *ptr, unsigned short amount)
|
||||
void InsertionSort(int *array, unsigned short amount)
|
||||
{
|
||||
std::cout << "\n";
|
||||
|
||||
for(unsigned short idx = 0; idx<amount-1; idx++) std::cout << ptr[idx] <<", ";
|
||||
std::cout << ptr[amount-1] << "\n"; //Ausgabe des unsortierten Arrays
|
||||
for(unsigned short idx = 0; idx<amount-1; idx++) std::cout << array[idx] <<", ";
|
||||
std::cout << array[amount-1] << "\n"; //Ausgabe des unsortierten Arrays
|
||||
|
||||
for(unsigned short idx = 1; idx < amount; idx++)
|
||||
{
|
||||
int temp = ptr[idx];
|
||||
int idx2 = idx - 1;
|
||||
int temp = array[idx], idx2 = idx-1;
|
||||
|
||||
while(idx2>=0 && ptr[idx2]>temp) ptr[idx2+1] = ptr[idx2--];
|
||||
ptr[idx2+1] = temp;
|
||||
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 << ptr[idx] << ", ";
|
||||
std::cout << ptr[amount-1] << "\n"; //Ausgabe des Arrays nach jedem Sortierungsschritt
|
||||
for(unsigned short idx2 = 0; idx2<amount-1; idx2++) std::cout << array[idx2] << ", ";
|
||||
std::cout << array[amount-1] << "\n"; //Ausgabe des Arrays nach jedem Sortierungsschritt
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,18 +23,17 @@ int main()
|
|||
{
|
||||
int *array = new int[amount];
|
||||
srand(time(0));
|
||||
for(unsigned short idx = 0; idx < amount; idx++) array[idx] = rand()%1000;
|
||||
for(unsigned short idx = 0; idx < amount; array[idx++] = rand()%1000);
|
||||
SelectionSort(array, amount);
|
||||
delete[] array;
|
||||
}
|
||||
else
|
||||
{
|
||||
long double *array = new long double[amount];
|
||||
for(unsigned short idx = 0; idx < amount; idx++)
|
||||
for(unsigned short idx = 0; idx < amount; std::stringstream(input) >> array[idx++])
|
||||
{
|
||||
std::cout << "Gib die " << idx+1 << ". Zahl ein: ";
|
||||
getline(std::cin,input);
|
||||
std::stringstream(input) >> array[idx];
|
||||
}
|
||||
SelectionSort(array, amount);
|
||||
delete[] array;
|
||||
|
@ -59,11 +58,10 @@ void SelectionSort(long double *array, unsigned short amount)
|
|||
if(indexMin!=idx)
|
||||
{
|
||||
long double temp = array[idx];
|
||||
array[idx] = array[indexMin];
|
||||
array[indexMin] = temp;
|
||||
array[idx] = array[indexMin], array[indexMin] = temp;
|
||||
}
|
||||
|
||||
for(unsigned short idx =0; idx<amount-1; idx++) std::cout << array[idx] << ", ";
|
||||
for(unsigned short idx2 = 0; idx2<amount-1; idx2++) std::cout << array[idx2] << ", ";
|
||||
std::cout << array[amount-1] << "\n"; //Ausgabe des Arrays nach jedem Sortierungsschritt
|
||||
}
|
||||
}
|
||||
|
@ -83,11 +81,10 @@ void SelectionSort(int *array, unsigned short amount)
|
|||
if(indexMin!=idx)
|
||||
{
|
||||
long double temp = array[idx];
|
||||
array[idx] = array[indexMin];
|
||||
array[indexMin] = temp;
|
||||
array[idx] = array[indexMin], array[indexMin] = temp;
|
||||
}
|
||||
|
||||
for(unsigned short idx =0; idx<amount-1; idx++) std::cout << array[idx] << ", ";
|
||||
for(unsigned short idx2 = 0; idx2<amount-1; idx2++) std::cout << array[idx2] << ", ";
|
||||
std::cout << array[amount-1] << "\n"; //Ausgabe des Arrays nach jedem Sortierungsschritt
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue