TINF_Abgaben
Simbuerger_03_Uebung.cpp@3:5e9d7e9d2fbc, 2020-04-27 (annotated)
- Committer:
- Ursukar
- Date:
- Mon Apr 27 14:08:52 2020 +0000
- Revision:
- 3:5e9d7e9d2fbc
- Parent:
- 2:e26ede163624
Jahreswechsel gefixt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Ursukar | 2:e26ede163624 | 1 | ////////////////////////////////////////////////////// |
Ursukar | 2:e26ede163624 | 2 | // // |
Ursukar | 2:e26ede163624 | 3 | // Aufgabe ist es, wenn man ein // |
Ursukar | 2:e26ede163624 | 4 | // Datum eingibt, dass der folgende // |
Ursukar | 2:e26ede163624 | 5 | // Tag angezeigt wird. // |
Ursukar | 2:e26ede163624 | 6 | // Schaltjahre müssen berücksichtigt werden // |
Ursukar | 2:e26ede163624 | 7 | // // |
Ursukar | 2:e26ede163624 | 8 | ////////////////////////////////////////////////////// |
Ursukar | 2:e26ede163624 | 9 | |
Ursukar | 2:e26ede163624 | 10 | #include <stdio.h> |
Ursukar | 2:e26ede163624 | 11 | #include <math.h> |
Ursukar | 2:e26ede163624 | 12 | #include <iostream> |
Ursukar | 2:e26ede163624 | 13 | |
Ursukar | 2:e26ede163624 | 14 | using namespace std; |
Ursukar | 2:e26ede163624 | 15 | |
Ursukar | 2:e26ede163624 | 16 | |
Ursukar | 2:e26ede163624 | 17 | class Datum |
Ursukar | 2:e26ede163624 | 18 | { |
Ursukar | 2:e26ede163624 | 19 | public: |
Ursukar | 2:e26ede163624 | 20 | int Tag; |
Ursukar | 2:e26ede163624 | 21 | int Monat; |
Ursukar | 2:e26ede163624 | 22 | int Jahr; |
Ursukar | 2:e26ede163624 | 23 | |
Ursukar | 2:e26ede163624 | 24 | int berechneDatum(); |
Ursukar | 2:e26ede163624 | 25 | |
Ursukar | 2:e26ede163624 | 26 | int leseTag() {return Tag;}; |
Ursukar | 2:e26ede163624 | 27 | int leseMonat() {return Monat;}; |
Ursukar | 2:e26ede163624 | 28 | int leseJahr() {return Jahr;}; |
Ursukar | 2:e26ede163624 | 29 | |
Ursukar | 2:e26ede163624 | 30 | Datum(); |
Ursukar | 2:e26ede163624 | 31 | Datum(int t, int m, int j); |
Ursukar | 2:e26ede163624 | 32 | }; |
Ursukar | 2:e26ede163624 | 33 | |
Ursukar | 2:e26ede163624 | 34 | int Datum::berechneDatum(){ |
Ursukar | 2:e26ede163624 | 35 | bool Schaltjahr = 0; |
Ursukar | 2:e26ede163624 | 36 | if(Jahr%4 == 0) |
Ursukar | 2:e26ede163624 | 37 | { |
Ursukar | 2:e26ede163624 | 38 | Schaltjahr = 1; |
Ursukar | 2:e26ede163624 | 39 | } |
Ursukar | 2:e26ede163624 | 40 | |
Ursukar | 2:e26ede163624 | 41 | Tag += 1; |
Ursukar | 2:e26ede163624 | 42 | |
Ursukar | 2:e26ede163624 | 43 | if((Monat == 1 || Monat == 3 || Monat == 5 || Monat == 7 || Monat == 8 || Monat == 10 || Monat == 12) && Tag < 31) |
Ursukar | 2:e26ede163624 | 44 | { |
Ursukar | 2:e26ede163624 | 45 | |
Ursukar | 2:e26ede163624 | 46 | if(Tag >= 31) |
Ursukar | 2:e26ede163624 | 47 | { |
Ursukar | 2:e26ede163624 | 48 | Monat += 1; |
Ursukar | 2:e26ede163624 | 49 | Tag = 1; |
Ursukar | 2:e26ede163624 | 50 | } |
Ursukar | 3:5e9d7e9d2fbc | 51 | |
Ursukar | 2:e26ede163624 | 52 | } |
Ursukar | 2:e26ede163624 | 53 | else if(Monat == 2 && Tag > 28) |
Ursukar | 2:e26ede163624 | 54 | { |
Ursukar | 2:e26ede163624 | 55 | Monat += 1; |
Ursukar | 2:e26ede163624 | 56 | Tag = 1; |
Ursukar | 2:e26ede163624 | 57 | } |
Ursukar | 2:e26ede163624 | 58 | else if(Tag > 30) |
Ursukar | 2:e26ede163624 | 59 | { |
Ursukar | 2:e26ede163624 | 60 | Monat += 1; |
Ursukar | 2:e26ede163624 | 61 | Tag =1; |
Ursukar | 2:e26ede163624 | 62 | } |
Ursukar | 3:5e9d7e9d2fbc | 63 | if(Monat > 12){ |
Ursukar | 3:5e9d7e9d2fbc | 64 | Monat = 1; |
Ursukar | 3:5e9d7e9d2fbc | 65 | Jahr +=1; |
Ursukar | 3:5e9d7e9d2fbc | 66 | } |
Ursukar | 2:e26ede163624 | 67 | if(Schaltjahr == 1 && (Monat == 2 && Tag > 28)) |
Ursukar | 2:e26ede163624 | 68 | { |
Ursukar | 2:e26ede163624 | 69 | Monat += 1; |
Ursukar | 2:e26ede163624 | 70 | Tag = 1; |
Ursukar | 2:e26ede163624 | 71 | } |
Ursukar | 2:e26ede163624 | 72 | } |
Ursukar | 2:e26ede163624 | 73 | |
Ursukar | 2:e26ede163624 | 74 | Datum::Datum(){ |
Ursukar | 2:e26ede163624 | 75 | |
Ursukar | 2:e26ede163624 | 76 | } |
Ursukar | 2:e26ede163624 | 77 | |
Ursukar | 2:e26ede163624 | 78 | Datum::Datum(int t, int m, int j) |
Ursukar | 2:e26ede163624 | 79 | { |
Ursukar | 2:e26ede163624 | 80 | |
Ursukar | 2:e26ede163624 | 81 | Tag = t; |
Ursukar | 2:e26ede163624 | 82 | Monat = m; |
Ursukar | 2:e26ede163624 | 83 | Jahr = j; |
Ursukar | 2:e26ede163624 | 84 | }; |
Ursukar | 2:e26ede163624 | 85 | |
Ursukar | 2:e26ede163624 | 86 | int main() |
Ursukar | 2:e26ede163624 | 87 | { |
Ursukar | 2:e26ede163624 | 88 | |
Ursukar | 2:e26ede163624 | 89 | int Tag; |
Ursukar | 2:e26ede163624 | 90 | int Monat; |
Ursukar | 2:e26ede163624 | 91 | int Jahr; |
Ursukar | 2:e26ede163624 | 92 | cout << "Bitte geben Sie ein Datum ein" << endl; |
Ursukar | 2:e26ede163624 | 93 | cout << "Tag: ", cin >> Tag; |
Ursukar | 2:e26ede163624 | 94 | cout << "Monat: ", cin >> Monat; |
Ursukar | 2:e26ede163624 | 95 | cout << "Jahr: ", cin >> Jahr; |
Ursukar | 2:e26ede163624 | 96 | |
Ursukar | 2:e26ede163624 | 97 | |
Ursukar | 2:e26ede163624 | 98 | Datum d(Tag, Monat, Jahr); |
Ursukar | 2:e26ede163624 | 99 | d.berechneDatum(); |
Ursukar | 2:e26ede163624 | 100 | printf("Datum: %d.%d.%d \n", d.leseTag(), d.leseMonat(), d.leseJahr()); |
Ursukar | 2:e26ede163624 | 101 | return 0; |
Ursukar | 2:e26ede163624 | 102 | } |