/*********************** 07-2-S.TXT ************************** *********** Prof. Dr. B. Bartning ***************************/ // Hints for solutions of 07-2.CPP (b) Removing function declaration not allowed. After reordering the text (definition of "rationalCalc" before "main"): permitted. (c) Altering the declaration only: Compiler: warnings (variables k,l,m,n used before initializing) Linker: error (unresolved name: function "rationalCalc" with six int's not found) After altering the definition, too: Compiler warnings just as above. No linker error. Not sensible because calculation results (from "rationalCalc") are not available in the main program. (d) Altering reference into constant reference: not permitted because parameters are changed in the function. Altering value parameter into reference: permitted. But a call of "rationalCalc(i+j,...)" is not permitted. Altering into constant references: possible. Now the call "rationalCalc(i+j,...)" is allowed, too. (e) Function definition (declaration: do it yourself!) bool safeDivMult(double val1, double val2, double "ient, double &product) { // multiplication permitted, anyway: product = val1*val2; // division not permitted if denominator (val2) equals zero: if (val2==0.0) { quotient = 0.0; // not correct, but a definite value return false; } // the following: possible also as "else" branch of the "if" above quotient = val1/val2; return true; } (f) Function definition (declaration: do it yourself!) void plus1(int &val) // parameter must be a non-constant reference! // (call by value would be permitted, but you would not // have any altered value after function call!) { val=val+1; // or: val+=1; // or: ++val; // or: val++; // prefix or postfix increment possible because only side effect wanted } //********************************************************************************