Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication2.cpp: Definiert den Einstiegspunkt für die Konsolenanwendung.
- //
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- void Aufgabe1() {
- for (int i = 0; i < 10; i++) {
- cout << i;
- }
- cout << endl;
- }
- void Aufgabe2() {
- int a = 0;
- while (a <= 10) {
- cout << a;
- a++;
- }
- }
- void Aufgabe3() {
- int laenge = 0;
- char mycstring[100] = "Ein alter cString";
- char *Buchstabe3 = mycstring + 2; //* bedeutet Behandlung als Pointer
- char ergebnis1 = 0;
- char ergebnis2 = 0;
- cout << "Adresse Buchstabe 0 ist: " <<(long) mycstring << endl;
- cout << "Adresse Buchstabe 2 ist: " <<(long) Buchstabe3 << endl;
- ergebnis1 = mycstring[2]; //*(mycstring+2)
- ergebnis2 = *Buchstabe3;
- cout << "1: " << ergebnis1 << " 2: " << ergebnis2 << endl;
- laenge = (int)strlen(mycstring);
- cout << "Der String - ";
- cout << mycstring;
- cout << " - ist " << laenge << " Zeichen lang" << endl;
- }
- void Palindrom1() {
- char test1[100] = "nochnxdrin";
- cout << "Bitte Teststring eingeben: ";
- cin >> test1;
- int laenge = (int)strlen(test1);
- for (int index = laenge-1; index >= 0; index--) {
- //cout << test1[index];
- cout << *(test1 + index);
- }
- cout << endl;
- }
- void Palindromchecker() {
- char test1[100] = "nochnxdrin";
- char lower[100];
- bool palin = false;
- cout << "Bitte Teststring eingeben: ";
- cin >> test1;
- int laenge = (int)strlen(test1);
- for(int i=0;i<laenge;i++){
- lower[i] = tolower(test1[i]);
- cout << lower[i];
- }
- cout << '\n';
- int ir=laenge, iv=0;
- do {
- if (lower[ir - 1] == lower[iv]) palin = true;
- else {
- palin = false;
- break;
- };
- cout << " ir= " << test1[ir - 1] << " iv= " << test1[iv] << " vgl= " << palin << endl;
- ir--;
- iv++;
- } while (ir!=0);
- if (palin) {
- cout << "das ist ein Palindrom";
- }
- else cout << "das ist kein Palindrom";
- cout << endl;
- }
- int MiniMenue() {
- int option;
- do {
- cout << "geben sie einen Menüpunkt ein" << endl;
- do { //warten auf Tastendruck
- if (!cin) {
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- }
- } while (!(cin >> option));
- switch ((int)option) //(int) varible ist als int zu behandeln
- {
- case 0: cout << "......GOODBYE......" << endl;
- break;
- case 1:
- Aufgabe1();
- break;
- default: cout << ".....Kenn ich nicht....." << endl;
- break;
- case 2:
- Aufgabe2();
- break;
- case 3:
- Aufgabe3();
- break;
- case 4:
- Palindrom1();
- break;
- case 5:
- Palindromchecker();
- break;
- }
- } while (option != 0); //laufen bis 0 eingegeben wird
- return option;
- }
- int main()
- {
- int Auswahl;
- Auswahl = MiniMenue();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement