Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.73 KB | None | 0 0
  1. // ConsoleApplication2.cpp: Definiert den Einstiegspunkt für die Konsolenanwendung.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. void Aufgabe1() {
  9.     for (int i = 0; i < 10; i++) {
  10.         cout << i;
  11.     }
  12.     cout << endl;
  13. }
  14. void Aufgabe2() {
  15.     int a = 0;
  16.     while (a <= 10) {
  17.         cout << a;
  18.         a++;
  19.     }
  20. }
  21. void Aufgabe3() {
  22.     int laenge = 0;
  23.     char mycstring[100] = "Ein alter cString";
  24.     char *Buchstabe3 = mycstring + 2;                                       //* bedeutet Behandlung als Pointer
  25.  
  26.     char ergebnis1 = 0;
  27.     char ergebnis2 = 0;
  28.  
  29.     cout << "Adresse Buchstabe 0 ist: " <<(long) mycstring << endl;
  30.     cout << "Adresse Buchstabe 2 ist: " <<(long) Buchstabe3 << endl;
  31.  
  32.     ergebnis1 = mycstring[2];                                               //*(mycstring+2)
  33.     ergebnis2 = *Buchstabe3;
  34.  
  35.     cout << "1: " << ergebnis1 << " 2: " << ergebnis2 << endl;
  36.  
  37.     laenge = (int)strlen(mycstring);
  38.     cout << "Der String - ";
  39.     cout << mycstring;
  40.     cout << " - ist " << laenge << " Zeichen lang" << endl;
  41.  
  42. }
  43. void Palindrom1() {
  44.     char test1[100] = "nochnxdrin";
  45.  
  46.     cout << "Bitte Teststring eingeben: ";
  47.     cin >> test1;
  48.  
  49.     int laenge = (int)strlen(test1);
  50.     for (int index = laenge-1; index >= 0; index--) {
  51.         //cout << test1[index];
  52.         cout << *(test1 + index);
  53.     }
  54.     cout << endl;
  55. }
  56.  
  57. void Palindromchecker() {
  58.     char test1[100] = "nochnxdrin";
  59.     char lower[100];
  60.     bool palin = false;
  61.  
  62.     cout << "Bitte Teststring eingeben: ";
  63.     cin >> test1;
  64.  
  65.     int laenge = (int)strlen(test1);
  66.     for(int i=0;i<laenge;i++){
  67.         lower[i] = tolower(test1[i]);
  68.  
  69.         cout << lower[i];
  70.     }
  71.     cout << '\n';
  72.  
  73.     int ir=laenge, iv=0;
  74.     do {
  75.         if (lower[ir - 1] == lower[iv]) palin = true;
  76.         else {
  77.             palin = false;
  78.             break;
  79.         };
  80.  
  81.         cout << " ir= " << test1[ir - 1] << " iv= " << test1[iv] << " vgl= " << palin << endl;
  82.         ir--;
  83.         iv++;
  84.  
  85.     } while (ir!=0);
  86.  
  87.     if (palin) {
  88.         cout << "das ist ein Palindrom";
  89.     }
  90.     else cout << "das ist kein Palindrom";
  91.     cout << endl;
  92. }
  93.  
  94. int MiniMenue() {
  95.     int option;
  96.  
  97.     do {
  98.         cout << "geben sie einen Menüpunkt ein" << endl;
  99.  
  100.         do {                                                            //warten auf Tastendruck
  101.             if (!cin) {
  102.                 cin.clear();
  103.                 cin.ignore(numeric_limits<streamsize>::max(), '\n');
  104.             }
  105.  
  106.         } while (!(cin >> option));                
  107.  
  108.         switch ((int)option)                                            //(int) varible ist als int zu behandeln
  109.         {
  110.         case 0: cout << "......GOODBYE......" << endl;
  111.             break;
  112.  
  113.         case 1:
  114.             Aufgabe1();
  115.             break;
  116.         default: cout << ".....Kenn ich nicht....." << endl;
  117.             break;
  118.  
  119.         case 2:
  120.             Aufgabe2();
  121.             break;
  122.  
  123.         case 3:
  124.             Aufgabe3();
  125.             break;
  126.  
  127.         case 4:
  128.             Palindrom1();
  129.             break;
  130.         case 5:
  131.             Palindromchecker();
  132.             break;
  133.         }
  134.     } while (option != 0);                          //laufen bis 0 eingegeben wird
  135.  
  136.     return option;
  137. }
  138.  
  139. int main()
  140. {
  141.     int Auswahl;
  142.     Auswahl = MiniMenue();
  143.     return 0;
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement