Created
November 10, 2015 12:01
-
-
Save leolabs/627d45a6f7a51ae2e532 to your computer and use it in GitHub Desktop.
OF6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| string backwards(string input) { | |
| string tmp = ""; | |
| int length = (int) input.length(); | |
| while(length-- > 0) { | |
| tmp += input.at(length); | |
| } | |
| return tmp; | |
| } | |
| bool checkString(string input) { | |
| for(int i = 0; i < input.length(); i++) { | |
| if(input.at(i) > 'z' || input.at(i) < 'a') return false; | |
| } | |
| return true; | |
| } | |
| void aufgabe1() { | |
| string input = ""; | |
| // Daten abfragen | |
| while(true) { | |
| cout << "Text = ? "; | |
| input = ""; | |
| getline(cin, input); | |
| if(checkString(input)) break; | |
| } | |
| // Daten ausgeben | |
| if(input.compare(backwards(input)) == 0) { | |
| cout << "Das eingegebene Wort ist ein Palindrom." << endl; | |
| }else{ | |
| cout << "Das eingegebene Wort ist KEIN Palindrom." << endl; | |
| } | |
| } | |
| void aufgabe2() { | |
| int numbers[5] = {0}; | |
| // Daten abfragen | |
| for(int i = 0; i < 5; i++) { | |
| int number = 0; | |
| while(true) { | |
| cout << "Bitte geben Sie die " << i + 1 << ". Zahl ein: ? "; | |
| cin >> number; | |
| if(number >= 0 && number <= 9) break; | |
| } | |
| numbers[i] = number; | |
| } | |
| // Daten ausgeben | |
| for(int i = 0; i < 5; i++) { | |
| cout << i+1; | |
| for(int j = 0; j < numbers[i]; j++) { | |
| cout << "*"; | |
| } | |
| cout << endl; | |
| } | |
| cout << " 123456789"; | |
| } | |
| int main() { | |
| aufgabe2(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment