// Copyright Amruth N. Kumar, amruth@computer.org // No parameter, void return type - DON'T USE, can learn from other combinations // // ********** Function definition **************** // Category constraints: One parameter(s) passed by value only, NON-void return type // // 100 // Function.Definition.Local variable.Name overlap // Local variable with same name as in caller // 125 // Function.Definition.Multiple return statements - 125 // Multiple return statements in function definition // // 175 - TO DO // Program.Program does not contain the function main() // Program does not contain main() function // 200 // Function.Definition.return statement missing in the definition of a function with non-void return type // Missing return statement in definition // 225 // Function.Definition.Data type of the value in the return statement is incompatible with the return type of the function // Incorrect type of returned value // 250 // Function.Definition.Return is not the last statement in the function // return statement followed by unreachable statements at the end // 275 // Function.Definition.Formal parameter is re-declared as a local variable in the function // Parameters re-declared as local variables // // // *********** Function call *************** // // Learning objectives that will be met elsewhere // Call in output statement // Call in expression // Call as standalone statement // Zero parameters.. // // 300 // Function.Call.Call as expression // Calling a function with a non-void return type // 325 - TO DO // Function.Call.Calls to multiple functions as statements // Calls to multiple functions // 350 - TO DO // Function.Call.Multiple calls to the same function // Multiple calls to the same function // 375 - TO DO // Function.Call.Chained // main calls fun1 calls fun2 // // // 400 // Function.Call.Function is called before it is defined/prototyped // Function is called before it is defined (C++ only) // 425 // Function.Call.Value returned by the function is ignored by the caller // return value of the function is ignored // 450 // Function.Call.Caller tries to use the value returned by a function with void return type // Call in an expression // 475 // Function.Call.Data type of the value returned by the function call is incompatible with the expected data type in the caller // Returned type incompatible with expression in which it is called // // ******** Parameter Passing ************** // Category constraints: Parameter(s) passed by value only (void return type) // // 500 // Function.Parameter.Value.Variable.One // Call with 1 parameter (variable) passed by value // 525 // Function.Parameter.Value.Variable.Many // Call with many parameters (variables) passed by value // 550 // Function.Parameter.Value.Variable.Repeated // Call with same variable repeated multiple times as parameter // 575 // Function.Parameter.Value.Constant // Call with literal constants as actual parameters // 600 // Function.Parameter.Value.Expression // Call with expressions as actual parameters // // 625 // Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition // Call with incorrect number of parameters // 650 // Function.Parameter.Data type of the actual parameter in the call is incompatible with the data type of the formal parameter in the definition // Call with incorrect types/order of parameters // // // 700 - TO DO // Function.Parameter.Reference.Variable.One // Call with 1 parameter (variable) passed by reference // 725 - TO DO // Function.Parameter.Reference.Variable.Many // Call with many parameters (variables) passed by reference // 750 - TO DO // Function.Parameter.Reference.Variable.Repeated // Call with same variable repeated multiple times as parameter by reference // // // 800 - To DO // Function.Parameter.Reference.Constant or expression is passed by reference // Call with literal constant/expression as actual parameter // // // // 900 - TO DO // Passed by a mix of value and reference:.. // Prototype // ----------------------------------------------------------------------------------------------------------------- // ***************** ADVANCED TOPICS ******************* // // 1000 - TO DO // Function.Call.Calls to multiple functions in an expression // Multiple calls in an expression // 1025 - TO DO // Function.Parameter.Value.FunctionCall // Call with function call as actual parameter // // 1100 - TO DO // Function.Parameter.Pointer // // 1200 - TO DO // Function.Definition.Default.Correct // Definition with default values for parameters - C++ only // 1225 - TO DO // Function.Definition.Default.Error.Definition // Incorrect use of default values in definition // 1250 - TO DO // Function.Definition.Default.Error.Call // Incorrect use of default values in call // 1300 - // Function.Call.Recursive.Tail.Side effect // Recursive function calls - tail recursive, i.e., local work before recursive call, result is printed // 1325 - // Function.Call.Recursive.Tail.Scalar output // Recursive function calls - tail recursive, i.e., local work before recursive call, result is returned // 1350 - // Function.Call.Recursive.Tail.Vector output // Recursive function calls - tail recursive, i.e., local work before recursive call, result is passed by reference // 1400 - // Function.Call.Recursive.Head.Side effect // Recursive function calls - head recursive, i.e., local work after recursive call, result is printed // 1425 - // Function.Call.Recursive.Head.Scalar output // Recursive function calls - head recursive, i.e., local work after recursive call, result is returned // 1450 - // Function.Call.Recursive.Head.Vector output // Recursive function calls - head recursive, i.e., local work after recursive call, result is passed by reference // 1500 - // Function.Call.Recursive.Mid.Side effect // Recursive function calls - mid recursive, i.e., local work both before and after recursive call, result is printed // 1525 - // Function.Call.Recursive.Mid.Scalar output // Recursive function calls - mid recursive, i.e., local work both before and after recursive call, result is returned // 1550 - // Function.Call.Recursive.Mid.Vector output // Recursive function calls - mid recursive, i.e., local work both before and after recursive call, result is passed by reference // 1600 - TO DO // Function.Call.Recursive.Multiple // Multiple recursive function calls in the same statement // Notes: We could have had // Multiple.Side Effect, Multiple.Scalar Output and Multiple.Vector Output. // BUT, Multiple.Side Effect and Multiple.Vector Output problems are pretty much // two instances of Head/Tail versions, back to back - No extra synergy is involved. // On the other hand, Multiple.Scalar Output expects the user to combine the results of the two recursive calls // which is the synergy lacking in the other two cases. // So, only Scalar Output is considered for Multiple recursion. // Similarly, Recursive.Indirect could be another learning objective // where f(x) calls g(x) which in turn calls f(x). // But, this is is applying regular recursion one at a time, so, we can skip. // ----------------------------------------------------------------------------------------------------------------- // OLD SCHEME: - All covered in new scheme above // This is the master plan for function // // Definition cases are probably only for synthesis // Definition // Return // void // non-void // // Parameter // none // one // many // // Return statement // // Local Variables // unique // conflicting with caller's local variables // // Call // // As // statement // expression // // parameter // // parameter passing // Value // Reference // ValueResult // Result // // Called // Once // Multiple // Recursive // // Prototype // // ------------------------------------------------------------------- // Other factors that affect template hardness: // Function Definition: // Body: // Just a print statement // a constant // a variable // a simple expression involving local variables // An if-else statement // A loop // ---------------------------------------------------- // ********** Function definition **************** // Category constraints: One parameter(s) passed by value only, NON-void return type // ---------------------------------------------------- // 100 // Function.Definition.Local variable.Name overlap // Local variable with same name as in caller // Design parameters // call: as statement // parameters: none (100), 1 (105) // : by value // local variables: none # 100 Function.Definition.Local variable.Name overlap > {(){ = ;<<;}(){; = ;();<<;}} > Type: output Hardness: 20 # 101 Function.Definition.Local variable.Name overlap > {(){; = ;<<;}(){ = ;<<;();}} > Type: output Hardness: 20 # 102 Function.Definition.Local variable.Name overlap > {(){; = ;<<;}(){();; = ;<<;}} > Type: output Hardness: 20 # 105 Function.Definition.Local variable.Name overlap ? Function.Parameter.Value.Variable.One > {(){<<; = ;<<;}(){; = ;(); = ;<<;}} > Type: output Hardness: 20 # 106 Function.Definition.Local variable.Name overlap ? Function.Parameter.Value.Variable.One > {(){ = + 1;<<;}(){ = ; = ;();<<;}} > Type: output Hardness: 20 # 107 Function.Definition.Local variable.Name overlap ? Function.Parameter.Value.Variable.One > {(){ = * 10;<<;}(){ = ; = ;();<<;<<;}} > Type: output Hardness: 20 // ---------------------------------------------------- // 125 // Function.Definition.Multiple return statements // Multiple return statements in function definition // Design parameters // call: as expression // parameters: none (125), 1 (135) // : by value // local variables: none // Callee does not modify parameter passed by value # 125 Function.Definition.Multiple return statements ? Function.Call.Call as expression > {(){ = ;if( > ){ return - 1; } else { return + 1; }}(){<< ();}} > Type: output Hardness: 30 # 126 Function.Definition.Multiple return statements ? Function.Call.Call as expression > {(){; = ; if( >= ){return ;}<< ; return + 1;}(){; = ();<<;}} > Type: output Hardness: 30 # 127 Function.Definition.Multiple return statements ? Function.Call.Call as expression > {(){ = ; if( != ){ << ; return ; } << ; return ;}(){ = ();<<;}} > Type: output Hardness: 30 # 128 Function.Definition.Multiple return statements ? Function.Call.Call as expression > {(){ = ; if( < ) { return 10 - ;} else {return + 10;} }(){ = ();<<;}} > Type: output Hardness: 30 # 129 Function.Definition.Multiple return statements ? Function.Call.Call as expression > {(){ = ; if( <= ) { = * 10;return ;} else { = * 100; return + 1; }}(){<< ();}} > Type: output Hardness: 30 # 130 Function.Definition.Multiple return statements ? Function.Call.Call as expression > {(){ = ; if( == ) { return * 2;} else { = - 1; return ;}}(){; = ();<<;}} > Type: output Hardness: 30 // Callee does not modify parameter passed by value # 135 Function.Definition.Multiple return statements ? Function.{Parameter.Value.Variable.One,Call.Call as expression} > {(){if( != ){ return ; } else { return ; }}(){ = ;<< ();}} > Type: output Hardness: 40 # 136 Function.Definition.Multiple return statements ? Function.{Parameter.Value.Variable.One,Call.Call as expression} > {(){<< ; if( < ){return ;} = + 1; return ;}(){ = ; = ();<<;}} > Type: output Hardness: 40 # 137 Function.Definition.Multiple return statements ? Function.{Parameter.Value.Variable.One,Call.Call as expression} > {(){<<; if( >= ){ << ; return ; } << ; return ;}(){ = ;<< ();}} > Type: output Hardness: 40 # 138 Function.Definition.Multiple return statements ? Function.{Parameter.Value.Variable.One,Call.Call as expression} > {(){if( == ) { return 10 - ;} else {return + 10;} }(){ = ; = ();<<;}} > Type: output Hardness: 40 # 139 Function.Definition.Multiple return statements ? Function.{Parameter.Value.Variable.One,Call.Call as expression} > {(){<<; if( > ) { = - ;return + 1;} = + ; return - 1; }(){ = ;<< ();}} > Type: output Hardness: 40 # 140 Function.Definition.Multiple return statements ? Function.{Parameter.Value.Variable.One,Call.Call as expression} > {(){<< ; ; if( <= ) { = * 2; return ;} else { = ; return + 1;}}(){ = ;; = ();<<;}} > Type: output Hardness: 40 // ---------------------------------------------------- // 175 // Program.Program does not contain the function main() // Program does not contain main() // Design parameters // call: none // parameters: none (TO DO), 1 (TO DO) // : by value // local variables: none // # 175 // Function.Definition.Program does not contain the function main() // > // {(){; = ;(,);<<;}(,){; = ;<<;}} // > // Type: debug // Hardness: 50 // ---------------------------------------------------- // 200 // Function.Definition.return statement missing in the definition of a function with non-void return type // Missing return statement in definition // Design parameters // call: as statement // parameters: none // local variables: none (200), 1 (210) // Call in output, assignment, initialization, re-ssignment, in expression // return statement has constant, variable or expression # 200 Function.Definition.return statement missing in the definition of a function with non-void return type > {(){<< ;}(){<< ();<< ;}} > Type: debug Hardness: 20 # 201 Function.Definition.return statement missing in the definition of a function with non-void return type > {(){<< - ;}(){; = ();<< ;}} > Type: debug Hardness: 20 # 202 Function.Definition.return statement missing in the definition of a function with non-void return type > {(){<< * ;}(){ = ();<<;}} > Type: debug Hardness: 20 # 203 Function.Definition.return statement missing in the definition of a function with non-void return type > {(){<< * ;}(){ = ;<<; = ();<<;}} > Type: debug Hardness: 20 # 204 Function.Definition.return statement missing in the definition of a function with non-void return type > {(){<< ;}(){ = ; = () - ;<<;}} > Type: debug Hardness: 20 # 210 Function.Definition.return statement missing in the definition of a function with non-void return type > {(){ = ;<< ;}(){<< ();}} > Type: debug Hardness: 30 # 211 Function.Definition.return statement missing in the definition of a function with non-void return type > {(){; = + ;<< ;}(){; = ();<<;}} > Type: debug Hardness: 30 # 212 Function.Definition.return statement missing in the definition of a function with non-void return type > {(){ = ;<< * 10;}(){ = ();<<;}} > Type: debug Hardness: 30 # 213 Function.Definition.return statement missing in the definition of a function with non-void return type > {(){ = ;<< * ;}(){ = ;<<; = ();<<;}} > Type: debug Hardness: 30 # 214 Function.Definition.return statement missing in the definition of a function with non-void return type > {(){ = * 10;<< ;}(){; = () + ;<<;}} > Type: debug Hardness: 30 # 215 Function.Definition.return statement missing in the definition of a function with non-void return type > {(){ = ; = * ;<< ;}(){; = () / ;<<;}} > Type: debug Hardness: 30 // ---------------------------------------------------- // 225 // Function.Definition.Data type of the value in the return statement is incompatible with the return type of the function // Incorrect type of returned value // Design parameters // call: as statement // parameters: none // local variables: none - too subtle without local variables, 1 (225), 2 (235) // Call in output, assignment, initialization, re-ssignment, in expression // return statement has constant, variable or expression # 225 Function.Definition.Data type of the value in the return statement is incompatible with the return type of the function > {(){ = ;return ;}(){<< ();}} > Type: debug Hardness: 20 # 226 Function.Definition.Data type of the value in the return statement is incompatible with the return type of the function > {(){; = + ;return ;}(){; = ();<<;}} > Type: debug Hardness: 20 # 227 Function.Definition.Data type of the value in the return statement is incompatible with the return type of the function > {(){ = ;return + 10;}(){ = ();<<;}} > Type: debug Hardness: 20 # 228 Function.Definition.Data type of the value in the return statement is incompatible with the return type of the function > {(){ = ;return * ;}(){ = ;<<; = ();<<;}} > Type: debug Hardness: 20 # 229 Function.Definition.Data type of the value in the return statement is incompatible with the return type of the function > {(){ = ; = * 10;return ;}(){; = () + 1;<<;}} > Type: debug Hardness: 20 # 230 Function.Definition.Data type of the value in the return statement is incompatible with the return type of the function > {(){ = ; = * 2;return ;}(){; = () / 2;<<;}} > Type: debug Hardness: 20 # 235 Function.Definition.Data type of the value in the return statement is incompatible with the return type of the function > {(){ = ;<<; = / 2;return ;}(){<< ();}} > Type: debug Hardness: 30 # 236 Function.Definition.Data type of the value in the return statement is incompatible with the return type of the function > {(){ = ;<<; = + ;return ;}(){ = ();<<;}} > Type: debug Hardness: 30 # 237 Function.Definition.Data type of the value in the return statement is incompatible with the return type of the function > {(){ = ; = + 10;return ;}(){; = ; = ();<<;}} > Type: debug Hardness: 30 # 238 Function.Definition.Data type of the value in the return statement is incompatible with the return type of the function > {(){ = ; = * ;return ;}(){ = ;<<; = ();<<;}} > Type: debug Hardness: 30 # 239 Function.Definition.Data type of the value in the return statement is incompatible with the return type of the function > {(){ = ; = 10 - ;return ;}(){; = () + ;<<;}} > Type: debug Hardness: 30 # 240 Function.Definition.Data type of the value in the return statement is incompatible with the return type of the function > {(){ = ; = * 2;return ;}(){; = () * 2;<<;}} > Type: debug Hardness: 30 // ---------------------------------------------------- // 250 // Function.Definition.return statement is not the last statement in the function // Design parameters // call: as statement // parameters: none // local variables: none (250), 1 (260) // Call in output, assignment, initialization, re-ssignment, in expression // return statement has constant, variable or expression // Callee does not modify parameter passed by value # 250 Function.Definition.return statement is not the last statement in the function > {(){<< ;return ;<< + 1;}(){<< ();}} > Type: debug Hardness: 20 # 251 Function.Definition.return statement is not the last statement in the function > {(){<< ;<< ;return - ;<< - ;}(){ = ();<<;}} > Type: debug Hardness: 20 # 252 Function.Definition.return statement is not the last statement in the function > {(){<< + 10;return ;<< * 10;}(){ = ();<<;}} > Type: debug Hardness: 20 # 253 Function.Definition.return statement is not the last statement in the function > {(){<< * 2;return ;<< * ;}(){ = ;<<; = ();<<;}} > Type: debug Hardness: 20 # 254 Function.Definition.return statement is not the last statement in the function > {(){<< / 2;return ;<< % 2;}(){ = ;<<; = + ();<<;}} > Type: debug Hardness: 20 // Callee does not modify parameter passed by value # 260 Function.Definition.return statement is not the last statement in the function > {(){ = ;return ;<< ;}(){<< ();}} > Type: debug Hardness: 30 # 261 Function.Definition.return statement is not the last statement in the function > {(){ = + ;return ;<< ;<< ;}(){; = ();<<;}} > Type: debug Hardness: 30 # 262 Function.Definition.return statement is not the last statement in the function > {(){ = ;return * 10;<< * 100;}(){ = ();<<;}} > Type: debug Hardness: 30 # 263 Function.Definition.return statement is not the last statement in the function > {(){ = ;return * ;<< * ;}(){ = ;<<; = ();<<;}} > Type: debug Hardness: 30 # 264 Function.Definition.return statement is not the last statement in the function > {(){ = ;return ; = * 10;<< ;}(){; = () + 1;<<;}} > Type: debug Hardness: 30 # 265 Function.Definition.return statement is not the last statement in the function > {(){ = ;return ; = * 2;<< ;}(){; = () / 2;<<;}} > Type: debug Hardness: 30 // Works, but line numbers are not correct // # 270 // Function.Definition.return statement is not the last statement in the function // > // {(){ = ; if( == ) { return * 2;<< ;<< - 1;} else { = - 1; return ;<< ;<< + 1;}}(){; = ();<<;}} // > // Type: output // Hardness: 30 // ---------------------------------------------------- // 275 // Function.Definition.Formal parameter is re-declared as a local variable in the function // Function.Definition.Re-declaring a variable that has already been declared // Parameters re-declared as local variables // Design parameters // call: as statement // parameters: 1 (275), 2 (285) // : by value // body: does not modify, appears to modify, modifies parameter // Callee does not modify parameter passed by value # 275 Function.Definition.Re-declaring a variable that has already been declared // Function.Definition.Formal parameter is re-declared as a local variable in the function > {(){;<<;<< ;}(){; = ;();<<;}} > Type: debug Hardness: 20 # 276 Function.Definition.Re-declaring a variable that has already been declared // Function.Definition.Formal parameter is re-declared as a local variable in the function > {(){<< ;;<<;}(){; = ;<<;();}} > Type: debug Hardness: 20 // Callee APPEARS to modify parameter passed by value # 277 Function.Definition.Re-declaring a variable that has already been declared // Function.Definition.Formal parameter is re-declared as a local variable in the function > {(){;<< - ;}(){; = ;<<;();}} > Type: debug Hardness: 20 # 278 Function.Definition.Re-declaring a variable that has already been declared // Function.Definition.Formal parameter is re-declared as a local variable in the function > {(){<< ;;<< + ;}(){ = ;();<<;}} > Type: debug Hardness: 20 // Callee modifies parameter passed by value # 279 Function.Definition.Re-declaring a variable that has already been declared // Function.Definition.Formal parameter is re-declared as a local variable in the function > {(){<<;; = + 1;<<;}(){; = ;();<<;}} > Type: debug Hardness: 20 # 280 Function.Definition.Re-declaring a variable that has already been declared // Function.Definition.Formal parameter is re-declared as a local variable in the function > {(){ = - 1;<<;; = - 1;<<;}(){; = ;();<<;}} > Type: debug Hardness: 20 // No modification of formal par # 285 Function.Definition.Re-declaring a variable that has already been declared // Function.Definition.Formal parameter is re-declared as a local variable in the function > {(,){;<<;<<;}(){; = ;; = ;(,);<<;<<;}} > Type: debug Hardness: 30 # 286 Function.Definition.Re-declaring a variable that has already been declared // Function.Definition.Formal parameter is re-declared as a local variable in the function > {(,){<< ;;<<;<<;}(){ = ; = ;<<;<<;(,);}} > Type: debug Hardness: 30 // APPEAR to modify formal par # 287 Function.Definition.Re-declaring a variable that has already been declared // Function.Definition.Formal parameter is re-declared as a local variable in the function > {(,){<< + ;;<< - ;}(){ = ; = ;(,);<<;<<;}} > Type: debug Hardness: 30 # 288 Function.Definition.Re-declaring a variable that has already been declared // Function.Definition.Formal parameter is re-declared as a local variable in the function > {(,){;<< - ;<< * 2;}(){ = ; = ;(,);<<;<<;}} > Type: debug Hardness: 30 // Modify formal par # 289 Function.Definition.Re-declaring a variable that has already been declared // Function.Definition.Formal parameter is re-declared as a local variable in the function > {(,){ = - 1;<<;; = + 1;<<;}(){; = ;; = ;(,);<<;<<;}} > Type: debug Hardness: 30 // Modify formal par # 290 Function.Definition.Re-declaring a variable that has already been declared // Function.Definition.Formal parameter is re-declared as a local variable in the function > {(,){<< ;; = + ; = - ;<<;<<;}(){; = ;; = ;(,);<<;<<;}} > Type: debug Hardness: 30 // *********** Function call *************** // ---------------------------------------------------- // 300 // Function.Call.Call as expression // Calling a function with a non-void return type // Design parameters // call: as statement // parameters: none // local variables: none (300), 1 (310) // Call in output, assignment, initialization, re-ssignment, in expression // return statement has constant, variable or expression // Callee does not modify parameter passed by value # 300 Function.Call.Call as expression > {(){return ;}(){<< ();}} > Type: output Hardness: 20 # 301 Function.Call.Call as expression > {(){return + ;}(){; = ();<<;}} > Type: output Hardness: 20 # 302 Function.Call.Call as expression > {(){return * 10;}(){ = ();<<;}} > Type: output Hardness: 20 # 303 Function.Call.Call as expression > {(){return * ;}(){ = ;<<; = ();<<;}} > Type: output Hardness: 20 # 304 Function.Call.Call as expression > {(){return ;}(){ = ;<<; = + ();<<;}} > Type: output Hardness: 20 // Callee does not modify parameter passed by value # 310 Function.Call.Call as expression > {(){ = ;return ;}(){<< ();}} > Type: output Hardness: 30 # 311 Function.Call.Call as expression > {(){; = + ;return ;}(){; = ();<<;}} > Type: output Hardness: 30 # 312 Function.Call.Call as expression > {(){ = ;return * 10;}(){ = ();<<;}} > Type: output Hardness: 30 # 313 Function.Call.Call as expression > {(){ = ;return * ;}(){ = ;<<; = ();<<;}} > Type: output Hardness: 30 # 314 Function.Call.Call as expression > {(){ = ; = * 10;return ;}(){; = () + 1;<<;}} > Type: output Hardness: 30 # 315 Function.Call.Call as expression > {(){ = ; = * 2;return ;}(){; = () / 2;<<;}} > Type: output Hardness: 30 // ---------------------------------------------------- // 325 // Function.Call.Calls to multiple functions as statements // Calls to multiple functions // Design parameters // call: as statement // parameters: none (325) // : by value // local variables: none or in one function (325), both functions (335) // Just printing value in functions # 325 Function.Call.Calls to multiple functions as statements > {(){<< ;}(){<< ;}(){();; = ;<<;();}} > Type: output Hardness: 20 # 326 Function.Call.Calls to multiple functions as statements > {(){<< * 2;}(){<< * 10;}(){ = ;<<;();();}} > Type: output Hardness: 20 # 327 Function.Call.Calls to multiple functions as statements > {(){<< - ;}(){<< + ;}(){; = ;<<;();();}} > Type: output Hardness: 20 // Reversing the function call order # 328 Function.Call.Calls to multiple functions as statements > {(){<< ;}(){ = ;<<;}(){<< ;();();}} > Type: output Hardness: 30 # 329 Function.Call.Calls to multiple functions as statements > {(){; = ;<< * 2;}(){<< * 10;}(){();<< ;();}} > Type: output Hardness: 30 # 335 Function.Call.Calls to multiple functions as statements > {(){ = ;<<;}(){; = ;<<;}(){; = ;<<;();();}} > Type: output Hardness: 30 # 336 Function.Call.Calls to multiple functions as statements > {(){ = ;<< + 1;}(){; = ;<< - 1;}(){();; = ;<<;();}} > Type: output Hardness: 30 # 337 Function.Call.Calls to multiple functions as statements > {(){; = ;<< ;<< * 10;}(){; = ;<< ;<< * 10;}(){();(); = ;<<;}} > Type: output Hardness: 30 // Reversing the order of function calls # 338 Function.Call.Calls to multiple functions as statements > {(){ = ;<<;}(){ = ;<<;}(){; = ;<<;();();}} > Type: output Hardness: 40 # 339 Function.Call.Calls to multiple functions as statements > {(){; = ;<< * 2;}(){ = - ;<< ;}(){(); = ;<<;();}} > Type: output Hardness: 40 # 340 Function.Call.Calls to multiple functions as statements > {(){; = ;<< * 10;}(){; = ;<< + 1;}(){();(); = ;<<;}} > Type: output Hardness: 40 // // Just printing value in functions // # 330 // Function.Call.Calls to multiple functions as statements // ? // Function.Parameter.Value.Variable.One // > // {(){<<;}(){<<;}(){; = ;(); = ;();<<;}} // > // Type: output // Hardness: 50 // // Printing an expression involving the parameter // # 331 // Function.Call.Calls to multiple functions as statements // ? // Function.Parameter.Value.Variable.One // > // {(){<< - ;}(){<< + ;}(){; = ;(); = ;();<<;}} // > // Type: output // Hardness: 50 // ---------------------------------------------------- // 350 // Function.Call.Multiple calls to the same function // Multiple calls to the same function // Design parameters // call: as statement (350) // parameters: none // local variables: none, one, two # 350 Function.Call.Multiple calls to the same function > {(){<< ;}(){(); = ;<<;();}} > Type: output Hardness: 20 # 351 Function.Call.Multiple calls to the same function > {(){ = ;<< ;}(){();(); = ;<<;}} > Type: output Hardness: 20 # 352 Function.Call.Multiple calls to the same function > {(){ = ;<< ; = + 1;<< ;}(){();();}} > Type: output Hardness: 20 # 353 Function.Call.Multiple calls to the same function > {(){ = ;<< + 1;}(){(); = ;<<;();}} > Type: output Hardness: 20 # 354 Function.Call.Multiple calls to the same function > {(){ = ;<< - 1;<< - 2;}(){();();}} > Type: output Hardness: 20 # 355 Function.Call.Multiple calls to the same function > {(){; = - ;<< ;}(){ = ;<<;();();}} > Type: output Hardness: 20 # 356 Function.Call.Multiple calls to the same function > {(){ = ;<< ; = - ;<< ;}(){();();}} > Type: output Hardness: 20 # 357 Function.Call.Multiple calls to the same function > {(){ = ; = * 10;<<;}(){();(); = ;<<;}} > Type: output Hardness: 20 # 358 Function.Call.Multiple calls to the same function > {(){ = ;<< ; = * 2;<< ;}(){();();}} > Type: output Hardness: 20 # 359 Function.Call.Multiple calls to the same function > {(){ = ; = * 10;<<;<<;}(){(); = ;<<;();}} > Type: output Hardness: 20 # 360 Function.Call.Multiple calls to the same function > {(){ = ;<< ; = * 2;<<;}(){();();}} > Type: output Hardness: 20 // // Passing parameters to functions // # 355 // Function.Call.Multiple calls to the same function // ? // Function.Parameter.Value.Variable.One // > // {(){<< + 1;}(){; = ;(); = ;();<<;}} // > // Type: output // Hardness: 50 // # 356 // Function.Call.Multiple calls to the same function // ? // Function.Parameter.Value.Variable.One // > // {(){<< - 1;}(){; = ;(); = ;<<;();}} // > // Type: output // Hardness: 50 // // Expression as actual parameter // # 480 // Function.Call.Expression // ? // Function.Call.Call as expression,Function.Parameter.Value.Expression // > // // {(){return + ;}(){; = ;( + 1); = ;( + ) + 1;<<;}} // {(){return + ;}(){; = ;<< ( + 1); = ;<< ( + );<<;}} // > // Type: output // Hardness: 50 // ---------------------------------------------------- // 375 // Function.Call.Chained // main calls fun1 calls fun2 # 375 Function.Call.Chained > {(){<< ;}(){<< ;();}(){; = ;<<;();}} > Type: output Hardness: 20 # 376 Function.Call.Chained > {(){<< * 2;}(){();<< * 10;}(){ = ;<<;();}} > Type: output Hardness: 20 # 377 Function.Call.Chained > {(){<< - ;}(){<< + ;();}(){; = ;<<;();}} > Type: output Hardness: 20 // Reversing the function call order # 378 Function.Call.Chained > {(){<< ;}(){(); = ;<<;}(){<< ;();}} > Type: output Hardness: 30 # 379 Function.Call.Chained > {(){; = ;<< * 2;}(){<< * 10;();}(){();<< ;}} > Type: output Hardness: 30 # 385 Function.Call.Chained > {(){ = ;<<;}(){(); = ;<<;}(){; = ;<<;();}} > Type: output Hardness: 30 # 386 Function.Call.Chained > {(){ = ;<< + 1;}(){; = ;<< - 1;();}(){ = ;<<;();}} > Type: output Hardness: 30 # 387 Function.Call.Chained > {(){; = ;<< ;<< * 10;}(){(); = ;<< ;<< * 10;}(){(); = ;<<;}} > Type: output Hardness: 30 // Reversing the order of function calls # 388 Function.Call.Chained > {(){ = ;<<;}(){ = ;<<;();}(){; = ;<<;();}} > Type: output Hardness: 40 # 389 Function.Call.Chained > {(){; = ;<< * 2;}(){(); = - ;<< ;}(){(); = ;<<;}} > Type: output Hardness: 40 # 390 Function.Call.Chained > {(){; = ;<< * 10;}(){; = ;<< + 1;();}(){(); = ;<<;}} > Type: output Hardness: 40 // // Using function call in returned value // # 395 // Function.Call.Chained // ? // ... // > // // {(){return + ;}(){return ();}(){ = ;<< ();}} // {(){return + ;}(){return () + ();}(){ = ;<< (); = ;<< ();<<;}} // > // Type: output // Hardness: 50 // ---------------------------------------------------- // 400 // Function.Call.Function is called before it is defined/prototyped // Function is called before it is defined (C++ only) // Design parameters // call: as statement (400), as expression (410) // parameters: none, 1, 2 // : by value // local variables: none # 400 Function.Call.Function is called before it is defined/prototyped > {(){; = ;();<<;}(){<< ;<< + 1;}} > Type: debug Hardness: 20 # 401 Function.Call.Function is called before it is defined/prototyped > {(){; = ;();<<;}(){; = ;<<;}} > Type: debug Hardness: 20 # 402 Function.Call.Function is called before it is defined/prototyped > {(){; = ;();<<;}(){<<;<< + 1;}} > Type: debug Hardness: 30 # 403 Function.Call.Function is called before it is defined/prototyped > {(){; = ;();<<;}(){<<; = + ;<<;}} > Type: debug Hardness: 30 # 404 Function.Call.Function is called before it is defined/prototyped > {(){; = ;; = ;(,);<<;<<;}(, ){<<;<<;}} > Type: debug Hardness: 40 # 410 Function.Call.Function is called before it is defined/prototyped > {(){; = ;<< ();<<;}(){return ;}} > Type: debug Hardness: 30 # 411 Function.Call.Function is called before it is defined/prototyped > {(){; = ;<< ();<<;}(){; = ;return ;}} > Type: debug Hardness: 30 // NOT PRINTING VALUE OF VARIABLE AFTER ASSIGNING FUNCTION CALL BECAUSE IT ADDS A SECOND SEMANTIC ERROR # 412 Function.Call.Function is called before it is defined/prototyped > {(){ = ;<<;; = ();}(){return + ;}} > Type: debug Hardness: 40 // NOT PRINTING VALUE OF VARIABLE AFTER ASSIGNING FUNCTION CALL BECAUSE IT ADDS A SECOND SEMANTIC ERROR # 413 Function.Call.Function is called before it is defined/prototyped > {(){ = ;<<;; = ();}(){<<; = + ;return ;}} > Type: debug Hardness: 40 // NOT PRINTING VALUE OF VARIABLE AFTER ASSIGNING FUNCTION CALL BECAUSE IT ADDS A SECOND SEMANTIC ERROR # 414 Function.Call.Function is called before it is defined/prototyped > {(){ = ;; = ; = (,);}(, ){return - ;}} > Type: debug Hardness: 50 // ---------------------------------------------------- // 425 // Function.Call.Value returned by the function is ignored by the caller // return value of the function is ignored // Design parameters // call: as statement // parameters: none (425), 1 or more (445) // local variables: none (425), 1 (435) // Call in output, assignment, initialization, re-ssignment, in expression // return statement has constant, variable or expression // Callee does not modify parameter passed by value # 425 Function.Call.Value returned by the function is ignored by the caller > {(){return ;}(){();}} > Type: debug Hardness: 20 # 426 Function.Call.Value returned by the function is ignored by the caller > {(){return + ;}(){ = ;();<<;}} > Type: debug Hardness: 20 # 427 Function.Call.Value returned by the function is ignored by the caller > {(){return * 10;}(){ = * 10;();<<;}} > Type: debug Hardness: 20 # 428 Function.Call.Value returned by the function is ignored by the caller > {(){return * ;}(){ = ;<<;();<<;}} > Type: debug Hardness: 20 # 429 Function.Call.Value returned by the function is ignored by the caller > {(){return ;}(){ = ;<<;();<<;}} > Type: debug Hardness: 20 // Callee does not modify parameter passed by value # 435 Function.Call.Value returned by the function is ignored by the caller > {(){ = ;return ;}(){();}} > Type: debug Hardness: 30 # 436 Function.Call.Value returned by the function is ignored by the caller > {(){; = + ;return ;}(){ = ;();<<;}} > Type: debug Hardness: 30 # 437 Function.Call.Value returned by the function is ignored by the caller > {(){ = ;return * 10;}(){ = ;();<<;}} > Type: debug Hardness: 30 # 438 Function.Call.Value returned by the function is ignored by the caller > {(){ = ;return * ;}(){ = ;<<;();<<;}} > Type: debug Hardness: 30 # 439 Function.Call.Value returned by the function is ignored by the caller > {(){ = ; = * 10;return ;}(){ = ;();<<;}} > Type: debug Hardness: 30 # 440 Function.Call.Value returned by the function is ignored by the caller > {(){ = ; = * 2;return ;}(){ = * 10;();<<;}} > Type: debug Hardness: 30 # 445 Function.Call.Value returned by the function is ignored by the caller > {(){return + ;}(){; = ;();<<;}} > Type: debug Hardness: 40 # 446 Function.Call.Value returned by the function is ignored by the caller > {(, ){return + ;}(){ = ; = ;(,);<<;<<;}} > Type: debug Hardness: 50 // ---------------------------------------------------- // 450 // Function.Call.Caller tries to use the value returned by a function with void return type // Call in an expression // Design parameters // call: as statement // parameters: none (450), 1 (460) // : by value // local variables: none // body: does not modify, appears to modify, modifies parameter // Callee does not modify parameter passed by value # 450 Function.Call.Caller tries to use the value returned by a function with void return type > {(){<< ;}(){<< ();}} > Type: debug Hardness: 20 # 451 Function.Call.Caller tries to use the value returned by a function with void return type > {(){<< ;}(){; = ();<<;}} > Type: debug Hardness: 20 # 452 Function.Call.Caller tries to use the value returned by a function with void return type > {(){ = ;<<;}(){<< ();}} > Type: debug Hardness: 20 # 453 Function.Call.Caller tries to use the value returned by a function with void return type > {(){ = ;<<;}(){ = ();<<;}} > Type: debug Hardness: 20 # 454 Function.Call.Caller tries to use the value returned by a function with void return type > {(){ = ;<<; = / 2;<<;}(){<< ();}} > Type: debug Hardness: 20 # 455 Function.Call.Caller tries to use the value returned by a function with void return type > {(){ = ;<<; = % 2;<<;}(){ = ();<<;}} > Type: debug Hardness: 20 // Callee does not modify parameter # 460 Function.Call.Caller tries to use the value returned by a function with void return type > {(){<< ;}(){ = ;<< ();}} > Type: debug Hardness: 30 # 461 Function.Call.Caller tries to use the value returned by a function with void return type > {(){<< - ;}(){ = ;<<; = ();<<;}} > Type: debug Hardness: 30 // Callee APPEARS to modify parameter passed by value # 462 Function.Call.Caller tries to use the value returned by a function with void return type > {(){<< + ;}(){ = ;<< ();<<;}} > Type: debug Hardness: 30 # 463 Function.Call.Caller tries to use the value returned by a function with void return type > {(){<< - ;}(){ = ; = ();<<;}} > Type: debug Hardness: 30 # 464 Function.Call.Caller tries to use the value returned by a function with void return type > {(){ = + ;<< ;}(){ = ;<< ();}} > Type: debug Hardness: 30 # 465 Function.Call.Caller tries to use the value returned by a function with void return type > {(){<< ; = - ;<< ;}(){ = ; = ();<<;}} > Type: debug Hardness: 30 // Callee modifies parameter passed by value # 466 Function.Call.Caller tries to use the value returned by a function with void return type > {(){<<; = + 1;<<;}(){; = ;<<; = ();<<;}} > Type: debug Hardness: 30 # 467 Function.Call.Caller tries to use the value returned by a function with void return type > {(){ = - 1;<<; = - 1;<<;}(){; = ;<< ();<<;}} > Type: debug Hardness: 30 // ---------------------------------------------------- // 475 // Function.Call.Data type of the value returned by the function call is incompatible with the expected data type in the caller // ******** Parameter Passing ************** // Category constraints: Parameter(s) passed by value only (void return type) // ---------------------------------------------------- // 500 // Function.Parameter.Value.Variable.One // Call with 1 parameter (variable) passed by value // Design parameters // call: as statement // parameters: 1 // : by value // local variables: none // body: does not modify (500), appears to modify (505), modifies parameter (510) // Callee does not modify parameter passed by value # 500 Function.Parameter.Value.Variable.One > {(){<<;}(){; = ;();<<;}} > Type: output Hardness: 20 # 501 Function.Parameter.Value.Variable.One > {(){<<;}(){; = ;<<;();}} > Type: output Hardness: 20 // Callee APPEARS to modify parameter passed by value # 505 Function.Parameter.Value.Variable.One > {(){<< - ;}(){; = ;<<;();}} > Type: output Hardness: 30 # 506 Function.Parameter.Value.Variable.One > {(){<< + ;}(){ = ;();<<;}} > Type: output Hardness: 30 // Callee modifies parameter passed by value # 510 Function.Parameter.Value.Variable.One > {(){<<; = + 1;<<;}(){; = ;();<<;}} > Type: output Hardness: 40 # 511 Function.Parameter.Value.Variable.One > {(){ = - 1;<<; = - 1;<<;}(){; = ;();<<;}} > Type: output Hardness: 40 // ---------------------------------------------------- // 525 // Function.Parameter.Value.Variable.Many // Call with many parameters (variables) passed by value // Design parameters // call: as statement // parameters: 2 (525), 3 (TO DO?) // : by value // local variables: none // body: does not modify (525), appears to modify (530), modifies parameter (535) // No modification of formal par # 525 Function.Parameter.Value.Variable.Many > {(,){<<;<<;}(){; = ;; = ;(,);<<;<<;}} > Type: output Hardness: 30 # 526 Function.Parameter.Value.Variable.Many > {(,){<<;<< ;<<;}(){ = ; = ;<<;<<;(,);}} > Type: output Hardness: 30 // APPEAR to modify formal par # 530 Function.Parameter.Value.Variable.Many > {(,){<< + ;<< - ;}(){ = ; = ;(,);<<;<<;}} > Type: output Hardness: 40 # 531 Function.Parameter.Value.Variable.Many > {(,){<< - ;<< * 2;}(){ = ; = ;(,);<<;<<;}} > Type: output Hardness: 40 // Modify formal par # 535 Function.Parameter.Value.Variable.Many > {(,){ = - 1;<<; = + 1;<<;}(){; = ;; = ;(,);<<;<<;}} > Type: output Hardness: 50 // Modify formal par # 536 Function.Parameter.Value.Variable.Many > {(,){ = + ; = - ;<<;<<;}(){; = ;; = ;(,);<<;<<;}} > Type: output Hardness: 50 // ---------------------------------------------------- // 550 // Function.Parameter.Value.Variable.Repeated // Call with same variable repeated multiple times as parameter // Design parameters // call: as statement // parameters: 2 (550) // : by value // local variables: none // body: does not modify (550), appears to modify (555), modifies parameter (560) // No modification of formal par # 550 Function.Parameter.Value.Variable.Repeated > {(,){<<;<<;}(){; = ;<<;(,);}} > Type: output Hardness: 30 # 551 Function.Parameter.Value.Variable.Repeated > {(,){<<;<< ;<<;}(){ = ;<<;(,);}} > Type: output Hardness: 30 // APPEAR to modify formal par # 555 Function.Parameter.Value.Variable.Repeated > {(,){<< + 1;<< - 1;}(){ = ;(,);<<;}} > Type: output Hardness: 40 # 556 Function.Parameter.Value.Variable.Repeated > {(,){<< - ;<< + ;}(){ = ;(,);<<;}} > Type: output Hardness: 40 // Modify formal par # 560 Function.Parameter.Value.Variable.Repeated > {(,){ = + 10;<<; = * 10;<<;}(){; = ;(,);<<;}} > Type: output Hardness: 50 // Modify formal par # 561 Function.Parameter.Value.Variable.Repeated > []{(,){ = + ; = / ;<<;<<;}(){; = ;(,);<<;}} > Type: output Hardness: 50 // ---------------------------------------------------- // 575 // Function.Parameter.Value.Constant // Call with literal constants as actual parameters // Design parameters // call: as statement // parameters: 1 (575), 2 (590) // : by value // local variables: none // body: does not modify, appears to modify, modifies parameter // Callee does not modify parameter passed by value # 575 Function.Parameter.Value.Constant > {(){<<;}(){();}} > Type: output Hardness: 20 // Callee APPEARS to modify parameter passed by value # 580 Function.Parameter.Value.Constant > {(){<< - ;<< + 1;}(){();}} > Type: output Hardness: 30 # 581 Function.Parameter.Value.Constant > {(){<< + ;<< - ;}(){();}} > Type: output Hardness: 30 // Callee modifies parameter passed by value # 585 Function.Parameter.Value.Constant > {(){ = - 1;<<; = * 2;<<;}(){();}} > Type: output Hardness: 40 # 586 Function.Parameter.Value.Constant > {(){ = - ;<<; = ;<<;}(){();}} > Type: output Hardness: 40 // APPEAR to modify formal par # 590 Function.Parameter.Value.Constant > {(,){<< ;<< ;}(){(,);}} > Type: output Hardness: 50 # 591 Function.Parameter.Value.Constant > {(,){<< - ;<< ;}(){(,);}} > Type: output Hardness: 50 // Modify formal par # 595 Function.Parameter.Value.Constant > {(,){ = - 1;<<; = + 1;<<;}(){(,);}} > Type: output Hardness: 60 // Modify formal par # 596 Function.Parameter.Value.Constant > {(,){ = + ; = - ;<<;<<;}(){(,);}} > Type: output Hardness: 60 // ---------------------------------------------------- // 600 // Function.Parameter.Value.Expression // Call with expressions as actual parameters // Design parameters // call: as statement // parameters: 1 // : by value // local variables: none // body: does not modify (600), appears to modify (605), modifies parameter (610) // Only +, - and * operators used // Callee does not modify parameter passed by value # 600 Function.Parameter.Value.Expression > {(){<<;<< ;}(){; = ;( - 1);<<;}} > Type: output Hardness: 20 # 601 Function.Parameter.Value.Expression > {(){<< ;<<;}(){; = ;( + 1);<<;}} > Type: output Hardness: 20 // Callee APPEARS to modify parameter passed by value # 605 Function.Parameter.Value.Expression > {(){<< ;}(){; = ;( - );<<;}} > Type: output Hardness: 30 # 606 Function.Parameter.Value.Expression > {(){<< ;}(){ = ;( + );<<;}} > Type: output Hardness: 30 // Callee modifies parameter passed by value # 610 Function.Parameter.Value.Expression > {(){<<; = - ;<<;}(){; = ;( * 2);<<;}} > Type: output Hardness: 40 # 611 Function.Parameter.Value.Expression > {(){<<; = / 2;<<;}(){; = ;( + );<<;}} > Type: output Hardness: 40 // ---------------------------------------------------- // 625 // Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition // Call with incorrect number of parameters // Design parameters // call: as statement // parameters: 0 in def - 1 in call (630); 1 in def - 0 in call (625); 1 in def - 2 in call (635), 2 in def - 1 in call (641) // : by value // local variables: none // body: does not modify (625), appears to modify (630), modifies parameter (635) // Only +, - and * operators used // Callee does not modify parameter passed by value # 625 Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition > {(){<<;<< ;}(){; = ;();<<;}} > Type: debug Hardness: 20 // Callee APPEARS to modify parameter passed by value # 626 Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition > {(){<< - ;}(){; = ;<<;();}} > Type: debug Hardness: 20 # 627 Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition > {(){<< + ;}(){ = ;();<<;}} > Type: debug Hardness: 20 // Callee modifies parameter passed by value # 628 Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition > {(){<<; = + 1;<<;}(){; = ;();<<;}} > Type: debug Hardness: 20 # 629 Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition > {(){ = - 1;<<; = - 1;<<;}(){; = ;();<<;}} > Type: debug Hardness: 20 // Callee does not modify parameter passed by value # 630 Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition > {(){<< ;}(){; = ;();<<;}} > Type: debug Hardness: 30 // Callee APPEARS to modify parameter passed by value # 631 Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition > {(){ = ;<< * 2;}(){; = ;<<;();}} > Type: debug Hardness: 30 # 632 Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition > {(){ = ;<< + ;}(){ = ;();<<;}} > Type: debug Hardness: 30 // Callee modifies parameter passed by value # 633 Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition > {(){ = ;<<; = + 1;<<;}(){; = ;();<<;}} > Type: debug Hardness: 30 # 634 Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition > {(){ = ; = - 1;<<; = - 1;<<;}(){; = ;();<<;}} > Type: debug Hardness: 30 // No modification of formal par # 635 Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition > {(){<<;}(){; = ;; = ;(,);<<;<<;}} > Type: debug Hardness: 30 # 636 Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition > {(){<<;<< ;}(){ = ; = ;<<;<<;(,);}} > Type: debug Hardness: 30 // APPEAR to modify formal par # 637 Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition > {(){<< + ;}(){ = ; = ;(,);<<;<<;}} > Type: debug Hardness: 30 # 638 Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition > {(){<<;<< * 2;}(){ = ; = ;(,);<<;<<;}} > Type: debug Hardness: 30 // Modify formal par # 639 Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition > {(){ = - 1;<<;}(){; = ;; = ;(,);<<;<<;}} > Type: debug Hardness: 30 // Modify formal par # 640 Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition > {(){ = + ;<<;}(){; = ;; = ;(,);<<;<<;}} > Type: debug Hardness: 30 // No modification of formal par # 641 Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition > {(,){<<;<<;}(){; = ;<<;();}} > Type: debug Hardness: 40 # 642 Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition > {(,){<<;<< ;<<;}(){ = ;<<;();}} > Type: debug Hardness: 40 // APPEAR to modify formal par # 643 Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition > {(,){<< + ;<< - ;}(){ = ;<<;();}} > Type: debug Hardness: 40 # 644 Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition > {(,){<< - ;<< * 2;}(){ = ;<<;();}} > Type: debug Hardness: 40 // Modify formal par # 645 Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition > {(,){ = - 1;<<; = + 1;<<;}(){; = ;<<;();}} > Type: debug Hardness: 40 // Modify formal par # 646 Function.Parameter.Number of actual parameters in the call not equal to the number of formal parameters in the definition > {(,){ = + ; = - ;<<;<<;}(){; = ;<<;();}} > Type: debug Hardness: 40 // ---------------------------------------------------- // 650 // Function.Parameter.Data type of the actual parameter in the call is incompatible with the data type of the formal parameter in the definition // Call with incorrect types/order of parameters // Design parameters // call: as statement // parameters: 1 (650), 2 (660) // : by value // local variables: none // body: does not modify (600), appears to modify (605), modifies parameter (610) // Only +, - and * operators used // Function definition with integer formal parameter, function call with real actual parameter // Avoiding boolean, char; unsigned does not exist in Java // data loss in C++, so warning generated // type incompatible in Java // ?? in C# // Callee does not modify parameter passed by value # 650 Function.Parameter.Data type of the actual parameter in the call is incompatible with the data type of the formal parameter in the definition > {(){<<;<< ;}(){; = ;();<<;}} > Type: debug Hardness: 20 # 651 Function.Parameter.Data type of the actual parameter in the call is incompatible with the data type of the formal parameter in the definition > {(){<< ;<<;}(){; = ;<<;();}} > Type: debug Hardness: 20 // Callee APPEARS to modify parameter passed by value # 652 Function.Parameter.Data type of the actual parameter in the call is incompatible with the data type of the formal parameter in the definition > {(){<< - ;}(){; = ;<<;();}} > Type: debug Hardness: 20 # 653 Function.Parameter.Data type of the actual parameter in the call is incompatible with the data type of the formal parameter in the definition > {(){<< + ;}(){ = ;();<<;}} > Type: debug Hardness: 20 // Callee modifies parameter passed by value # 654 Function.Parameter.Data type of the actual parameter in the call is incompatible with the data type of the formal parameter in the definition > {(){<<; = + 1;<<;}(){; = ;();<<;}} > Type: debug Hardness: 20 # 655 Function.Parameter.Data type of the actual parameter in the call is incompatible with the data type of the formal parameter in the definition > {(){ = - 1;<<; = - 1;<<;}(){; = ;();<<;}} > Type: debug Hardness: 20 // No modification of formal par # 660 Function.Parameter.Data type of the actual parameter in the call is incompatible with the data type of the formal parameter in the definition > {(,){<<;<<;}(){; = ;; = ;(,);<<;<<;}} > Type: debug Hardness: 40 # 661 Function.Parameter.Data type of the actual parameter in the call is incompatible with the data type of the formal parameter in the definition > {(,){<<;<< ;<<;}(){ = ; = ;<<;<<;(,);}} > Type: debug Hardness: 40 // APPEAR to modify formal par # 662 Function.Parameter.Data type of the actual parameter in the call is incompatible with the data type of the formal parameter in the definition > {(,){<< + ;<< - ;}(){ = ; = ;(,);<<;<<;}} > Type: debug Hardness: 40 # 663 Function.Parameter.Data type of the actual parameter in the call is incompatible with the data type of the formal parameter in the definition > {(,){<< - ;<< * 2;}(){ = ; = ;(,);<<;<<;}} > Type: debug Hardness: 40 // Modify formal par # 664 Function.Parameter.Data type of the actual parameter in the call is incompatible with the data type of the formal parameter in the definition > {(,){ = - 1;<<; = + 1;<<;}(){; = ;; = ;(,);<<;<<;}} > Type: debug Hardness: 40 // Modify formal par # 665 Function.Parameter.Data type of the actual parameter in the call is incompatible with the data type of the formal parameter in the definition > {(,){ = + ; = - ;<<;<<;}(){; = ;; = ;(,);<<;<<;}} > Type: debug Hardness: 40 // ---------------------------------------------------- // 700 // Function.Parameter.Reference.Variable.One // Call with 1 parameter (variable) passed by reference // // Callee modifies parameter passed by value // # 274 // Function.{Parameters.One,ParPass.Value} // ? // Function.PostCall // > // {(&){<<; = + 1;<<;}(){; = ;();<<;}} // > // Type: output // Hardness: 50 // // // same actual parameter - appear to modify formal par // # 275 // Function.{Parameters.Many,ParPass.Value} // ? // Function.PostCall // > // {(&){<< ; = ;}(){; = ;<<;();<<;}} // > // Type: output // Hardness: 50 // // // // Using returned value to print // # 485 // Function.Call.Expression // ? // Function.{PostCall,Parameters.One,ParPass.Value} // > // {(){return + ;}(){; = ;<< (); = ;<< () + 1;<<;}} // > // Type: output // Hardness: 50 // // // // Using returned value in assignment // # 487 // Function.Call.Expression // ? // Function.{PostCall,Parameters.One,ParPass.Value} // > // {(){return + ;}(){ = ;; = ();<<;<<;}} // > // Type: output // Hardness: 50 // // // Using returned value in initialization // # 488 // Function.Call.Expression // ? // Function.{PostCall,Parameters.One,ParPass.Value} // > // {(){return + ;}(){ = ; = ();<<;<<;}} // > // Type: output // Hardness: 50 // ---------------------------------------------------- // 725 // Function.Parameter.Reference.Variable.Many // Call with many parameters (variables) passed by reference // ---------------------------------------------------- // 750 // Function.Parameter.Reference.Variable.Repeated // Call with same variable repeated multiple times as parameter by reference // // ---------------------------------------------------- // 800 // Function.Parameter.Reference.Constant or expression is passed by reference // Call with literal constant/expression as actual parameter // // ---------------------------------------------------- // 900 // Passed by a mix of value and reference:.. // Prototype // ************ ADVANCED TOPICS ******************* // ---------------------------------------------------- // 1000 // Function.Call.Calls to multiple functions in an expression // Multiple calls in an expression // // // Using returned value to print - multiple calls in one expresssion // # 1000 // Function.Definition.Local variable.Name overlap // // Function.Call.Expression // ? // Function.{PostCall,Parameters.One,ParPass.Value} // > // {(){return + ;}(){return + ;}(){ = ; = ;<< () + ();<<;<<;}} // > // Type: output // Hardness: 50 // ---------------------------------------------------- // 1025 // Function.Parameter.Value.FunctionCall // Call with function call as actual parameter // // // Using function call in actual parameter // # 490 // Function.Call.Expression // ? // Function.{PostCall,Parameters.One,ParPass.Value} // > // {(){return + ;}(){return () + ;}(){ = ;<< (());}} // // {(){return + ;}(){return () + ;}(){ = ;<< ();}} // > // Type: output // Hardness: 50 // ---------------------------------------------------- // 1100 // Function.Parameter.Pointer // ---------------------------------------------------- // 1200 // Function.Definition.Default.Correct // ---------------------------------------------------- // 1225 // Function.Definition.Default.Error.Definition // ---------------------------------------------------- // 1250 // Function.Definition.Default.Error.Call // ---------------------------------------------------- // 1300 // Function.Call.Recursive.Tail.Side effect // Recursive function calls - tail recursive, i.e., local work before recursive call, result is printed // Pretest // Down-counting # 1300 Function.Call.Recursive.Tail.Side effect > {(){ if( > 0 ) {<< ; = - 1;(); }}(){ = ;(); }} > Type: debug_output Hardness: 20 Purpose: The function prints counting down from to 1 // Post-test // Up-counting to a parameter # 1301 Function.Call.Recursive.Tail.Side effect > {(, ){ if( < ) {<< ; = + 1;(, ); }}(){ = ;(, ); }} > Type: debug_output Hardness: 20 Purpose: The function prints counting up from up to // Demo // Thresholding, with input # 1302 Function.Call.Recursive.Tail.Side effect > []{(){; >> ; if( != ) { if( < ){ << ;} (); }}(){; >> ;(); }} > Input: "\n\n\n\n\n\n\n" > Type: debug_output Hardness: 30 Purpose: The function prints read values less than // Two numbers moving towards each other # 1303 Function.Call.Recursive.Tail.Side effect > [,]{(, ){ if( > ) {<< ; << ; = - 1; = + 1; (, ); }}(){ = ; = ;(, ); }} > Type: debug_output Hardness: 30 Purpose: The function prints counting down from and counting up from // Two numbers moving away from each other # 1304 Function.Call.Recursive.Tail.Side effect > [,]{(, ){ if( < ) {<< ; << ; = + 1; = - 1; (, ); }}(){ = ; (, ); }} > Type: debug_output Hardness: 30 Purpose: The function prints 3 numbers counting up and down from // ---------------------------------------------------- // 1325 // Function.Call.Recursive.Tail.Scalar output // Recursive function calls - tail recursive, i.e., local work before recursive call, result is returned // Arithmetic progression # 1325 Function.Call.Recursive.Tail.Scalar output > {(){ if( > 0 ) { return + ( - 1); } else return 0; }(){ = ;<< (); }} > Type: debug_output Hardness: 20 Purpose: The function returns the sum of all the numbers from down to 1 // Pretest // Factorial # 1326 Function.Call.Recursive.Tail.Scalar output > {(){ if( > 0 ) { return * ( - 1); } else return 1; }(){ = ;<< (); }} > Type: debug_output Hardness: 20 Purpose: The function returns the factorial of // Posttest // Square # 1327 Function.Call.Recursive.Tail.Scalar output > []{(){ if( > 0 ) { return + ( - 1); } else return 0; }(){ = ;<< (); }} > Type: debug_output Hardness: 20 Purpose: The function returns the square of // 1 1 2 2 3 3 4 4 5 5 pattern returned # 1328 Function.Call.Recursive.Tail.Scalar output > {(){ if( > 0 ) { return - ( - 1); } else return 0; }(){ = ;<< (); }} > Type: debug_output Hardness: 30 // Difference between n and (n/2 - n/4) - Math hard only for R1 = 3 # 1329 Function.Call.Recursive.Tail.Scalar output > [,]{(){ if( > ) { return - ( / 2); } else return ; }(){<< ( ); }} > Type: debug_output Hardness: 30 // Demo // Sum of all the elements # 1330 Function.Call.Recursive.Tail.Scalar output > {([],){ if( < 5 ) { return [] + (, + 1); } else return []; } (){[6] = {, , , , , }; << (, 0 ); }} > Type: debug_output Hardness: 30 Purpose: The function returns the sum of all the elements in the array // Count of a[n] < a[n+1] # 1331 Function.Call.Recursive.Tail.Scalar output > {([],){ if( < 5 ) { = 0; if( [] < [ + 1] ) = 1; return + (, + 1); }else return 0; } (){[6] = {, , , , , }; << (, 0 ); } } > Type: debug_output Hardness: 30 Purpose: The function returns the number of elements less than the next element in the array // Thresholding count # 1332 Function.Call.Recursive.Tail.Scalar output > {([],){ if( < 6 ) { ; if( [] < ) = 1; else = 0; return + (, + 1); } else return 0; } (){[6] = {, , , , , }; << (, 0); }} > Type: debug_output Hardness: 30 Purpose: The function returns the number of elements in the array less than // Largest among the input number sequence of specified length # 1333 Function.Call.Recursive.Tail.Scalar output > [,,,,,,,]{(, ){ ; ; >> ; if( >= 0 ) { if( > ) = ; else = ; return ( , - 1 ); } else return ; } (){ << ( 0, ); }} > Input: "\n\n\n\n\n\n\n" > Type: debug_output Hardness: 30 Purpose: The function returns the largest of the first numbers read // ---------------------------------------------------- // 1350 // Function.Call.Recursive.Tail.Vector output // Recursive function calls - tail recursive, i.e., local work before recursive call, result is passed by reference // Assigning multiples of # 1350 Function.Call.Recursive.Tail.Vector output > []{([],){ if( >= 0 ) { [] = * ; (, - 1); } }(){[6] = {0, 0, 0, 0, 0, 0}; = 5;(, ); }} > Type: state Hardness: 20 Purpose: The function assigns the multiples of to the array // Assigning in reverse order # 1351 Function.Call.Recursive.Tail.Vector output > []{([],,){ if( < 6 ) { [] = ; (, + 1, - 1); } }(){[6] = {0, 0, 0, 0, 0, 0}; (, 0, ); }} > Type: state Hardness: 30 Purpose: The function assigns values counting down from to the array // Pretest // Moving all elements up by one # 1352 Function.Call.Recursive.Tail.Vector output > {([],){ if( > 0 ) { [] = [ - 1]; (, - 1); } } (){[6] = {, , , , , }; (, 5 ); } } > Type: state Hardness: 30 Purpose: The function shifts the elements of the array up by one // Posttest // Moving all elements down by one # 1353 Function.Call.Recursive.Tail.Vector output > {([],){ if( < 5 ) { [] = [ + 1]; (, + 1); } } (){[6] = {, , , , , }; (, 0 ); } } > Type: state Hardness: 30 Purpose: The function shifts the elements of the array down by one // Bleed down of last element to all other elements # 1354 Function.Call.Recursive.Tail.Vector output > {([],){ if( > 0 ) { [ - 1] = []; (, - 1); } } (){[6] = {, , , , , }; (, 5 ); } } > Type: state Hardness: 30 Purpose: The function copies the last element to all the other elements // Bubble sort - one pass - largest number bubbles to the first # 1355 Function.Call.Recursive.Tail.Vector output > {([],){ if( > 0 ) { if( [] > [ - 1] ){ = []; [] = [ - 1]; [ - 1] = ; (, - 1); }}} (){[6] = {, , , , , }; (, 5); }} > Type: state Hardness: 40 Purpose: The function "bubbles" the largest value to the first element of the array // Demo // Thresholding # 1356 Function.Call.Recursive.Tail.Vector output > {([],){ if( < 6 ) { if( [] < ) [] = 0; else [] = 1; (, + 1); } } (){[6] = {, , , , , }; (, 0); }} > Type: state Hardness: 30 Purpose: The function sets each array element to 0 if it is less than and 1 otherwise // Cumulation of numbers # 1357 Function.Call.Recursive.Tail.Vector output > {([],, ){ if( < 6 ) { = [] + ; [] = ; (, + 1, ); } } (){[6] = {, , , , , }; (, 1, [0] ); }} > Type: state Hardness: 40 Purpose: The function sets each array element to the sum of all the elements before it // Reading into an array # 1358 Function.Call.Recursive.Tail.Vector output > [,,,,,]{([],){ if( < 6 ) { >> []; (, + 1); } } (){[6] = {0, 0, 0, 0, 0, 0}; (, 0 ); }} > Input: "\n\n\n\n\n" > Type: state Hardness: 40 Purpose: The function reads into the elements of the array // ---------------------------------------------------- // 1400 // Function.Call.Recursive.Head.Side effect // Recursive function calls - head recursive, i.e., local work after recursive call, result is printed // Demo // Up-counting # 1400 Function.Call.Recursive.Head.Side effect > {(){ if( > 0 ) { ( - 1); << ; }}(){ = ;(); }} > Type: debug_output Hardness: 20 Purpose: The function prints from 1 up to // Down-counting to a parameter # 1401 Function.Call.Recursive.Head.Side effect > [,,]{(, ){ if( < ) {( + 1, ); << ; }}(){ = ;(, ); }} > Type: debug_output Hardness: 20 Purpose: The function prints from down to // Thresholding, with input # 1402 Function.Call.Recursive.Head.Side effect > []{(){; >> ; if( != ) { (); if( < ){ << ;} }}(){; >> ;(); }} > Input: "\n\n\n\n\n\n\n" > Type: debug_output Hardness: 30 Purpose: The function prints all the read numbers less than in reverse order // Pretest // Two numbers moving towards each other # 1403 Function.Call.Recursive.Head.Side effect > [,]{(, ){ if( > ) {( - 1, + 1); << ; << ; }}(){ = ; = ;(, ); }} > Type: debug_output Hardness: 30 Purpose: The function prints numbers counting down from and counting up from in reverse order // Post-test // Two numbers moving away from each other # 1404 Function.Call.Recursive.Head.Side effect > [,]{(, ){ if( < ) {( + 1, - 1); << ; << ; }}(){ = ; (, ); }} > Type: debug_output Hardness: 30 Purpose: The function prints 3 numbers counting up and down from in reverse order // ---------------------------------------------------- // 1425 // Function.Call.Recursive.Head.Scalar output // Recursive function calls - head recursive, i.e., local work after recursive call, result is returned // Complement of arithmetic progression # 1425 Function.Call.Recursive.Head.Scalar output > [,,]{(){ if( > 0 ) { return ( - 1) - ; } else return ; }(){ = ;<< (); }} > Type: debug_output Hardness: 20 Purpose: The function returns - the sum of all the numbers from 1 up to // Demo // Powers of 2 in descending order # 1426 Function.Call.Recursive.Head.Scalar output > [,]{(){ if( > 0 ) { return ( - 1) / 2; } else return ; }(){ = ;<< (); }} > Type: debug_output Hardness: 20 Purpose: The function returns / power of 2 // Subtracting 3-4 multiples of from # 1427 Function.Call.Recursive.Head.Scalar output > [,]{(){ if( > 0 ) { return ( - 1) - ; } else return ; }(){<< (); }} > Type: debug_output Hardness: 20 Purpose: The function returns - * // Pretest // Returning the minimum in an array # 1428 Function.Call.Recursive.Head.Scalar output > // {([],){ if( > 0 ) { = (, - 1); if( [] < ) return []; else return ; } else return []; }(){[6] = {, , , , , }; << (, 5); }} {([],){ if( > 0 ) { = (, - 1); if( [] < ) return []; else return ; } else return []; }(){[6] = {, , , , , }; << (, 5); }} > Type: debug_output Hardness: 20 Purpose: The function returns the minimum value in the array // Large number - Sum of all the elements of the array # 1429 Function.Call.Recursive.Head.Scalar output > [,,]{([],){ if( < 6 ) { return (, + 1) - []; } else return ; } (){[6] = {,,,,,}; << (, 0 ); }} > Type: debug_output Hardness: 20 Purpose: The function returns - sum of all the elements in the array // Posttest // Returning the maximum in an array # 1430 Function.Call.Recursive.Head.Scalar output > // {([],){ if( > 0 ) { = (, - 1); if( [] < ) return ; else return []; } else return []; }(){[6] = {, , , , , }; << (, 5); }} {([],){ if( > 0 ) { = (, - 1); if( [] < ) return ; else return []; } else return []; }(){[6] = {, , , , , }; << (, 5); }} > Type: debug_output Hardness: 20 Purpose: The function returns the maximum value in the array // NOT VERY GOOD PROBLEMS // Calculating 4th multiple of = 4 * - 4 * # 1431 Function.Call.Recursive.Head.Scalar output > [,,,]{(){ if( < ) { return ( + ) - ; } else return ; }(){<< ( 0 ); }} > Type: debug_output Hardness: 20 Purpose: The function returns 4 * // Powers of 2 in ascending order # 1432 Function.Call.Recursive.Head.Scalar output > {(){ if( < ) { return ( * 2) - ; } else return ; }(){<< ( 1 ); }} > Type: debug_output Hardness: 20 // ---------------------------------------------------- // 1450 // Function.Call.Recursive.Head.Vector output // Recursive function calls - head recursive, i.e., local work after recursive call, result is passed by reference // Backward bleed of last element to all elements # 1450 Function.Call.Recursive.Head.Vector output > {([],){ if( < 5 ) { (, + 1); [] = [ + 1]; } } (){[6] = {, , , , , }; (, 0 ); } } > Type: state Hardness: 30 Purpose: The function copies the last element to all the other elements of the array // Moving numbers down by one # 1451 Function.Call.Recursive.Head.Vector output > {([],){ if( > 0 ) { (, - 1); [ - 1] = []; } } (){[6] = {, , , , , }; (, 5 ); } } > Type: state Hardness: 30 Purpose: The function shifts the array elements down by one // Moving numbers up by one # 1452 Function.Call.Recursive.Head.Vector output > {([],){ if( < 5 ) { (, + 1); [ + 1] = []; } } (){[6] = {, , , , , }; (, 0 ); } } > Type: state Hardness: 30 Purpose: The function shifts the array elements up by one // Pretest // If a[n] > a[n-1], a[n]++ # 1453 Function.Call.Recursive.Head.Vector output > {([],){ if( < 6 ) { if( [] > [ - 1] ){[] = [] + 1;} (, + 1); } } (){[6] = {, , , , , }; (, 1 ); } } > Type: state Hardness: 30 Purpose: The function increments every array element that is greater than the next element // Posttest // Cumulation of numbers in reverse order # 1454 Function.Call.Recursive.Head.Vector output > {([],){ if( < 5 ) { (, + 1); [] = [] + [ + 1]; } } (){[6] = {, , , , , }; (, 0 ); }} > Type: state Hardness: 40 Purpose: The function adds to each array element, the sum of all the elements after it // Demo // Reading into an array in reverse order # 1455 Function.Call.Recursive.Head.Vector output > [,,,,,]{([],){ if( < 6 ) { (, + 1); >> []; } } (){[6] = {0, 0, 0, 0, 0, 0}; (, 0 ); }} > Input: "\n\n\n\n\n" > Type: state Hardness: 40 Purpose: The function reads into the elements of the array in reverse order // Bubble sort - one pass - smallest number bubbles to the end # 1456 Function.Call.Recursive.Head.Vector output > {([],){ if( > 0 ) { (, - 1); if( [] > [ - 1] ){ = []; [] = [ - 1]; [ - 1] = ; }}} (){[6] = {, , , , , }; (, 5); }} > Type: state Hardness: 40 Purpose: The function "bubbles" the smallest value to the last element of the array // ---------------------------------------------------- // 1500 // Function.Call.Recursive.Mid.Side effect // Recursive function calls - mid recursive, i.e., local work both before and after recursive call, result is printed // Down-Up Counting # 1500 Function.Call.Recursive.Mid.Side effect > {(){ if( > 0 ) {<< ; ( - 1); << ; }}(){ = ;(); }} > Type: debug_output Hardness: 20 Purpose: The function prints counting down from to 1, followed by counting up from 1 to // Demo // Up-down counting to a parameter # 1501 Function.Call.Recursive.Mid.Side effect > [,,]{(, ){ if( < ) {<< ; ( + 1, ); << ; }}(){ = ;(, ); }} > Type: debug_output Hardness: 20 Purpose: The function prints counting up from to , followed by counting down from to // Printing in reverse order of reading # 1502 Function.Call.Recursive.Mid.Side effect > [,,,,,]{(){ ; if( < ) { >> ; ( + 1); << ; } }(){ ( 0 ); }} > Input: "\n\n\n\n\n" > Type: debug_output Hardness: 30 Purpose: The function prints numbers in opposite order of reading them // Pretest // Two numbers moving towards each other # 1503 Function.Call.Recursive.Mid.Side effect > [,]{(, ){ if( > ) {<< ; ( - 1, + 1); << ; }}(){ = ; = ;(, ); }} > Type: debug_output Hardness: 30 Purpose: The function prints numbers counting down from followed by counting up from . // Posttest // Two numbers moving away from each other # 1504 Function.Call.Recursive.Mid.Side effect > [,]{(, ){ if( < ) {<< ; ( + 1, - 1); << ; }}(){ = ; (, ); }} > Type: debug_output Hardness: 30 Purpose: The function prints numbers counting up and down from // ---------------------------------------------------- // 1525 // Function.Call.Recursive.Mid.Scalar output // Recursive function calls - mid recursive, i.e., local work both before and after recursive call, result is returned // Demo // Smallest among the input number sequence till sentinel encountered # 1525 Function.Call.Recursive.Mid.Scalar output > [,,,,,]{(){ ; ; >> ; if( != ) { = (); if( < ) return ; else return ; } else return ; } (){ << (); }} > Input: "\n\n\n\n\n\n" > Type: debug_output Hardness: 30 Purpose: The function returns the smallest value read before the sentinel // Counts number of decrements from one element to the next until a number is repeated # 1526 Function.Call.Recursive.Mid.Scalar output > [,,,,,]{( ){ ; ; >> ; if( == ) return 0; else { = ( ); if( < ) return + 1; else return ; } } (){; >> ; << ( ); }} > Input: "\n\n\n\n\n\n\n" > Type: debug_output Hardness: 30 Purpose: The function returns the number of times a larger number is read before a smaller number // Largest of the first n numbers in input number sequence # 1527 Function.Call.Recursive.Mid.Scalar output > [,,,,,]{( ){ if( > 0 ) {; ; >> ; = ( - 1 ); if( > ) return ; else return ; } else return 0; } (){ << ( ); }} > Input: "\n\n\n\n\n\n" > Type: debug_output Hardness: 30 Purpose: The function returns the largest of the first numbers read // Pretest // Largest possible product of two adjacent numbers, 0 is the sentinel # 1528 Function.Call.Recursive.Mid.Scalar output > [,,,,,]{( ){ ; ; >> ; if( == 0 ) return 0; else { = ( ); if( * < ) return ; else return * ; } } (){; >> ; << ( ); }} > Input: "\n\n\n\n\n\n0" > Type: debug_output Hardness: 30 Purpose: The function returns the largest product of two numbers read back to back // Posttest // Smallest possible sum of two adjacent numbers, count of numbers passed as parameter # 1529 Function.Call.Recursive.Mid.Scalar output > [,,,,,]{( , ){ ; ; >> ; if( == 0 ) return 9; else { = ( , - 1 ); if( + > ) return ; else return + ; } } (){; >> ; << ( , ); }} > Input: "\n\n\n\n\n\n\n" > Type: debug_output Hardness: 40 Purpose: The function returns the smallest sum of two numbers read back to back // // Counts number of monotonically decreasing elements in a sequence // # 1527 // Function.Call.Recursive.Mid.Scalar output // > // // Does not work // // [,,,,,]{( ){ = 1; ; >> ; if( <= ){ = 1 + ( ); } else = 1; return ; } (){; >> ; << ( ); }} // > // // Input: "\n\n\n\n\n\n" // Input: "\n\n\n\n\n\n" // > // Type: debug_output // Hardness: 30 // // Works // // [,,,,,]{( ){ = 1; ; >> ; if( > ) = 1; else = ( ) + 1; return ; } (){; >> ; << ( ); }} // // Works // // [,,,,,]{( ){ = 1; ; >> ; if( <= ){ return ( ) + 1; } else return 1; } (){; >> ; << ( ); }} // ---------------------------------------------------- // 1550 // Function.Call.Recursive.Mid.Vector output // Recursive function calls - mid recursive, i.e., local work both before and after recursive call, result is passed by reference // Pretest // Write an increasing sequence into the two halves of an array # 1550 Function.Call.Recursive.Mid.Vector output > {([],, ){ if( < 3 ) { [] = ; (, + 1, + 1); [ + 3] = ; } } (){[6] = {0, 0, 0, 0, 0, 0}; (, 0, ); } } > Type: state Hardness: 20 Purpose: The function assigns an increasing sequence of numbers to the two halves of the array back to back // Posttest // Fan out array values from the center # 1551 Function.Call.Recursive.Mid.Vector output > {([], ){ if( <= 3 ) { [3 - ] = ; (, + 1); [3 + ] = ; } } (){[7] = {0, 0, 0, 0, 0, 0, 0}; (, 1 ); } } > Type: state Hardness: 20 Purpose: The function assigns a mirrored sequence of numbers to the two halves of the array // Copy elements forward and bleed backward # 1552 Function.Call.Recursive.Mid.Vector output > [, , , , , ]{([],){ if( < 5 ) { [] = [ + 1]; (, + 1); [] = [ + 1]; } } (){[6] = {,,,,,}; (, 0 ); } } > Type: state Hardness: 30 Purpose: The function shifts the array elements up by one and overwrites them with the last value // If a[n] > a[n-1], a[n]++, and vice versa - increasing contrast # 1553 Function.Call.Recursive.Mid.Vector output > {([],){ if( < 6 ) { if( [] > [ - 1] ){[] = [] + 1;} (, + 1); } if( [] < [ - 1] ){[] = [] - 1;} } (){[6] = {, , , , , }; (, 1 ); } } > Type: state Hardness: 30 Purpose: The function increases the contrast between adjacent elements by incrementing the larger value and decrementing the smaller value // Copy elements backward and bleed forward # 1554 Function.Call.Recursive.Mid.Vector output > [, , , , , ]{([],){ if( > 0 ) { [] = [ - 1]; (, - 1); [] = [ - 1]; } } (){[6] = {,,,,,}; (, 5 ); } } > Type: state Hardness: 30 Purpose: The function shifts the array elements down by one and overwrites them with the first value // Cumulation of numbers in forward order followed by reverse order # 1555 Function.Call.Recursive.Mid.Vector output > {([],){ if( < 5 ) { [ + 1] = [] + [ + 1]; (, + 1); [] = [] + [ + 1]; } } (){[6] = {, , , , , }; (, 0 ); }} > Type: state Hardness: 30 Purpose: The function adds to each array element the sum of all the elements before it and again by the sum of all the elements after it // Reading into an array in forward and reverse order # 1556 Function.Call.Recursive.Mid.Vector output > [,,,,,,,]{([],){ if( < 4 ) { ; >> ; [] = [] + ; (, + 1); >> ; [] = [] + ; } } (){[4] = {0, 0, 0, 0}; (, 0 ); }} > Input: "\n\n\n\n\n\n\n\n" > Type: state Hardness: 30 Purpose: The function reads into array elements in order, followed by reading and adding to the elements in reverse order // Demo // Bubble sort - largest number bubbles to the start, and smallest number bubbles to the end # 1557 Function.Call.Recursive.Mid.Vector output > [, , , , , ]{([],){ ; if( [] > [ - 1] ){ = []; [] = [ - 1]; [ - 1] = ; } if( > 0 ) { (, - 1); if( [] > [ - 1] ){ = []; [] = [ - 1]; [ - 1] = ; }}} (){[6] = {,,,,,}; (, 5); }} > Type: state Hardness: 40 Purpose: The function "bubbles" the largest value to the first element and the smallest value to the last element of the array // Sum all the elements, replace them with their complements wrt the sum # 1558 Function.Call.Recursive.Mid.Vector output > [, , , , , ]{([],,){ if( < 6 ){ = + []; ( , + 1, ); [] = - []; } } (){[6] = {,,,,,}; (, 0, 0 ); }} > Type: state Hardness: 30 Purpose: The function replaces each element by the sum of all the elements before it // ---------------------------------------------------- // 1600 // Function.Call.Recursive.Multiple // Multiple recursive calls in a statement // Demo // Fibonacci numbers # 1600 Function.Call.Recursive.Multiple > // switch version results in stack overflow - either of the two versions // {(){ switch( ) { case 0: return 0; case 1: return 1; default: return ( - 1 ) + ( - 2); } return 0; }(){ = ;<< (); }} // {(){ ; switch( ){ case 0: = 0; case 1: = 1; default: = ( - 1 ) + ( - 2); } return ; }(){ = ;<< (); }} {(){ if( <= 1 ) return ; else return ( - 1 ) + ( - 2); }(){ = ;<< (); }} > Type: debug_output Hardness: 20 Purpose: The function returns Fibonacci number // Quotient of factorials # 1601 Function.Call.Recursive.Multiple > {(){ if( > 0 ) { return * ( - 1); } else return 1; }(){ = ;<< () / ( - 1 ); }} > Type: debug_output Hardness: 20 Purpose: The function returns ! / ( - 1) ! // Difference of Arithmetic progressions # 1602 Function.Call.Recursive.Multiple > {(){ if( > 0 ) { return + ( - 1); } else return 0; }(){ = ;<< () - ( - ); }} > Type: debug_output Hardness: 20 Purpose: The function returns the sum of consecutive numbers up to // Pretest // Difference in the sums of left and right halfs # 1603 Function.Call.Recursive.Multiple > // [, , , , , ]{([],,){ if( <= ){ return [] + ( , + 1, ); } else return 0; } (){[8] = {,,,,,,,}; << (, 0, 3 ) - (, 4, 7); }} [, , , , , ]{([],,){ if( <= ){ return [] + ( , + 1, ); } else return 0; } (){[8] = {,,,,,,,}; << (, 0, 3 ) - (, 4, 7); }} > Type: debug_output Hardness: 30 Purpose: The function returns the difference between the sums of left and right halves of the array // Difference in the largest of left and right halfs # 1604 Function.Call.Recursive.Multiple > // [, , , , , ]{([],,){ if( < ){ = ( , + 1, ); if( > [] ) return ; else return []; } else return []; } (){[8] = {,,,,,,,}; << (, 0, 3 ) - (, 4, 7); }} [, , , , , ]{([],,){ if( < ){ = ( , + 1, ); if( > [] ) return ; else return []; } else return []; } (){[8] = {,,,,,,,}; << (, 0, 3 ) - (, 4, 7); }} > Type: debug_output Hardness: 30 Purpose: The function returns the difference between the largest values of the left and right halves of the array // Posttest // Difference in the sums of odd and even elements # 1605 Function.Call.Recursive.Multiple > // [, , , , , ]{([],){ if( < 8 ){ return [] + ( , + 2 ); } else return 0; } (){[8] = {,,,,,,,}; << (, 0 ) - (, 1 ); }} [, , , , , ]{([],){ if( < 8 ){ return [] + ( , + 2 ); } else return 0; } (){[8] = {,,,,,,,}; << (, 0 ) - (, 1 ); }} > Type: debug_output Hardness: 30 Purpose: The function returns the difference between the sums of odd and even elements of the array // // Printing an expression involving the parameter // # 500 // Function.Call.Recursive // ? // Function.{PostCall,Parameters.One,ParPass.Value} // > // {(){if( > 0){ = - 1;();}<<;}(){; = ;();<<;}} // > // Type: output // Hardness: 50 // ------------------ Parsons Puzzles -------------------------------------------------------- // Factors on hardness scale // Parameter passing // Function does not versus does return a value // Functions have the same local variable by name // Types of functions: // Input (with do-while and return value) // Compute (with parameters and return type, and control statements) // Output (with parameters, pretty printing) // Learning objectives: // Function.Parsons.OneFun.OneCall - 2000 // main calling one other function once // Function.Parsons.OneFun.ManyCall - 2025 // main calling one other function repeatedly // Function.Parsons.ManyFun.OneCall - 2050 // main calling many other functions once each // Function.Parsons.Recursive - 2075 // main calls a recursive function // -------------------------------------------------------------------------------------------- // Selection.ifElse.Parsons.Single.Simple - 2000 // One input: 2000-; Two inputs: 2005- // DemoParsons // Prints whether the number is odd or even # 2000 Function.Parsons.OneFun.OneCall > "It reads and validtes a number (1-100), computes whether it is odd or even and prints it." {() { ; do{ << "Enter a number (1-100)"; >> ; } while( < 1 || > 100 ); return ; } (){ /* Declare */ ; = (); if( % 2 == 0 ) {<< << " is even";} else {<< << " is odd";} }} > Type: parsons Hardness: 20 // DemoParsons // Prints whether the number is odd or even # 2001 Function.Parsons.OneFun.OneCall > "It reads and validtes a number (1-100), computes whether it is odd or even and prints it." {() { ; do{ << "Enter a number (1-100)"; >> ; } while( < 1 || > 100 ); return ; } (){ if( % 2 == 0 ) {return true;} else {return false;} } (){ /* Declare */ ; = (); if( () == true ) {<< << " is even";} else {<< << " is odd";} }} > Type: parsons Hardness: 20 // DemoParsons // Prints whether the number is odd or even # 2002 Function.Parsons.OneFun.OneCall > "It reads and validtes a number (1-100), computes whether it is odd or even and prints it." {() { ; do{ << "Enter a number (1-100)"; >> ; } while( < 1 || > 100 ); return ; } (){ if( % 2 == 0 ) {return true;} else {return false;} } (, ) { if( == true ) {<< << " is even";} else {<< << " is odd";} } (){ /* Declare */ ; = (); = (); (, ); }} > Type: parsons Hardness: 20 // -------------------------------------------------------------------------- // Templates here are for demonstration purposes // Included at the end so that regular practice does not pick up these templates // How to enter an output # 90 Demonstration > {(){=;<<;}} > Type: output Hardness: 10 // How to enter multiple outputs # 91 Demonstration > {(){=;<<;=;<<;<< - ;}} > Type: output Hardness: 10 // How to enter NO output # 92 Demonstration > {(){=;=;; = + ;}} > Type: output Hardness: 10 // ------------------------------------------------------------------------------ // Templates used for the trial run // Intentionally do not provide correct learning objectives, // so that trial run does not affect student's learning objectives // Semantic error # 95 Demonstration > {(){;<<;}} > Type: debug Hardness: 10 // Code OK # 96 Demonstration > {(){=;=;<< - ;}} > Type: debug Hardness: 10 // Syntax error # 97 Demonstration > {(){{;}<<;}} > Type: debug Hardness: 10