Advertisement
Randomsurpriseguy

Präsenz2

Nov 16th, 2020
796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.24 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int max(int a, int b){
  5.   return -min(-a,-b);
  6. }
  7.  
  8. int min(int a, int b){
  9.   if(a<b) return a;
  10.   return b;
  11. }
  12.  
  13. bool repr_letter(int in){
  14.   return (in <= 122 && in >=97 || in <= 90 && in >= 65);
  15. }
  16.  
  17. void sort(int* in){//simpler Sortieralgorithmus, ausreichend für ein Array mit Länge 3
  18.   int i=0;
  19.   int *intermed;
  20.   bool change=true;
  21.   while(change){
  22.     change=false;
  23.     i=0;
  24.     while(i< 3-1){
  25.       if(*(in+i) > *(in+i+1)){
  26.         *intermed=*(in+i+1);
  27.         *(in+i+1)=*(in+i);
  28.         *(in+i)=*intermed;
  29.         change=true;
  30.       }
  31.       i++;
  32.     }
  33.  
  34.   }
  35. }
  36.  
  37. int rechne(int x,int y, int z){
  38.   int arr[3]={x,y,z};
  39.   sort(arr);
  40.   cout << (*arr * *(arr+2) + *(arr+1));
  41.   return 0;
  42.  
  43. }
  44.  
  45. bool gerade(int in){
  46.   return (in%2==0);
  47. }
  48.  
  49. void Aufgabe1(){
  50.   char in;
  51.   cout << "Ueberpruefe auf Vokal/Konsonant:";
  52.   cin >> in;
  53.   if(repr_letter(in)){
  54.     if(in == 'a' || in == 'e' || in == 'i' || in == 'o' || in == 'u' || in == 'A' || in == 'E' || in == 'I' || in == 'O' || in == 'U' ){
  55.       cout << "Vokal" << endl;
  56.     }else cout << "Konsonant" << endl;
  57.   }
  58.   else cout << "Kein Buchstabe" << endl;
  59. }
  60.  
  61. void Aufgabe2(){
  62.   char x,y,z;
  63.   cout << "letter 1=";
  64.   cin >> x;
  65.   cout << "letter 2=";
  66.   cin >> y;
  67.   cout << "letter 3=";
  68.   cin >> z;
  69.  
  70.   if(x < y){
  71.     if(z < x){
  72.       cout << z << "," << x << "," << y  << endl; // z<x,x<y -> z<y
  73.     }
  74.     else{
  75.       if(z<y){
  76.         cout << x << "," << z << ","<< y  << endl;
  77.       }
  78.       else cout << x << "," << y << "," <<  z  << endl;
  79.  
  80.     }
  81.   }else{
  82.     if(z > x){
  83.       cout << y << "," << x << ","<<  z  << endl; // z>x, x>y -> z>y
  84.     }
  85.     else{
  86.       if(z>y){
  87.         cout << y << "," << z << "," <<x  << endl;
  88.       }
  89.       else cout << z << "," << y << "," << x  << endl;
  90.  
  91.     }
  92.   }
  93.  
  94.  
  95.  
  96. }
  97.  
  98. void Aufgabe3(){
  99.   int testgerade;
  100.   cout << "Gebe Integer zum Testen ein:";
  101.   cin >> testgerade;
  102.   if(gerade(testgerade)) cout << "Zahl ist gerade." << endl;
  103.   else cout << "Zahl ist ungerade." << endl;
  104. }
  105.  
  106. void Aufgabe4(){
  107.   cout << min(-42,42) << endl;
  108. }
  109.  
  110. void Aufgabe5(){
  111.   rechne(1,3,-2);
  112. }
  113.  
  114. int main(){
  115.  
  116.  
  117.   /*Aufgabe1();
  118.   Aufgabe2();*/
  119.   Aufgabe3();
  120.   Aufgabe4();
  121.   Aufgabe5();
  122.  
  123.   return 0;
  124. }
  125.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement