TINF_Abgaben
Simbuerger_03_Uebung.cpp@2:e26ede163624, 2020-04-21 (annotated)
- Committer:
- Ursukar
- Date:
- Tue Apr 21 18:09:00 2020 +0000
- Revision:
- 2:e26ede163624
- Child:
- 3:5e9d7e9d2fbc
Uebung vom 21.04.2020
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 | 2:e26ede163624 | 51 | if(Monat > 12){ |
Ursukar | 2:e26ede163624 | 52 | Jahr +=1; |
Ursukar | 2:e26ede163624 | 53 | } |
Ursukar | 2:e26ede163624 | 54 | } |
Ursukar | 2:e26ede163624 | 55 | else if(Monat == 2 && Tag > 28) |
Ursukar | 2:e26ede163624 | 56 | { |
Ursukar | 2:e26ede163624 | 57 | Monat += 1; |
Ursukar | 2:e26ede163624 | 58 | Tag = 1; |
Ursukar | 2:e26ede163624 | 59 | } |
Ursukar | 2:e26ede163624 | 60 | else if(Tag > 30) |
Ursukar | 2:e26ede163624 | 61 | { |
Ursukar | 2:e26ede163624 | 62 | Monat += 1; |
Ursukar | 2:e26ede163624 | 63 | Tag =1; |
Ursukar | 2:e26ede163624 | 64 | } |
Ursukar | 2:e26ede163624 | 65 | if(Schaltjahr == 1 && (Monat == 2 && Tag > 28)) |
Ursukar | 2:e26ede163624 | 66 | { |
Ursukar | 2:e26ede163624 | 67 | Monat += 1; |
Ursukar | 2:e26ede163624 | 68 | Tag = 1; |
Ursukar | 2:e26ede163624 | 69 | } |
Ursukar | 2:e26ede163624 | 70 | } |
Ursukar | 2:e26ede163624 | 71 | |
Ursukar | 2:e26ede163624 | 72 | Datum::Datum(){ |
Ursukar | 2:e26ede163624 | 73 | |
Ursukar | 2:e26ede163624 | 74 | } |
Ursukar | 2:e26ede163624 | 75 | |
Ursukar | 2:e26ede163624 | 76 | Datum::Datum(int t, int m, int j) |
Ursukar | 2:e26ede163624 | 77 | { |
Ursukar | 2:e26ede163624 | 78 | |
Ursukar | 2:e26ede163624 | 79 | Tag = t; |
Ursukar | 2:e26ede163624 | 80 | Monat = m; |
Ursukar | 2:e26ede163624 | 81 | Jahr = j; |
Ursukar | 2:e26ede163624 | 82 | }; |
Ursukar | 2:e26ede163624 | 83 | |
Ursukar | 2:e26ede163624 | 84 | int main() |
Ursukar | 2:e26ede163624 | 85 | { |
Ursukar | 2:e26ede163624 | 86 | |
Ursukar | 2:e26ede163624 | 87 | int Tag; |
Ursukar | 2:e26ede163624 | 88 | int Monat; |
Ursukar | 2:e26ede163624 | 89 | int Jahr; |
Ursukar | 2:e26ede163624 | 90 | cout << "Bitte geben Sie ein Datum ein" << endl; |
Ursukar | 2:e26ede163624 | 91 | cout << "Tag: ", cin >> Tag; |
Ursukar | 2:e26ede163624 | 92 | cout << "Monat: ", cin >> Monat; |
Ursukar | 2:e26ede163624 | 93 | cout << "Jahr: ", cin >> Jahr; |
Ursukar | 2:e26ede163624 | 94 | |
Ursukar | 2:e26ede163624 | 95 | |
Ursukar | 2:e26ede163624 | 96 | Datum d(Tag, Monat, Jahr); |
Ursukar | 2:e26ede163624 | 97 | d.berechneDatum(); |
Ursukar | 2:e26ede163624 | 98 | printf("Datum: %d.%d.%d \n", d.leseTag(), d.leseMonat(), d.leseJahr()); |
Ursukar | 2:e26ede163624 | 99 | return 0; |
Ursukar | 2:e26ede163624 | 100 | } |