// Copyright Amruth N. Kumar, amruth@computer.org // This is the master plan for the different loops // [Single Loop] // Skip - Zero Iteration // // PassThrough - One Iteration // // Infinite // // [Many Iterations] - Normal case, not mentioned // Initialization // Yes // No // // Condition // No // [Exists] // Arithmetic // [True] // [False] // Logical // [Short Circuit + Side Effect] // [No Short Circuit] // Assignment // [True] // [False] // Relational // Boundary does not change // Boundary changes // Declaration // same variable declared both before and in header, // and printed both in and after loop // // Action // Empty [statement] // Simple [statement] // Compound [statement] // // Update // None // After [body] // [Keyboard input] // [Expression] // Before [body] // [Keyboard input] // [Expression] // // PostLoop [Resume after loop] // // Multiple [Back to back] // Dependent // [2 loop problems] - degrees of hardness // [3 loop problems] - degrees of hardness // [All loops of same type] - degrees of hardness // [Loops of different types] - degrees of hardness // Up [Counting] // Down [Counting] // // Independent // [2 loop problems] - degrees of hardness // [3 loop problems] - degrees of hardness // [All loops of same type] - degrees of hardness // [Loops of different types] - degrees of hardness // Up [Counting] // Down [Counting] // // Nested // Dependent // [2 loop problems] - degrees of hardness // [3 loop problems] - degrees of hardness // [All loops of same type] - degrees of hardness // [Loops of different types] - degrees of hardness // Up [Counting] // Down [Counting] // // Independent // [2 loop problems] - degrees of hardness // [3 loop problems] - degrees of hardness // [All loops of same type] - degrees of hardness // [Loops of different types] - degrees of hardness // Up [Counting] // Down [Counting] // // ---------------------------------------------------------------- // Other factors that affect template hardness: // Loop body: // Just a print statement // a constant // the loop counter // a simple expression involving the loopvar // the loopvar, boundary value (when boundary is a variable or expression) // an expression involving the loopvar and boundary value (when // it is a variable) - No, too complicated // an if-else statement with different variables in the two clauses // // Note that the type of operator, and its subtypes determine hardness, // not learning objectives. // Zero iterations // < > // far off value // boundary value // <= >= // far off value // == // far off value // != // same value // Only One iteration // Multiple iterations // < > // far off value // <= >= // far off value // boundary value // == // same value // != // n-removed value // ---------------------------------------------------- // These are the actual learning objectives // 100 // Iteration.Logic.Pretest.Skip // Iteration.Logic.Pretest.PassThrough // 150 // Iteration.Logic.Pretest.Initialization.No // Iteration.Logic.Pretest.Initialization.Yes // 225 // Iteration.Logic.Pretest.Condition.No // Iteration.Logic.Pretest.Condition.Arithmetic // Iteration.Logic.Pretest.Condition.Logical // Iteration.Logic.Pretest.Condition.Assignment // Iteration.Logic.Pretest.Condition.Relational // Iteration.Logic.Pretest.Condition.Declaration // Iteration.Logic.Pretest.Condition.Changing // 400 // Iteration.Logic.Pretest.Action.Empty // Iteration.Logic.Pretest.Action.Simple // Iteration.Logic.Pretest.Action.Compound // 525 // Iteration.Logic.Pretest.Update.No // Iteration.Logic.Pretest.Update.Before // Iteration.Logic.Pretest.Update.After // 650 // Iteration.Logic.Pretest.PostLoop // 675 // Iteration.Logic.Pretest.Multiple.Dependent // Iteration.Logic.Pretest.Multiple.Independent // // Iteration.Logic.Pretest.Nested.Dependent // Iteration.Logic.Pretest.Nested.Independent // 800 // Iteration.Logic.Pretest.Infinite //****************** WHILE LOOPS *************************************** // ------------------------------------------------------------------------ // Pretest.Skip ************************************ //Empty Loops *************************** 100 # 100 Pretest.Skip > {(){=;while( > ){<<; = - 1;}}} > Type: output Hardness: 50 # 101 Pretest.Skip > {(){=;while( == ){<<;<<; = + 1;}}} > Type: output Hardness: 50 # 102 Pretest.Skip > {(){=;while( < ){<<; = + 1;<<;}}} > Type: output Hardness: 50 # 103 Pretest.Skip > {(){=;while( >= ){<<;<<; = - 1;}}} > Type: output Hardness: 50 # 104 Pretest.Skip > {(){=;while( != ){<<;<<; = + 1;}}} > Type: output Hardness: 50 # 105 Pretest.Skip > {(){=;while( <= ){<<; = + 1;<<;}}} > Type: output Hardness: 50 # 106 Pretest.Skip > {(){=;=;while( > ){<<; = - 1;<<;}}} > Type: output Hardness: 50 # 107 Pretest.Skip > {(){=;=;while( == ){<<;<<; = + 1;}}} > Type: output Hardness: 50 # 108 Pretest.Skip > {(){=;=;while( < ){<<; = + 1;<<;}}} > Type: output Hardness: 50 # 109 Pretest.Skip > {(){=;=;while( >= ){<<;<<; = - 1;}}} > Type: output Hardness: 50 # 110 Pretest.Skip > {(){=;=;while( != ){<<;<<; = + 1;}}} > Type: output Hardness: 50 # 111 Pretest.Skip > {(){=;=;while( <= ){<<; = + 1;<<;}}} > Type: output Hardness: 50 // ------------------------------------------------------------------------ // Pretest.PassThrough ************************************ 125 # 125 Pretest.PassThrough > // {(){=; = - 1;while( < ){<<; = + 1;}}} {(){=;while( < ){<<; = + 1;}}} > Type: output Hardness: 50 # 126 Pretest.PassThrough > // {(){=; = + 1;while( > ){<<; = - 1;}}} {(){=;while( > ){<<; = - 1;}}} > Type: output Hardness: 50 # 127 Pretest.PassThrough > {(){=;while( == ){<<; = + 1;}}} > Type: output Hardness: 50 # 128 Pretest.PassThrough > {(){=;while( <= ){<<; = + 1;}}} > Type: output Hardness: 60 # 129 Pretest.PassThrough > {(){=;while( >= ){<<; = - 1;}}} > Type: output Hardness: 60 # 130 Pretest.PassThrough > {(){=;while( != ){<<; = ;}}} > Type: output Hardness: 50 # 131 Pretest.PassThrough > {(){=;while( < ){<<; = ;}}} > Type: output Hardness: 50 # 132 Pretest.PassThrough > {(){=;while( > 0){<<; = - ;}}} > Type: output Hardness: 60 # 133 Pretest.PassThrough > {(){=;=;while( == ){<<;<<; = - 1;}}} > Type: output Hardness: 50 # 134 Pretest.PassThrough > {(){=;while( <= ){<<; = * 2;}}} > Type: output Hardness: 50 # 135 Pretest.PassThrough > {(){=;=;while( >= ){<<; = - 1;}}} > Type: output Hardness: 50 # 136 Pretest.PassThrough > // {(){=;=; = + 1;while( != ){<<;<<; = + 1;}}} {(){=; = ;while( != ){<<;<<; = + 1;}}} > Type: output Hardness: 50 # 137 Pretest.PassThrough > // {(){=; = ; = + 1;while( < ){<<;<<; = + 1;}}} {(){=; = ;while( < ){<<;<<; = + 1;}}} > Type: output Hardness: 50 # 138 Pretest.PassThrough > // {(){=;=; = - 1;while( > ){<<;<<; = - 1;}}} {(){=; = ;while( > ){<<;<<; = - 1;}}} > Type: output Hardness: 50 # 139 Pretest.PassThrough > {(){=;=;while( == ){<<; = ;<<;}}} > Type: output Hardness: 50 # 140 Pretest.PassThrough > {(){=;=;while( <= ){<<; = + 1;}}} > Type: output Hardness: 60 # 141 Pretest.PassThrough > {(){=;=;while( >= ){<<; = - 1;}}} > Type: output Hardness: 50 # 142 Pretest.PassThrough > {(){=;=;while( != ){<<;<<; = ;}}} > Type: output Hardness: 50 // ------------------------------------------------------------------------ // Pretest.Initialization.No ************************************ 150 // # 125 // Pretest.Initialization.No // > // {(){;while( < 6){<<; = + 1;}}} // > // Type: output // Hardness: 20 // ------------------------------------------------------------------------ // Pretest.Initialization.Yes ************************************ // ------------------------------------------------------------------------ // Pretest.Condition.No ************************************ 225 // ------------------------------------------------------------------------ // Pretest.Condition.Arithmetic ************************************ 250 // ------------------------------------------------------------------------ // Pretest.Condition.Logical ************************************ 275 // ------------------------------------------------------------------------ // Pretest.Condition.Assignment ************************************ 300 // ------------------------------------------------------------------------ // Pretest.Condition.Relational ************************************ 325 // Using a constant as boundary value, update by one # 325 Pretest.Condition.Relational ? Pretest.Update.After > {(){=;while( < ){<<; = + 1;}}} > Type: output Hardness: 20 # 326 Pretest.Condition.Relational ? Pretest.Update.After > {(){=;while( > ){<<; = - 1;}}} > Type: output Hardness: 50 # 327 Pretest.Condition.Relational ? Pretest.Update.After > {(){=;while( <= ){<<; = + 1;}}} > Type: output Hardness: 20 # 328 Pretest.Condition.Relational ? Pretest.Update.After > {(){=;while( >= ){<<; = - 1;}}} > Type: output Hardness: 50 # 329 Pretest.Condition.Relational ? Pretest.Update.After > {(){=;while( != ){<<; = + 1;}}} > Type: output Hardness: 50 // Using a variable to hold boundary value, update by one # 330 Pretest.Condition.Relational ? Pretest.Update.After > {(){=;=;while( < ){<<; = + 1;}}} > Type: output Hardness: 50 # 331 Pretest.Condition.Relational ? Pretest.Update.After > {(){=;=;while( > ){<<; = - 1;}}} // {(){=;=;while( > ){<<; = + 1;}}} > Type: output Hardness: 50 # 332 Pretest.Condition.Relational ? Pretest.Update.After > {(){=;=;while( <= ){<<; = + 1;}}} // {(){=;=;while( <= ){<<; = - 1;}}} > Type: output Hardness: 60 # 333 Pretest.Condition.Relational ? Pretest.Update.After > {(){=;=;while( >= ){<<; = - 1;}}} > Type: output Hardness: 60 # 334 Pretest.Condition.Relational ? Pretest.Update.After > {(){=;=;while( != ){<<; = + 1;}}} // {(){=;=;while( != ){<<; = + 1;<<;}}} // Simplified for S08 > Type: output Hardness: 50 # 335 Pretest.Condition.Relational ? Pretest.Update.After > {(){=;=;while( != ){<<; = - 1;}}} // {(){=;=;while( != ){<<; = - 1;<<;}}} // Simplified for S08 > Type: output Hardness: 50 // Using a constant to hold boundary value, update by more than one # 336 Pretest.Condition.Relational ? Pretest.Update.After > {(){=;while( < ){<<; = + ;}}} > Type: output Hardness: 20 # 337 Pretest.Condition.Relational ? Pretest.Update.After > {(){=;while( > ){<<; = - ;}}} > Type: output Hardness: 50 # 338 Pretest.Condition.Relational ? Pretest.Update.After > {(){=;while( <= ){<<; = + ;}}} > Type: output Hardness: 20 # 339 Pretest.Condition.Relational ? Pretest.Update.After > {(){=;while( >= ){<<; = - ;}}} > Type: output Hardness: 50 // Using a variable to hold boundary value, update by more than one # 340 Pretest.Condition.Relational ? Pretest.Update.After > {(){=;=;while( < ){<<; = + ;}}} > Type: output Hardness: 50 # 341 Pretest.Condition.Relational ? Pretest.Update.After > {(){=;=;while( > ){<<; = - ;}}} > Type: output Hardness: 50 # 342 Pretest.Condition.Relational ? Pretest.Update.After > {(){=;=;while( <= ){<<; = + ;}}} // {(){=;=;while( <= ){<<; = - ;}}} > Type: output Hardness: 60 # 343 Pretest.Condition.Relational ? Pretest.Update.After > {(){=;=;while( >= ){<<; = - ;}}} // {(){=;=;while( >= ){<<; = + ;}}} > Type: output Hardness: 60 # 344 Pretest.Condition.Relational ? Pretest.Update.After > // {(){=;; = + * ; while( != ){<<; = + ;}}} [,,,]{(){=; = ; while( != ){<<; = + ;}}} > Type: output Hardness: 70 # 345 Pretest.Condition.Relational ? Pretest.Update.After > // {(){=;; = + * ; while( != ){<<; = - ;}}} [,,,]{(){=; = ; while( != ){<<; = - ;}}} > Type: output Hardness: 70 # 346 Pretest.Condition.Relational ? Pretest.Update.After > {(){=;=;while( < ){<<; = + ;}}} > Type: output Hardness: 70 # 347 Pretest.Condition.Relational ? Pretest.Update.After > {(){=;=;while( <= ){<<; = + ;}}} > Type: output Hardness: 70 // ------------------------------------------------------------------------ // Pretest.Condition.Declaration ************************************ 350 // # 350 // Pretest.Condition.Declaration // ? // Pretest.Update.After // > // {(){=;while( = ){<<; = - 1;break;}}} // > // Type: output // Hardness: 70 // // # 351 // Pretest.Condition.Declaration // ? // Pretest.Update.After // > // {(){=;while( = ){<<; = - 1;if( < 2){break;}}}} // > // Type: output // Hardness: 70 // // // ------------------------------------------------------------------------ // Pretest.Condition.Changing ************************************ 375 // NOT simplified for S08 since multiple outputs in the loop help student correctly understand behavior of loop // Loop variable and Boundary variable changing in the opposite directions by 1 # 375 Pretest.Condition.Changing > {(){=;=;while( < ){<<;<<; = + 1; = - 1;}}} > Type: output Hardness: 60 # 376 Pretest.Condition.Changing > {(){=;=;while( > ){<<;<<; = - 1; = + 1;}}} > Type: output Hardness: 60 # 377 Pretest.Condition.Changing > {(){=;=;while( <= ){<<;<<; = + 1; = - 1;}}} > Type: output Hardness: 70 # 378 Pretest.Condition.Changing > {(){=;=;while( >= ){<<;<<; = - 1; = + 1;}}} > Type: output Hardness: 70 # 379 Pretest.Condition.Changing > // {(){=;=; = + 6 * ;while( != ){<<;<<; = + ; = - ;}}} [,,]{(){=;=;while( != ){<<;<<; = + ; = - ;}}} > Type: output Hardness: 60 // Loop variable and Boundary variable changing in the opposite directions by the same amount, not 1 # 380 Pretest.Condition.Changing > {(){=;=;while( < ){<<;<<; = + ; = - ;}}} > Type: output Hardness: 70 # 381 Pretest.Condition.Changing > {(){=;=;while( > ){<<;<<; = - ; = + ;}}} > Type: output Hardness: 70 # 382 Pretest.Condition.Changing > {(){=;=;while( <= ){<<;<<; = + ; = - ;}}} > Type: output Hardness: 70 # 383 Pretest.Condition.Changing > {(){=;=;while( >= ){<<;<<; = - ; = + ;}}} > Type: output Hardness: 70 # 384 Pretest.Condition.Changing > // {(){=;=; = + 4 * ;while( != ){<<;<<; = - ; = + ;}}} [,,]{(){=;=;while( != ){<<;<<; = + ; = - ;}}} > Type: output Hardness: 70 // Loop variable and Boundary variable changing in the same direction, but by different amounts # 385 Pretest.Condition.Changing > {(){=;=;while( < ){<<;<<; = + ; = + 1;}}} > Type: output Hardness: 80 # 386 Pretest.Condition.Changing > {(){=;=;while( > ){<<;<<; = - ; = - 1;}}} > Type: output Hardness: 80 # 387 Pretest.Condition.Changing > {(){=;=;while( <= ){<<;<<; = + ; = + 1;}}} > Type: output Hardness: 80 # 388 Pretest.Condition.Changing > {(){=;=;while( >= ){<<;<<; = - ; = - 1;}}} > Type: output Hardness: 80 // ------------------------------------------------------------------------ // Pretest.Action.Empty ************************************ 400 // ------------------------------------------------------------------------ // Pretest.Action.Simple ************************************ 425 // Using a constant as boundary value, update by one # 425 Pretest.Action.Simple > {(){=;while( < ) = + 1;<<;}} > Type: output Hardness: 60 # 426 Pretest.Action.Simple > {(){=;while( > ) = - 1;<<;}} > Type: output Hardness: 60 # 427 Pretest.Action.Simple > {(){=;while( <= ) = + 1;<<;}} > Type: output Hardness: 60 # 428 Pretest.Action.Simple > {(){=;while( >= ) = - 1;<<;}} > Type: output Hardness: 60 # 429 Pretest.Action.Simple > {(){=;while( != ) = + 1;<<;}} > Type: output Hardness: 60 // Using a variable to hold boundary value, update by one # 430 Pretest.Action.Simple > {(){=;=;while( < ) = + 1;<<;}} > Type: output Hardness: 60 # 431 Pretest.Action.Simple > {(){=;=;while( > ) = - 1;<<;}} > Type: output Hardness: 60 # 432 Pretest.Action.Simple > {(){=;=;while( <= ) = + 1;<<;}} > Type: output Hardness: 70 # 433 Pretest.Action.Simple > {(){=;=;while( >= ) = - 1;<<;}} > Type: output Hardness: 70 # 434 Pretest.Action.Simple > {(){=;=;while( != ) = + 1;<<;}} // {(){=;=;while( != ) = + 1;<<;<<;}} // Simplified for S08 > Type: output Hardness: 60 # 435 Pretest.Action.Simple > {(){=;=;while( != ) = - 1;<<;}} // {(){=;=;while( != ) = - 1;<<;<<;}} // Simplified for S08 > Type: output Hardness: 60 // Using a constant to hold boundary value, update by more than one # 436 Pretest.Action.Simple > {(){=;while( < ) = + ;<<;}} > Type: output Hardness: 50 # 437 Pretest.Action.Simple > {(){=;while( > ) = - ;<<;}} > Type: output Hardness: 60 # 438 Pretest.Action.Simple > {(){=;while( <= ) = + ;<<;}} > Type: output Hardness: 50 # 439 Pretest.Action.Simple > {(){=;while( >= ) = - ;<<;}} > Type: output Hardness: 60 // Using a variable to hold boundary value, update by more than one # 440 Pretest.Action.Simple > {(){=;=;while( < ) = + ;<<;}} > Type: output Hardness: 60 # 441 Pretest.Action.Simple > {(){=;=;while( > ) = - ;<<;}} > Type: output Hardness: 60 # 442 Pretest.Action.Simple > {(){=;=;while( <= ) = + ;<<;}} > Type: output Hardness: 70 # 443 Pretest.Action.Simple > {(){=;=;while( >= ) = - ;<<;}} > Type: output Hardness: 70 # 444 Pretest.Action.Simple > {(){=;; = + * ;while( != ) = + ;<<;}} > Type: output Hardness: 80 # 445 Pretest.Action.Simple > // {(){=;; = + * ;while( != ) = - ;<<;}} [,,,]{(){=; = ;while( != ) = - ;<<;}} > Type: output Hardness: 80 # 446 Pretest.Action.Simple > {(){=;=;while( < ) = + ;<<;}} > Type: output Hardness: 80 # 447 Pretest.Action.Simple > {(){=;=;while( <= ) = + ;<<;}} > Type: output Hardness: 80 // ------------------------------------------------------------------------ // Pretest.Action.Compound ************************************ 450 // ------------------------------------------------------------------------ // Pretest.Update.No ************************************ 525 // ------------------------------------------------------------------------ // Pretest.Update.Before ************************************ 550 // Using a constant for the boundary value, updating by one # 550 Pretest.Update.Before > {(){=;while( < ){ = + 1;<<;}}} > Type: output Hardness: 30 # 551 Pretest.Update.Before > {(){=;while( > ){ = - 1;<<;}}} > Type: output Hardness: 30 # 552 Pretest.Update.Before > {(){=;while( <= ){ = + 1;<<;}}} > Type: output Hardness: 30 # 553 Pretest.Update.Before > {(){=;while( >= ){ = - 1;<<;}}} > Type: output Hardness: 30 # 554 Pretest.Update.Before > {(){=;while( != ){ = + 1;<<;}}} > Type: output Hardness: 30 // Using a variable for the bounday value also, updating by one # 555 Pretest.Update.Before > {(){=;=;while( < ){ = + 1;<<;}}} > Type: output Hardness: 30 # 556 Pretest.Update.Before > {(){=;=;while( > ){ = - 1;<<;}}} > Type: output Hardness: 30 # 557 Pretest.Update.Before > {(){=;=;while( <= ){ = + 1;<<;}}} > Type: output Hardness: 40 # 558 Pretest.Update.Before > {(){=;=;while( >= ){ = - 1;<<;}}} > Type: output Hardness: 40 # 559 Pretest.Update.Before > {(){=;=;while( != ){ = + 1;<<;}}} // {(){=;=;while( != ){ = + 1;<<;<<;}}} // Simplified for S08 > Type: output Hardness: 30 # 560 Pretest.Update.Before > {(){=;=;while( != ){ = - 1;<<;}}} // {(){=;=;while( != ){ = - 1;<<;<<;}}} // Simplified for S08 > Type: output Hardness: 30 // Using a constant for the boundary value, updating by more than one # 561 Pretest.Update.Before > {(){=;while( < ){ = + ;<<;}}} > Type: output Hardness: 30 # 562 Pretest.Update.Before > {(){=;while( > ){ = - ;<<;}}} > Type: output Hardness: 60 # 563 Pretest.Update.Before > {(){=;while( <= ){ = + ;<<;}}} > Type: output Hardness: 30 # 564 Pretest.Update.Before > {(){=;while( >= ){ = - ;<<;}}} > Type: output Hardness: 60 // Using a variable for the boundary value, updating by more than one # 565 Pretest.Update.Before > {(){=;=;while( < ){ = + ;<<;}}} > Type: output Hardness: 60 # 566 Pretest.Update.Before > {(){=;=;while( > ){ = - ;<<;}}} > Type: output Hardness: 60 # 567 Pretest.Update.Before > {(){=;=;while( <= ){ = + ;<<;}}} > Type: output Hardness: 70 # 568 Pretest.Update.Before > {(){=;=;while( >= ){ = - ;<<;}}} > Type: output Hardness: 70 # 569 Pretest.Update.Before > {(){=;; = + * ; while( != ){ = + ;<<;}}} > Type: output Hardness: 70 # 570 Pretest.Update.Before > // {(){; = + * ; while( != ){ = - ;<<;}}} [,,,]{(){ = ; while( != ){ = - ;<<;}}} > Type: output Hardness: 70 // Using a variable for the boundary value, updating by the loop variable itself # 571 Pretest.Update.Before > {(){=;=;while( < ){ = + ;<<;}}} > Type: output Hardness: 80 # 572 Pretest.Update.Before > {(){=;=;while( <= ){ = + ;<<;}}} > Type: output Hardness: 80 // ------------------------------------------------------------------------ // Pretest.Update.After ************************************ 575 // All Condition.Relational templates are also Update.After (body) templates so far // ------------------------------------------------------------------------ // Pretest.PostLoop ************************************ 650 // Using a constant as boundary value, update by one # 650 Pretest.PostLoop > {(){=;while( < ){<<; = + 1;}<<;}} > Type: output Hardness: 30 # 651 Pretest.PostLoop > {(){=;while( <= ){<<; = + 1;}<<;}} > Type: output Hardness: 30 # 652 Pretest.PostLoop > {(){=;while( > ){<<; = - 1;}<<;}} > Type: output Hardness: 40 # 653 Pretest.PostLoop > {(){=;while( >= ){<<; = - 1;}<<;}} > Type: output Hardness: 40 # 654 Pretest.PostLoop > {(){=;while( != ){<<; = + 1;}<<;}} > Type: output Hardness: 30 // Using a variable to hold boundary value, update by one # 655 Pretest.PostLoop > {(){=;=;while( < ){<<; = + 1;}<<;}} > Type: output Hardness: 30 # 656 Pretest.PostLoop > {(){=;=;while( <= ){<<; = + 1;}<<;}} // {(){=;=;while( <= ){<<; = - 1;}<<;}} > Type: output Hardness: 40 # 657 Pretest.PostLoop > // {(){=;=;while( > ){<<; = + 1;}<<;}} {(){=;=;while( > ){<<; = - 1;}<<;}} > Type: output Hardness: 30 # 658 Pretest.PostLoop > {(){=;=;while( >= ){<<; = - 1;}<<;}} > Type: output Hardness: 40 # 659 Pretest.PostLoop > {(){=;=;while( != ){<<; = + 1;}<<;}} // {(){=;=;while( != ){<<; = + 1;<<;}<<;}} // Simplified for S08 > Type: output Hardness: 30 # 660 Pretest.PostLoop > {(){=;=;while( != ){<<; = - 1;}<<;}} // {(){=;=;while( != ){<<; = - 1;<<;}<<;}} // Simplified for S08 > Type: output Hardness: 40 // Using a constant to hold boundary value, update by more than one # 661 Pretest.PostLoop > {(){=;while( < ){<<; = + ;}<<;}} > Type: output Hardness: 30 # 662 Pretest.PostLoop > {(){=;while( <= ){<<; = + ;}<<;}} > Type: output Hardness: 30 # 663 Pretest.PostLoop > {(){=;while( > ){<<; = - ;}<<;}} > Type: output Hardness: 40 # 664 Pretest.PostLoop > {(){=;while( >= ){<<; = - ;}<<;}} > Type: output Hardness: 40 // Using a variable to hold boundary value, update by more than one # 665 Pretest.PostLoop > {(){=;=;while( < ){<<; = + ;}<<;}} > Type: output Hardness: 30 # 666 Pretest.PostLoop > {(){=;=;while( <= ){<<; = + ;}<<;}} // {(){=;=;while( <= ){<<; = - ;}<<;}} > Type: output Hardness: 40 # 667 Pretest.PostLoop > {(){=;=;while( > ){<<; = - ;}<<;}} > Type: output Hardness: 40 # 668 Pretest.PostLoop > {(){=;=;while( >= ){<<; = - ;}<<;}} // {(){=;=;while( >= ){<<; = + ;}<<;}} > Type: output Hardness: 30 # 669 Pretest.PostLoop > // {(){=;; = + * ; while( != ){<<; = + ;}<<;}} [,,,]{(){=; = ; while( != ){<<; = + ;}<<;}} > Type: output Hardness: 30 # 670 Pretest.PostLoop > // {(){=;; = + * ; while( != ){<<; = - ;}<<;}} [,,,]{(){=; = ; while( != ){<<; = - ;}<<;}} > Type: output Hardness: 40 # 671 Pretest.PostLoop > {(){=;=;while( < ){<<; = + ;}<<;}} > Type: output Hardness: 30 # 672 Pretest.PostLoop > {(){=;=;while( <= ){<<; = + ;}<<;}} > Type: output Hardness: 30 // ------------------------------------------------------------------------ // Pretest.Multiple.Dependent ************************************ 675 // 2 loops // UpUp - Update by 1 vs many - use first loop variable's value as second loop's start value/end value // UpDown - Update by 1 vs many // DownUp - Update by 1 vs many // DownDown - Update by 1 vs many // Up X Up X update by 1 # 675 Pretest.Multiple.Dependent > {(){=;while( < ){<<; = + 1;}while( <= ){<<; = + 1;}}} > Type: output Hardness: 80 # 676 Pretest.Multiple.Dependent > {(){=;while( < ){<<; = + 1;}=;while( <= ){<<; = + 1;}}} > Type: output Hardness: 80 // Up X Up X Update by many # 677 Pretest.Multiple.Dependent > {(){=;while( < ){<<; = + ;}while( <= ){<<; = + ;}}} > Type: output Hardness: 80 # 678 Pretest.Multiple.Dependent > {(){=;while( < ){<<; = + ;}; = ;while( <= ){<<; = + ;}}} > Type: output Hardness: 80 // Up X Down X update by 1 # 679 Pretest.Multiple.Dependent > {(){=;while( < ){<<; = + 1;}while( >= ){<<; = - 1;}}} > Type: output Hardness: 80 # 680 Pretest.Multiple.Dependent > {(){=;while( < ){<<; = + 1;}=;while( >= ){<<; = - 1;}}} > Type: output Hardness: 80 // Up X Down X Update by many # 681 Pretest.Multiple.Dependent > {(){=;while( < ){<<; = + ;}while( >= ){<<; = - ;}}} > Type: output Hardness: 80 # 682 Pretest.Multiple.Dependent > {(){=;while( < ){<<; = + ;}=;while( >= ){<<; = - ;}}} > Type: output Hardness: 80 // Down X Up X Update by 1 # 683 Pretest.Multiple.Dependent > {(){=;while( > ){<<; = - 1;}while( <= ){<<; = + 1;}}} > Type: output Hardness: 80 # 684 Pretest.Multiple.Dependent > {(){=;while( >= ){<<; = - 1;}=;while( < ){<<; = + 1;}}} > Type: output Hardness: 80 // Down X Up X Update by many # 685 Pretest.Multiple.Dependent > {(){=;while( > ){<<; = - ;}while( <= ){<<; = + ;}}} > Type: output Hardness: 80 # 686 Pretest.Multiple.Dependent > {(){=;while( >= ){<<; = - ;}=;while( < ){<<; = + ;}}} > Type: output Hardness: 80 // Down X Down X Update by 1 # 687 Pretest.Multiple.Dependent > {(){=;while( > ){<<; = - 1;}while( >= ){<<; = - 1;}}} > Type: output Hardness: 80 # 688 Pretest.Multiple.Dependent > {(){=;while( > ){<<; = - 1;}=;while( >= ){<<; = - 1;}}} > Type: output Hardness: 80 // Down X Down X Update by many # 689 Pretest.Multiple.Dependent > {(){=;while( > ){<<; = - ;}while( >= ){<<; = - ;}}} > Type: output Hardness: 80 # 690 Pretest.Multiple.Dependent > {(){=;while( > ){<<; = - ;}=;while( >= ){<<; = - ;}}} > Type: output Hardness: 80 //3-levels # 691 Pretest.Multiple.Dependent > {(){=;while( < ){<<; = + 1;}while( < ){<<; = + 2;}while( < ){<<; = + 3;}}} > Type: output Hardness: 90 # 692 Pretest.Multiple.Dependent > {(){=;while( > ){<<; = - 3;}while( > ){<<; = - 2;}while( > ){<<; = - 1;}}} > Type: output Hardness: 90 // ------------------------------------------------------------------------ // Pretest.Multiple.Independent ************************************ 700 // ------------------------------------------------------------------------ // Pretest.Nested.Dependent ************************************ 725 // 2 loops nested // UpUp - Update by 1 vs many - use outside loop variable's value as inside loop's start value/end value/update value // UpDown - Update by 1 vs many // DownUp - Update by 1 vs many // DownDown - Update by 1 vs many // Up X Up X update by 1 # 725 Pretest.Nested.Dependent > {(){=;;while( < ){<<; = ;while( <= ){<<; = + 1;} = + 1;}}} > Type: output Hardness: 80 # 726 Pretest.Nested.Dependent > {(){=;;while( < ){<<; = ;while( <= ){<<; = + 1;} = + 1;}}} > Type: output Hardness: 80 // Up X Up X Update by many # 727 Pretest.Nested.Dependent > {(){=;;while( < ){<<; = ;while( <= ){<<; = + ;} = + ;}}} > Type: output Hardness: 80 # 728 Pretest.Nested.Dependent > {(){=;;while( < ){<<; = ;while( <= ){<<; = + ;} = + ;}}} > Type: output Hardness: 80 # 729 Pretest.Nested.Dependent > {(){=;;while( < ){<<; = ;while( <= ){<<; = + ;} = + ;}}} > Type: output Hardness: 90 // Up X Down X update by 1 # 730 Pretest.Nested.Dependent > {(){=;;while( < ){<<; = ;while( >= ){<<; = - 1;} = + 1;}}} > Type: output Hardness: 80 # 731 Pretest.Nested.Dependent > {(){=;;while( < ){<<; = ;while( >= ){<<; = - 1;} = + 1;}}} > Type: output Hardness: 80 // Up X Down X Update by many # 732 Pretest.Nested.Dependent > {(){=;;while( < ){<<; = ;while( >= ){<<; = - ;} = + ;}}} > Type: output Hardness: 80 # 733 Pretest.Nested.Dependent > {(){=;;while( < ){<<; = ;while( >= ){<<; = - ;} = + ;}}} > Type: output Hardness: 80 # 734 Pretest.Nested.Dependent > {(){=;;while( < ){<<; = ;while( >= ){<<; = - ;} = + ;}}} > Type: output Hardness: 90 // Down X Up X Update by 1 # 735 Pretest.Nested.Dependent > {(){=;;while( > ){<<; = ;while( <= ){<<; = + 1;} = - 1;}}} > Type: output Hardness: 80 # 736 Pretest.Nested.Dependent > {(){=;;while( > ){<<; = ;while( <= ){<<; = + 1;} = - 1;}}} > Type: output Hardness: 80 // Down X Up X Update by many # 737 Pretest.Nested.Dependent > {(){=;;while( > ){<<; = ;while( <= ){<<; = + ;} = - ;}}} > Type: output Hardness: 80 # 738 Pretest.Nested.Dependent > {(){=;;while( > ){<<; = ;while( <= ){<<; = + ;} = - ;}}} > Type: output Hardness: 80 # 739 Pretest.Nested.Dependent > {(){=;;while( > ){<<; = ;while( <= ){<<; = + ;} = - ;}}} > Type: output Hardness: 90 // Down X Down X Update by 1 # 740 Pretest.Nested.Dependent > {(){=;;while( > ){<<; = ;while( >= ){<<; = - 1;} = - 1;}}} > Type: output Hardness: 80 # 741 Pretest.Nested.Dependent > {(){=;;while( > ){<<; = ;while( >= ){<<; = - 1;} = - 1;}}} > Type: output Hardness: 80 // Down X Down X Update by many # 742 Pretest.Nested.Dependent > {(){=;;while( > ){<<; = ;while( >= ){<<; = - ;} = - ;}}} > Type: output Hardness: 80 # 743 Pretest.Nested.Dependent > {(){=;;while( > ){<<; = ;while( >= ){<<; = - ;} = - ;}}} > Type: output Hardness: 80 # 744 Pretest.Nested.Dependent > {(){=;;while( > ){<<; = ;while( >= ){<<; = - ;} = - ;}}} > Type: output Hardness: 90 // REVIEW FROM HERE ONWARDS //3-levels # 745 Pretest.Nested.Dependent > {(){=;;;while( < ){<<; = ;while( < ){<<; = ;while( < ){<<; = + 1;} = + 1;} = + 1;}}} // {(){=;;;while( < ){ = ;while( < ){ = ;while( < ){<<;<<;<<; = + 1;} = + 1;} = + 1;}}} // Simplified for S08 > Type: output Hardness: 90 # 746 Pretest.Nested.Dependent > {(){=;;;while( > ){<<; = ;while( > ){<<; = ;while( > ){<<; = - 1;} = - 1;} = - 1;}}} // {(){=;;;while( > ){ = ;while( > ){ = ;while( > ){<<;<<;<<; = - 1;} = - 1;} = - 1;}}} // Simplified for S08 > Type: output Hardness: 90 // ------------------------------------------------------------------------ // Pretest.Nested.Independent ************************************ 750 // 2 loops nested // UpUp - Update by 1 vs many - 2 constants for bounds, same constant for bounds, 2 variables for bounds both same // UpDown - Update by 1 vs many // DownUp - Update by 1 vs many // DownDown - Update by 1 vs many // Up X Up X update by 1 # 750 Pretest.Nested.Independent > {(){=;;while( < ){<<; = ;while( <= ){<<; = + 1;} = + 1;}}} > Type: output Hardness: 80 # 751 Pretest.Nested.Independent > {(){=;;while( < ){<<; = ;while( <= ){<<; = + 1;} = + 1;}}} > Type: output Hardness: 80 # 752 Pretest.Nested.Independent > {(){=;;=;while( < ){<<; = ;while( < ){<<; = + 1;} = + 1;}}} > Type: output Hardness: 80 // Up X Up X Update by many # 753 Pretest.Nested.Independent > {(){=;;while( < ){<<; = ;while( <= ){<<; = + ;} = + ;}}} > Type: output Hardness: 80 # 754 Pretest.Nested.Independent > {(){=;;while( < ){<<; = ;while( <= ){<<; = + ;} = + ;}}} > Type: output Hardness: 80 # 755 Pretest.Nested.Independent > {(){=;;=;=;while( < ){<<; = ;while( <= ){<<; = + ;} = + ;}}} > Type: output Hardness: 80 // Up X Down X update by 1 # 756 Pretest.Nested.Independent > {(){=;;while( < ){<<; = ;while( >= ){<<; = - 1;} = + 1;}}} > Type: output Hardness: 80 # 757 Pretest.Nested.Independent > {(){=;;while( < ){<<; = ;while( >= ){<<; = - 1;} = + 1;}}} > Type: output Hardness: 80 # 758 Pretest.Nested.Independent > {(){;;=;=; = ;while( < ){<<; = ;while( >= ){<<; = - 1;} = + 1;}}} > Type: output Hardness: 80 // Up X Down X Update by many # 759 Pretest.Nested.Independent > {(){=;;while( < ){<<; = ;while( >= ){<<; = - ;} = + ;}}} > Type: output Hardness: 80 # 760 Pretest.Nested.Independent > {(){=;;while( < ){<<; = ;while( >= ){<<; = - ;} = + ;}}} > Type: output Hardness: 80 # 761 Pretest.Nested.Independent > {(){=;=;=;=;;while( < ){<<; = ;while( >= ){<<; = - ;} = + ;}}} > Type: output Hardness: 80 // Down X Up X Update by 1 # 762 Pretest.Nested.Independent > {(){=;;while( > ){<<; = ;while( <= ){<<; = + 1;} = - 1;}}} > Type: output Hardness: 80 # 763 Pretest.Nested.Independent > {(){=;;while( > ){<<; = ;while( <= ){<<; = + 1;} = - 1;}}} > Type: output Hardness: 80 # 764 Pretest.Nested.Independent > {(){;;=;=; = ;while( > ){<<; = ;while( <= ){<<; = + 1;} = - 1;}}} > Type: output Hardness: 80 // Down X Up X Update by many # 765 Pretest.Nested.Independent > {(){=;;while( > ){<<; = ;while( <= ){<<; = + ;} = - ;}}} > Type: output Hardness: 80 # 766 Pretest.Nested.Independent > {(){=;;while( > ){<<; = ;while( <= ){<<; = + ;} = - ;}}} > Type: output Hardness: 80 # 767 Pretest.Nested.Independent > {(){=;=;=;=;;while( > ){<<; = ;while( <= ){<<; = + ;} = - ;}}} > Type: output Hardness: 80 // Down X Down X Update by 1 # 768 Pretest.Nested.Independent > {(){=;;while( > ){<<; = ;while( >= ){<<; = - 1;} = - 1;}}} > Type: output Hardness: 80 # 769 Pretest.Nested.Independent > {(){=;;while( > ){<<; = ;while( >= ){<<; = - 1;} = - 1;}}} > Type: output Hardness: 80 # 770 Pretest.Nested.Independent > {(){;;=;=; = ;while( > ){<<; = ;while( >= ){<<; = - 1;} = - 1;}}} > Type: output Hardness: 80 // Down X Down X Update by many # 771 Pretest.Nested.Independent > {(){=;;while( > ){<<; = ;while( >= ){<<; = - ;} = - ;}}} > Type: output Hardness: 80 # 772 Pretest.Nested.Independent > {(){=;;while( > ){<<; = ;while( >= ){<<; = - ;} = - ;}}} > Type: output Hardness: 80 # 773 Pretest.Nested.Independent > {(){=;=;=;=;;while( > ){<<; = ;while( >= ){<<; = - ;} = - ;}}} > Type: output Hardness: 80 // Generates error 50% of the time with C++ // //3-levels // # 774 // Pretest.Nested.Independent // > // {(){=;;;while( < ){<<;=;while( < ){<<; = ;while( < ){<<; = + 1;} = + 1;} = + 1;}}} // // {(){=;;while( < ){=;while( < ){ = ;while( < ){<<;<<;<<; = + 1;} = + 1;} = + 1;}}} // Simplified for S08 // > // Type: output // Hardness: 90 //3-levels # 775 Pretest.Nested.Independent > {(){=;;;while( > ){<<;=;while( > ){<<; = ;while( > ){<<; = - 1;} = - 1;} = - 1;}}} // {(){=;;while( > ){=;while( > ){ = ;while( > ){<<;<<;<<; = - 1;} = - 1;} = - 1;}}} // Simplified for S08 > Type: output Hardness: 90 // ------------------------------------------------------------------------ // Pretest.Infinite ************************************ 800 // ------------------ Parsons Puzzles -------------------------------------------------------- // DESIGN PRINCIPLES: // Use accumulator variables // Learning objectives: // Pretest.Parsons.Single - 2000 // Pretest.Parsons.Multiple.Independent - 2025 // Pretest.Parsons.Multiple.Dependent - 2050 // Pretest.Parsons.Nested.Independent - 2075 // Pretest.Parsons.Nested.Dependent - 2100 // ------------------------------------------------------------------------ // Pretest.Parsons.Single - 2000 // DemoParsons // while sentinel not found (-1), read numbers, calculate their sum # 2000 Pretest.Parsons.Single > "It reads numbers till the sentinel -1 is found. It computes the sum of all the numbers read and prints it (e.g., it prints 10 after reading 1,3,2,4,-1)." {(){ /* Declare */ ; /* Declare */ = 0; /* Read and add it to till -1 is found */ << "Enter the first number (-1 to end)"; >> ; while( != -1 ) { = + ; << "Enter the next number (-1 to end)"; >> ; } /* Print */ << ; }} > Type: parsons Hardness: 20 // Read numbers till odd number, count the number of even numbers # 2001 Pretest.Parsons.Single > "It reads numbers till an odd number is read. It counts the number of even numbers read and prints it (e.g., it prints 4 after reading the numbers 2,6,8,6,5)." {(){ /* Declare */ ; /* Declare */ = 0; /* Read till odd number found. Count number of even numbers read */ << "Enter the first number"; >> ; while( % 2 == 0 ) { = + 1; << "Enter the next number"; >> ; } /* Print */ << ; }} > Type: parsons Hardness: 20 // while 0 not entered, read income and expenses, and report the balance thereafter # 2002 Pretest.Parsons.Single > "It reads numbers till the sum of the numbers is zero (e.g., it reads up to -2 in 3,3,-4,-2,-7,4,3)." {(){ /* Declare */ ; /* Declare */ ; /* Read and add it to till is 0 */ << "Enter the first number"; >> ; = ; while( != 0 ) { << "Enter the next number"; >> ; = + ; } }} > Type: parsons Hardness: 20 // pretest // while current number not same as previous number... # 2005 Pretest.Parsons.Single > "It reads numbers till the same number appears back to back. It prints the first number to appear twice back to back (e.g., 4 appears back to back in 3,7,5,7,4,4,5 and is printed)." {(){ /* Declare */ ; /* Declare */ ; /* Read numbers till same number appears back to back */ << "Enter the first number"; >> ; << "Enter the next number"; >> ; while( != ) { = ; << "Enter the next number"; >> ; } /* Print */ << ; }} > Type: parsons Hardness: 30 // posttest // while current number not the negative of previous number... # 2006 Pretest.Parsons.Single > "It reads numbers till a number and its negative appear back to back. It prints the number and its negative (e.g., 6 and -6 are a number and its negative appearing back to back in 4,3,-5,6,-6,9)." {(){ /* Declare */ ; /* Declare */ ; /* Read numbers till a number (in ) and its negative (in ) appear back to back */ << "Enter the first number"; >> ; << "Enter the next number"; >> ; while( != -1 * ) { = ; << "Enter the next number"; >> ; } /* Print followed by */ << ; << ; }} > Type: parsons Hardness: 30 // while current number not a multiple of previous number... # 2007 Pretest.Parsons.Single > "It reads numbers till a number and its multiple appear back to back. It prints the number and its multiple (e.g., 5 and 10 are a number and its multiple appearing back to back in 3,4,6,5,10,12 )." {(){ /* Declare */ ; /* Declare */ ; /* Read numbers till a number (in ) and its multiple (in ) appear back to back */ << "Enter the first number"; >> ; << "Enter the next number"; >> ; while( % != 0 ) { = ; << "Enter the next number"; >> ; } /* Print followed by */ << ; << ; }} > Type: parsons Hardness: 30 // while numbers monotonically increasing, read numbers, count number of numbers in monotonic range # 2008 Pretest.Parsons.Single > "It reads numbers while they are monotonically increasing. It prints the first number that breaks the monotonic sequence (e.g., 5 breaks the monotonically increasing sequence in 1,3,3,6,5,7)." {(){ /* Declare */ ; /* Declare */ ; /* Read numbers while they increase monotonically */ << "Enter the first number"; >> ; << "Enter the next number"; >> ; while( >= ) { = ; << "Enter the next number"; >> ; } /* Print that broke the monotonic sequence */ << ; }} > Type: parsons Hardness: 30 // Read two numbers - min and max, read all the numbers while they are within the range of min-max // 3, 7 - 4,6,5,9 - read up to and including 5 // Read a number, add all subsequent numbers till that number is encountered again // 5 1 2 3 4 5 : print 10 // ------------------------------------------------------------------------ // Pretest.Parsons.Multiple.Independent - 2025 // read two factors of a number in increasing order // compute largest and smallest factor of a number // Read numbers till -1 and sum them; read additional numbers till the sum is over the first sum // ------------------------------------------------------------------------ // Pretest.Parsons.Multiple.Dependent - 2050 // Design: Validate an input using a while loop, use it in condition of second while loop DemoParsons // number of contiguous 1s followed by number of contiguous 0s # 2050 Pretest.Parsons.Multiple.Dependent > "It reads a series of 1s and 0s. It counts the number of contiguous 1s followed by the number of contiguous 0s, and prints the counts. For example, for the sequence 1,1,1,0,0,0,0,1,1,0, it prints 3 1s and 4 0s." {(){ /* Declare */ ; /* Declare */ = 0; /* Declare */ = 0; /* Count the number of contiguous 1s followed by contiguous 0s */ >> ; while( == 1 ) { = + 1; >> ; } while( == 0 ) { = + 1; >> ; } /* Print the number of contiguous 1s and 0s */ << "Number of 1s: " << << " Number of 0s: " << ; }} > Type: parsons Hardness: 20 // number not in sequence, followed by ... # 2051 Pretest.Parsons.Multiple.Dependent > "It reads a series of sequential numbers. It detects and prints the first number that is out of sequence, followed by the first number that gets back into sequence. For example, in the sequence 2,3,4,6,3,7,8, 6 is the first number out of sequence (should have been 5) and 7 is the first number back in sequence." {(){ /* Declare */ ; /* Declare */ ; /* Find and print the first number out of sequence followed by the first number back in sequence */ >> ; = ; while( == ) { >> ; = + 1; } << ; while( != ) { >> ; = + 1; } << ; }} > Type: parsons Hardness: 20 // read reservations and cancellations separated by sentinel value # 2052 Pretest.Parsons.Multiple.Dependent > "It reads a series of numbers, each representing the number of people per reservation at a restaurant, followed by a series of numbers representing the number of people per cancellation. Both the series end with -1. After reading both the series, it prints the number of people who still have reservations after subtracting cancellations. For example, in the sequence of numbers 2,4,1,6,-1,1,2,-1, 13 people reserve, and 3 cancel, leaving the restaurant with 10 people." {(){ /* Declare */ ; /* Declare */ ; /* Declare */ = 0; /* Read and sum all the reservations, read and subtract all the cancellations */ << "Enter the number of people in the next reservation"; >> ; while( != -1 ) { = + ; << "Enter the number of people in the next reservation"; >> ; } << "Enter the number of people in the next cancellation"; >> ; while( != -1 ) { = - ; << "Enter the number of people in the next cancellation"; >> ; } /* Print the number of people who still have reservation */ << "Number of people who still have reservation is " << ; }} > Type: parsons Hardness: 30 // pretest // Reads two numbers, counts the number of numbers before they appear in a series of numbers # 2053 Pretest.Parsons.Multiple.Dependent > "It inputs the face of a card. It then reads a deck of cards and prints how many cards into the deck it finds the input card, followed by its successor. For example, if the input card is 6, in a deck that starts with the cards 1,8,6,10,7,9,13, it finds the 6 card in 3rd place and 7 card in 5th place." {(){ /* Declare */ ; /* Declare */ ; /* Declare */ = 1; /* Read into the face of the card to look for in the deck */ << "Enter the face of the card to look for in the deck (1-13)"; >> ; /* Find the card and its successor in a deck of cards */ << "Enter the cards in the deck one at a time"; >> ; while( != ) { >> ; = + 1; } << "Card " << << " found in deck at position " << ; = + 1; >> ; = + 1; while( != ) { >> ; = + 1; } << "Card " << << " found in deck at position " << ; }} > Type: parsons Hardness: 40 // posttest // Reads min and max temperatures. Counts number of days before max temp is observed, // followed by number of days maximum temperature is observed. # 2054 Pretest.Parsons.Multiple.Dependent > "It inputs maximum temperature of a season. It then reads a series of daily temperatures and prints the day on which maximum temperature is first observed. Thereafter, it counts and prints the number of contiguous days when maximum temperature is observed. For example, given maximum temperature is 72, in the sequence of daily temperatures 32,40,36,72,72,62,72,-1, maximum temperature is observed on day 4, and is observed for two contiguous days." {(){ /* Declare */ ; /* Declare */ ; /* Declare */ = 1; /* Declare */ = 1; /* Read into the maximum temperature of the season */ << "Enter the maximum temperature observed"; >> ; /* Find the first day with followed by number of days with */ << "Enter the daily temperatures one at a time"; >> ; while( != ) { >> ; = + 1; } >> ; while( == ) { = + 1; >> ; } << << " first observed on day " << << " and for " << << " days"; }} > Type: parsons Hardness: 40 // monotonically increasing followed by monotonically decreasing # 2055 Pretest.Parsons.Multiple.Dependent > "It reads a sequence of numbers and prints the length of monotonically increasing sequence (each number >= previous number) followed by the length of monotonically decreasing sequence (each number <= previous number). For example, in the sequence 1,3,5,5,4,4,2,3,5, the first monotonically increasing sequence is 4 numbers long (1,3,5,5) and the next monotonically decreasing sequence is 3 numbers long (4,4,2)." {(){ /* Declare */ ; /* Declare */ ; /* Declare */ = 1; /* Read and count monotonically increasing numbers followed by monotpnically decreasing numbers */ << "Enter the numbers one at a time"; >> ; >> ; while( >= ) { = + 1; = ; >> ; } << "Length of monotonically increasing numbers is " << ; = 0; while( <= ) { = + 1; = ; >> ; } << "Length of monotonically decreasing numbers is " << ; }} > Type: parsons Hardness: 40 // read a number, compute its largest two factors, // assuming the number has 2 factors, though. // Even prime has one factor when you start from num / 2. // But, not all numbers have 2 factors. // SO, this may not be a good problem. // Input an n and a limit and validate them; then compute all powers of n less than m and print them // read all numbers till a sentinel and add them; now, find smallest square larger than the sum... // number of numbers read till they added up to 100, followed by number of numbers read till sum reduced to 0? // read a number that is x, read a number smaller/larger than the first that is y // Duplicate of 2053, used to test single character variable names // Reads two numbers, counts the number of numbers before they appear in a series of numbers # 2074 Pretest.Parsons.Multiple.Dependent > "It inputs the face of a card. It then reads a deck of cards and prints how many cards into the deck it finds the input card, followed by its successor. For example, if the input card is 6, in a deck that starts with the cards 1,8,6,10,7,9,13, it finds the 6 card in 3rd place and 7 card in 5th place." {(){ /* Declare */ ; /* Declare */ ; /* Declare */ = 1; /* Read into the face of the card to look for in the deck */ << "Enter the face of the card to look for in the deck (1-13)"; >> ; /* Find the card and its successor in a deck of cards */ << "Enter the cards in the deck one at a time"; >> ; while( != ) { >> ; = + 1; } << "Card " << << " found in deck at position " << ; = + 1; >> ; = + 1; while( != ) { >> ; = + 1; } << "Card " << << " found in deck at position " << ; }} > Type: parsons Hardness: 40 // ------------------------------------------------------------------------ // Pretest.Parsons.Nested.Independent - 2075 // ------------------------------------------------------------------------ // Pretest.Parsons.Nested.Dependent - 2100 // Design: While a sentinel not met, read a number and validate it using while loop, use accumulator var.. // Read and compute up to first number // Read and read based on first number # 2100 Pretest.Parsons.Nested.Dependent > "It repeatedly reads a positive number, computes the smallest square greater than that number and prints it (.e., smallest square greater than 5 is 9). It stops when the user enters 0 or a negative number." {(){ /* Declare */ ; /* Declare */ ; /* Repeatedly read into , compute the square larger than it using and print it */ << "Enter the number whose nearest larger square is desired"; >> ; while( > 0 ) { = 1; while( * <= ) { = + 1; } << "Smallest square larger than " << << " is " << * ; << "Enter the number whose nearest larger square is desired"; >> ; } }} > Type: parsons Hardness: 30 # 2101 Pretest.Parsons.Nested.Dependent > "It repeatedly reads a positive number, computes its largest factor and prints it (e.g., largest factor of 21 is 7). It stops when the user enters a number less than 2." {(){ /* Declare */ ; /* Declare */ ; /* Repeatedly read into , compute its largest factor in and print it */ << "Enter the number whose largest factor is desired"; >> ; while( > 1 ) { = / 2; while( % != 0 ) { = - 1; } << "Largest factor of " << << " is " << ; << "Enter the number whose largest factor is desired"; >> ; } }} > Type: parsons Hardness: 30 # 2102 Pretest.Parsons.Nested.Dependent > "It repeatedly reads a positive number, and computes and prints all the powers of 2 less than the number (e.g., all the powers of 2 less than 15 are 1,2,4,8). It stops when the user enters 0 or a negative number." {(){ /* Declare */ ; /* Declare */ ; /* Repeatedly read into , compute and print all powers of 2 less than using */ << "Enter a positive number as the upper bound for powers of 2"; >> ; while( > 0 ) { = 1; while( <= ) { << ; = * 2; } << "Enter a positive number as the upper bound for powers of 2"; >> ; } }} > Type: parsons Hardness: 30 // pretest # 2105 Pretest.Parsons.Nested.Dependent > "It repeatedly reads a positive number, reads additional numbers till its multiple is found, and prints the number and its multiple. It repeats this until 0 or negative value is entered for the number. For example, while reading the sequence 3,2,4,6,2,5,4,0 it prints 3,6 and 2,4." {(){ /* Declare */ ; /* Declare */ ; /* Read into , then read into until is a multiple of , print both and repeat */ << "Enter the number whose multiple is desired"; >> ; while( > 0 ) { << "Enter the number to test for multiple"; >> ; while( % != 0 ) { << "Enter the number to test for multiple"; >> ; } << << " is a multiple of " << ; << "Enter the number whose multiple is desired"; >> ; } }} > Type: parsons Hardness: 30 // posttest # 2106 Pretest.Parsons.Nested.Dependent > "It reads an initial number, reads and adds together subsequent numbers till it reads the initial number again, and prints the sum. It repeats this until 0 or negative value is entered for the initial number. For example, in the sequence 3,4,6,2,3,5,7,5,0, it sums the numbers 4,6 and 2 between the two 3s and prints their sum, i.e., 12. Similarly, it prints 7 as the sum of numbers between the two 5s." {(){ /* Declare */ ; /* Declare */ ; /* Declare */ ; /* Read into , read and add numbers till is found again, print sum */ << "Enter the initial number"; >> ; while( > 0 ) { = 0; << "Enter the number to be added"; >> ; while( != ) { = + ; << "Enter the number to be added"; >> ; } << "Sum of numbers between " << << " is " << ; << "Enter the initial number"; >> ; } }} > Type: parsons Hardness: 40 # 2107 Pretest.Parsons.Nested.Dependent > "It reads a positive number, reads that many more numbers, computes their sum and prints it. It repeats this until 0 or negative number is read. For example, in the sequence 3,2,4,2,2,5,1,0, it first reads 3, then reads 3 more numbers: 2,4,2 and prints their sum 8." {(){ /* Declare */ ; /* Declare */ ; /* Declare */ ; /* Read into , read more numbers, compute their sum and print it */ << "Enter the number of numbers you want to sum"; >> ; while( > 0 ) { = 0; while( > 0 ) { << "Enter the next number you want to sum"; >> ; = + ; = - 1; } << ; << "Enter the number of numbers you want to sum"; >> ; } }} > Type: parsons Hardness: 40 // DemoParsons // run-length encoding: print each number and its back to back occurrences till -1 # 2108 Pretest.Parsons.Nested.Dependent > "It reads a sequence of numbers, and prints each number and how many times it appears back to back. It repeats this until 0 or negative number is read. For example, for the sequence 3,4,4,1,1,1,5,-1 it prints 3 - 1, 4 - 2, 1 - 3 and 5 - 1." {(){ /* Declare */ ; /* Declare */ ; /* Declare */ ; /* Read a sequence of numbers, print each number and how many times it appears back to back */ << "Enter the sequence of numbers"; >> ; while( > 0 ) { = 1; >> ; while( == ) { = + 1; >> ; } << << " - " << ; = ; } }} > Type: parsons Hardness: 50 // Read a number, read until sum is 0? // -------------------------------------------------------------------------- // May be for INTEGRATED_LOOP problems? // Read two non-negative numbers, the second greater than the first, // Print all the powers of 2 in between them. // Uses 2 do-while loops for validation // Uses a while loop to come up to the first power of 2 // power = 1; while( power < firstNumber ) power *= 2; // Uses do-while to print the powers that follow // do{ << power; power *= 2; } while( power < secondNumber ); // ---------------------------Solvelet problems----------------------------- // WARNING: LAST LINE AND ONLY LAST LINE OF INSTRUCTIONS MUST END WITH DOUBLE-QUOTES // From parser/template/code/ProblemSpec: // order*="2": // order - temporal order in which this should be attempted // * means this attribute is given, do not ask the user for it // after*="*"* // Spatial order for this variable in the actual code, e.g., after="minimum" // "*" means any spatial order is fine // From parser/template/code/problemspec/ProblemSpec: // Could have , and tags, although, it appears, I am only using tag so far.. // From parser/template/code/ProblemSpec: // Attributes for data specification include "form", "type", "direction", "control" // From tutor.wizard.ControlConstants: // Value of "control" attribute can be if, ifelse, switch, elsif, multiway, while, for, dowhile - all lowercase, no hyphens // These are post-processed by ControlWizard to be Selection or Loop // PROBLEM TO TEST DEVELOPMENT OF WHILE LOOP TUTOR // Read a number, print its square until the user says n # 4100 Pretest.Solve.Condition.Independent > "Write a program to read a number and compute and print its square while the user's reply is yes (y) to whether the user wants to calculate another square." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: number Name: Type: */^^;^ /* Statement: Declare Purpose: square Name: Type: */^^;^ /* Statement: Declare Purpose: reply Name: Type: */^^;^ /* Block: Section Purpose: another Function: Initialization */ /* Statement: Section Purpose: reply Format: Read the response */ /* Statement: Prompt Purpose: reply Format: Do you want to calculate a square (y/n) */^^<< "Do you want to calculate a square (y/n)?";^ /* Statement: Input Purpose: reply */^^>> ;^ /* Block: Section Purpose: another Function: Loop Control: while */ while( == 'y' ) { /** Input Section */ /* Statement: Section Purpose: number Format: Read the number */ /* Statement: Prompt Purpose: number Format: Enter number */^^<< "Enter number";^ /* Statement: Input Purpose: number */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: square BasedOn: product of and */^^ = * ;^ /** Output Section */ /* Statement: Output Purpose: square Format: Square is 16 */^^<< "Square is " << ;^ /* Block: Section Purpose: another Function: Update */ /* Statement: Section Purpose: reply Format: Read the response */ /* Statement: Prompt Purpose: reply Format: Do you want to calculate a square (y/n) */^^<< "Do you want to calculate a square (y/n)?";^ /* Statement: Input Purpose: reply */^^>> ;^ } }} > Type: code Hardness: 15 // Number of input variables * 5 + number of output variables * 5 + number of expression operators * 5 + number of intermediate variables * 10 // Read a number> 1, print all the powers of 2 less than that number # 4200 Pretest.Solve.Condition.Dependent > "Write a program to read the limit (at least 2) and compute and print the smallest power of 2 greater than limit." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: limit Name: Type: */^^;^ /* Statement: Declare Purpose: power Name: Type: */^^;^ /** Input Section */ /* Block: Section Purpose: limit Function: validate Control: dowhile */ do{ /* Statement: Section Purpose: limit Format: Read the limit */ /* Statement: Prompt Purpose: limit Format: Enter the limit */^^<< "Enter the limit";^ /* Statement: Input Purpose: limit */^^>> ;^ } while( !( > 1) ); /** Compute Section */ /* Block: Section Purpose: power Function: compute Control: while */ = 1; while( <= ) { = * 2; } // /* Statement: Compute Purpose: power BasedOn: product of power and 2 */^^ = * ;^ /** Output Section */ /* Statement: Output Purpose: power Format: The smallest power of 2 greater than 10 is 16 */^^<< "The smallest power of 2 greater than " << << " is " << ;^ }} > Type: code Hardness: 15 // Number of input variables * 5 + number of output variables * 5 + number of expression operators * 5 + number of intermediate variables * 10 // Also try printing ALL the powers of 2 up to limit // -------------------------------------------------------------------------- // Templates here are for demonstration purposes // Included at the end so that regular practice does not pick up these templates // How to enter 2 outputs # 90 Demonstration > {(){=;<<;=;<<;<< - ;}} > Type: output Hardness: 10 // How to enter multiple outputs from the same line # 91 Demonstration > {(){; = 1;while( <= 2){<<; = + 1;}}} > Type: output Hardness: 10 // How to enter multiple outputs from alternate lines # 92 Demonstration > {(){; = 1;; = 5;while( <= 2){<<; = + 1;<<;}}} > Type: output Hardness: 10 // --------------------------------------------------------------------------