c++/max.cpp
author Markus Bröker<broeker.markus@googlemail.com>
Sun, 10 Feb 2019 13:17:01 +0100
changeset 173 374a86886bc5
parent 165 f551b78c3eee
permissions -rw-r--r--
LAST-DIGIT-BUG: INCREMENT before LF
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
165
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     1
#include <iostream>
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     2
#include <exception>
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     3
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     4
using namespace std;
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     5
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     6
template<class T>
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
void maxx(T a, T b) {
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     8
    if (a > b)
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     9
        cout << b << endl;
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    10
    else
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    11
        cout << a << endl;
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
}
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    13
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    14
void maxx(int a, int b) {
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    15
    cout << "handle ints special..." << endl;
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    16
}
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    17
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    18
int main(int argc, char **argv)
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    19
{
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    20
    double d1=3.2, d2=5.2;
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    22
    try {
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    23
        maxx(3.5, 5.1);
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    24
        maxx(5, 1);
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    25
        maxx(d1, d2);
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    26
    } catch (exception &e) {
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    27
        cout << e.what();
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    28
    }
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    29
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    30
    return 0;
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    31
}