diff --git a/Mathe/Dreiecke.cpp b/Mathe/Dreiecke.cpp index 085186f..e582ee1 100644 --- a/Mathe/Dreiecke.cpp +++ b/Mathe/Dreiecke.cpp @@ -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 diff --git a/Sonstiges/Kreuzende Autos.cpp b/Sonstiges/Kreuzende Autos.cpp index 98275a6..6cd07e4 100644 --- a/Sonstiges/Kreuzende Autos.cpp +++ b/Sonstiges/Kreuzende Autos.cpp @@ -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!"; diff --git a/Sonstiges/Schleifen.cpp b/Sonstiges/Schleifen.cpp index fc48cc1..680e7f7 100644 --- a/Sonstiges/Schleifen.cpp +++ b/Sonstiges/Schleifen.cpp @@ -17,11 +17,7 @@ int main() }while(depth<2); - for(long long idx = 0; idx0) 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> 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]idx; idx2--) if(array[idx2] #include -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=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=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> 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