Advertisement
sebihomie

U5GIP

Nov 7th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. void Ein_Ausgabe()
  7. {
  8.     int ein;
  9.     cout << "Bitte zahl eingeben: ";
  10.     cin >> ein;
  11.     cout << "Das doppelte der Zahl lautet: " << ein*2 << endl << endl;
  12. }
  13.  
  14. void Aus1( double a )
  15. {
  16.     cout << "\nDer Wert der Funktion lautet: " << a << endl << endl;
  17. }
  18.  
  19. char gk( char a )
  20. {
  21.     char r;
  22.     if(a>='A' && a<='Z'){r='+';}
  23.     else if(a>='a' && a<='z'){r='-';}
  24.     else{r='?';}
  25.     return r;
  26. }
  27.  
  28. void swap( int &a, int &b )
  29. {
  30.     int c = a;
  31.     a = b;
  32.     b = c;
  33. }
  34.  
  35. double test_default( double a, double b = 0)
  36. {
  37.     if(b==0){return a*a;}
  38.     else return a*b;
  39. }
  40.  
  41. void setze_variable(string &s)
  42. {
  43.     s = "Teste Call-by-reference";
  44. }
  45.  
  46. int main()
  47. {
  48.     int n;
  49.     cout << "Welche Aufagabe? ( 1 - 7)";
  50.     while(n<1||n>7)
  51.     {
  52.         cin >> n;
  53.     }
  54.    
  55.    
  56.         if(n==1)
  57.         {
  58.             cout << endl << "Aufgabe 1!\n\n";
  59.             Ein_Ausgabe();
  60.         }
  61.  
  62.         else if(n==2)
  63.         {
  64.             cout << endl << "Aufgabe 2!\n\n";
  65.             const double e = 12.6;
  66.             Aus1(e);
  67.         }
  68.    
  69.         else if(n==3)
  70.         {
  71.             cout << endl << "Aufgabe 3!\n\n";
  72.             double f;
  73.             cout << endl << "Bitte Zahl eingeben: ";
  74.             cin >> f;
  75.             Aus1(f);
  76.         }
  77.    
  78.         else if(n==4)
  79.         {
  80.             cout << endl << "Aufgabe 4!\n\n";
  81.             char g,h;
  82.             cout << endl << "Bitte Buchstaben eingeben: ";
  83.             cin >> g;
  84.             h = gk(g);
  85.             cout << endl << h << endl;
  86.         }
  87.        
  88.         else if(n==5)
  89.         {
  90.             cout << endl << "Aufgabe 5!\n\n";
  91.             string s = "text";
  92.             cout << endl << "Text vorher: " << s << endl;
  93.             setze_variable(s);
  94.             cout << endl << "Text nachher: " << s << endl;
  95.         }
  96.  
  97.         else if(n==6)
  98.         {
  99.             cout << endl << "Aufgabe 6!\n\n";
  100.             cout << endl << "Bitte 1 oder 2 Zahlen eingeben: (Bei 0 wird die vorherige Zahl quadriert ";
  101.             double i,j,k;
  102.             cin >> i;
  103.             cin >> j;
  104.             k = test_default(i,j);
  105.             cout << endl << "Lösung: " << k << endl;
  106.         }
  107.  
  108.         else if(n==7)
  109.         {
  110.             cout << endl << "Aufgabe 7!\n\n";
  111.             cout << endl << "Bitte 2 Zahlen eingeben: ";
  112.             int l,m;
  113.             cin >> l;
  114.             cin >> m;
  115.             cout << endl << "Zahlen vorher: a: " << l << "  b: " << m << endl;
  116.             swap(l,m);
  117.             cout << endl << "Zahlen nachher: a: " << l << "  b: " << m << endl;
  118.         }      
  119.  
  120.    
  121.     return 0;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement