• Keine Ergebnisse gefunden

? Truly Exceptional

N/A
N/A
Protected

Academic year: 2021

Aktie "? Truly Exceptional"

Copied!
4
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Truly Exceptional

3/27/2017 1

static int P(std::vector<int>& a, int i){

int res = a.at(i);

try{ return res + P(a,i+1); }

catch (std::out_of_range e) { return 5; } }

static int Q(std::vector<int>& a, int i){

try{ return a.at(i) + Q(a,i+1); }

catch (std::out_of_range e) { return 5; } }

int main() {

std::vector<int> a = {1,2,3,4};

std::cout << P(a,0) << " ";

std::cout << Q(a,0) << "\n";

return 0;

}

?

Was gibt das Programm aus?

(1)[Fehlermeldung]

(2)0, dann [Fehlermeldung]

(3)10, dann [Fehlermeldung]

(4)11, dann [Fehlermeldung]

(5)15, dann [Fehlermeldung]

(6)0, 10

(7)10,10

(8)11,11

(9)11,15

(10)15,15

(2)

Erklärung

3/27/2017 2

?

static int P(std::vector<int>& a, int i){

int res = a.at(i);

try{ return res + P(a,i+1); }

catch (std::out_of_range e) { return 5; } }

static int Q(std::vector<int>& a, int i){

try{ return a.at(i) + Q(a,i+1); }

catch (std::out_of_range e) { return 5; } }

int main() {

std::vector<int> a = {1,2,3,4};

std::cout << P(a,0) << " ";

std::cout << Q(a,0) << "\n";

return 0;

}

P(a,0) ok bis P(a,3), dann try

return P(a,4). Exception in P(a,4) [out of bounds!] dadurch catch block in P(a,3) gibt 5 zurück.

5 + 3 + 2 + 1 = 11

(3)

Erklärung

3/27/2017 3

?

static int P(std::vector<int>& a, int i){

int res = a.at(i);

try{ return res + P(a,i+1); }

catch (std::out_of_range e) { return 5; } }

static int Q(std::vector<int>& a, int i){

try{ return a.at(i) + Q(a,i+1); }

catch (std::out_of_range e) { return 5; } }

int main() {

std::vector<int> a = {1,2,3,4};

std::cout << P(a,0) << " ";

std::cout << Q(a,0) << "\n";

return 0;

}

Q(a,0) ok bis Q(a,3), dann try return Q(a,4) in Q(a,4).

Exception in Q(a,4) [out of

bounds!] dadurch catch block in Q(a,4) gibt 5 zurück.

5 + 4 + 3 + 2 + 1 = 15

(4)

Truly Exceptional

3/27/2017 4

static int P(std::vector<int>& a, int i){

int res = a.at(i);

try{ return res + P(a,i+1); }

catch (std::out_of_range e) { return 5; } }

static int Q(std::vector<int>& a, int i){

try{ return a.at(i) + Q(a,i+1); }

catch (std::out_of_range e) { return 5; } }

int main() {

std::vector<int> a = {1,2,3,4};

std::cout << P(a,0) << " ";

std::cout << Q(a,0) << "\n";

return 0;

}

Was gibt das Programm aus?

(1)[Fehlermeldung]

(2)0, dann [Fehlermeldung]

(3)10, dann [Fehlermeldung]

(4)11, dann [Fehlermeldung]

(5)15, dann [Fehlermeldung]

(6)0, 10 (7)10,10 (8)11,11 (9)11,15 (10)15,15

!

Referenzen

ÄHNLICHE DOKUMENTE

However, purchasing managers at Car-Ter realized that the approaches for planning and monitoring supplier performance still largely follow the notion of “one size fits all.” For most

If the employer unilaterally orders home office work due to the current situation in connection with the coronavirus, the employer would have to provide the employee with

This avalanche, one of the most catastrophic in Savoie (France), had never descended so low in living memory and has never recurred in such proportions since then. However rare it

Karl Burkhard constantly had to explore, discover the function of things, touch them and pick them up.. And he was a passionate collector, first and foremost sticks, stems,

Due to the fact that the peptide assignment for each HLA allelic variant is specific and each pHLA molecule displays a unique landscape to its cognate immune receptor, it

Recognition is only guaranteed for courses/modules executed consistent with the information given in the module descriptions and as agreed on with the person in charge at JMU before

This approach reveals a much shorter and more elegant way to prove the impor- tant maximal regularity for boundary value problems of type (1.1) on cylindrical domains of the

This dissertation introduces Truly Non-cooperative Games – axioms and complimentary negotiation models developed to analyse the human Struggle for Life (cf 5-11) – and presents