// Copyright Amruth N. Kumar, amruth@computer.org // Syntax: // Comment for reader's benefit, not parsed // # Template Number - +100 for each new type of problem, +10 for each new subtype // Learning Objective(s) for this template - when this template should be used // ? // If student gets the answer right, what OTHER objectives should get credit // Usually, counterpoint to the point of the error, say allocation for missing // deallocation, Declaration for out of scope error, assignment for incorrect // referencing, etc. // Make sure there is no overlap between this and antecedents! // : // If student gets the answer wrong, what OTHER objectives should get discredit // Make sure there is no overlap between this and antecedents! // > // The template itself, no double quotes, preceded and succeeded by a single > // > // Type: debug / output / code // Hardness: The student's correct percentage up to which this template will be used // Note: Syntax for learning objectives (in antecedent, ifCorrect, ifWrong) // is dot.separated, with {,} to represent alternates. // e.g., a.{b,c} is a.b and a.c // This is NOT graph structured, i.e., a,{b,c}.d is not accounted for to mean // a.b.d or a.c.d // FUTURE IMPROVEMENTS: // ADD TEMPLATES FOR POSTSTATEMENT FOR BOTH IF AND IFELSE // ADD TEMPLATES FOR DECLARATION/OTHER AS CONDITION OF IF ELSE // POSTSTATEMENT MAKES MOST SENSE WHEN IF CLAUSE IS EXECUTED AND ELSE CLAUSE IS A SIMPLE STATEMENT // CURRENTLY, POSTSTATEMENT ADDED WHEN IF CONDITION FALSE AND ELSE CLAUSE IS A SIMPLE STATEMENT... // IMPLEMENT DANGLING ELSE // for problems with condition such as variable = value, could print value of variable before if // for contrast. // For condition being var declaration, could have debugging problem where var is accessed after the if. // FOR TEMPLATES 835 AND UP - THE EXPLANATION ABOUT EXITING AN IF DOES NOT READ SMOOTHLY - GOES BACK // AND FORTH BETWEEN LINES. // FOR NESTED IF/IF-ELSE TEMPLATES, MAY WANT TO NOT ASK USER TO PRINT INPUT VARS, BUT ONLY // THE CALCULATED VAR - TO REDUCE COGNITIVE LOAD. e.g., if user calcuates index based // on amount and count, ask to print only index, not also amount and count.. // // ------------------------------------------------------------------------------- // The actual learning objectives: // 100 // Selection.ifElse.Condition.Relational.true // Selection.ifElse.Condition.Relational.false // Selection.ifElse.Condition.Declaration.true // Selection.ifElse.Condition.Declaration.false // Selection.ifElse.Condition.Other.true // Selection.ifElse.Condition.Other.false // 250 // Selection.ifElse.ifClause.Simple // Selection.ifElse.ifClause.Compound // Selection.ifElse.elseClause.Simple // Selection.ifElse.elseClause.Compound // 350 // Selection.ifElse.PostStatement // 400 // Selection.ifElse.Nested.Cascading // Selection.ifElse.Nested.Classification // Selection.ifElse.Nested.Random // Selection.ifElse.Nested.DanglingElse // 500 // Selection.ifElse.Multiple // // 600 // Selection.if.Condition.Relational.true // Selection.if.Condition.Relational.false // Selection.if.Condition.Declaration.true // Selection.if.Condition.Declaration.false // Selection.if.Condition.Other.true // Selection.if.Condition.Other.false // 750 // Selection.if.ifClause.Simple // Selection.if.ifClause.Compound // 800 // Selection.if.PostStatement // 825 // Selection.if.Nested // 850 // Selection.if.Multiple // // --------------------------------------------------------------------------- // 100 // Selection.ifElse.Condition.Relational.true // All 6 relational operators, repeated twice // All 4 combinations of simple/compound if and else clauses # 100 Selection.ifElse.Condition.Relational.true ? Selection.ifElse.{ifClause.Simple,elseClause.Simple} > {(){=;if( > )<<;else <<;}} > Type: output Hardness: 20 # 101 Selection.ifElse.Condition.Relational.true ? Selection.ifElse.{ifClause.Compound,elseClause.Simple} > {(){=;if( != ){ = ; <<;} else <<;}} // {(){=;if( != ){<<;<<;} else <<;}} // Simplified for S08 > Type: output Hardness: 30 # 102 Selection.ifElse.Condition.Relational.true ? Selection.ifElse.{ifClause.Simple,elseClause.Compound} > {(){=;if( != )<<;else { = + 1; <<;}}} // {(){=;if( != )<<;else {<<;<<;}}} // Simplified for S08 > Type: output Hardness: 20 # 103 Selection.ifElse.Condition.Relational.true ? Selection.ifElse.{ifClause.Compound,elseClause.Compound} > {(){=;=;if( <= ){<<;<<;}else {<<; <<;}}} > Type: output Hardness: 40 # 104 Selection.ifElse.Condition.Relational.true ? Selection.ifElse.{ifClause.Simple,elseClause.Simple} > {(){=;if( < )<<; else <<;}} > Type: output Hardness: 20 # 105 Selection.ifElse.Condition.Relational.true ? Selection.ifElse.{ifClause.Compound,elseClause.Compound} > {(){=;=;if( >= ){<<;<<;}else {<<;<<;}}} > Type: output Hardness: 40 # 106 Selection.ifElse.Condition.Relational.true ? Selection.ifElse.{ifClause.Compound,elseClause.Simple} > {(){=;if( < ){ = - 1; <<;}else <<;}} // {(){=;if( < ){<<;<<;}else <<;}} // Simplified for S08 > Type: output Hardness: 30 # 107 Selection.ifElse.Condition.Relational.true ? Selection.ifElse.{ifClause.Simple,elseClause.Compound} > {(){=;=;if( >= )<<;else { = ; <<;}}} // {(){=;=;if( >= )<<;else {<<;<<;}}} // Simplified for S08 > Type: output Hardness: 30 # 108 Selection.ifElse.Condition.Relational.true ? Selection.ifElse.{ifClause.Simple,elseClause.Simple} > {(){=; = + ;if( == * 2)<<; else <<;}} > Type: output Hardness: 30 # 109 Selection.ifElse.Condition.Relational.true ? Selection.ifElse.{ifClause.Simple,elseClause.Compound} > {(){=;=;if( <= )<<; else { = + ; <<;}}} // {(){=;=;if( <= )<<; else {<<;<<;}}} // Simplified for S08 > Type: output Hardness: 30 # 110 Selection.ifElse.Condition.Relational.true ? Selection.ifElse.{ifClause.Compound,elseClause.Compound} > {(){=;if( > ){<<;<<;} else {<<;<<;}}} > Type: output Hardness: 30 # 111 Selection.ifElse.Condition.Relational.true ? Selection.ifElse.{ifClause.Compound,elseClause.Simple} > {(){=; = * 2;if( - == ){<<; = + 1;} else <<;}} // {(){=; = * 2;if( - == ){<<;<<;} else <<;}} // Simplified for S08 > Type: output Hardness: 40 // Selection.ifElse.Condition.Relational.false *********************** 125 // All 6 relational operators, repeated twice // With Vs Without PostStatement // All 4 combinations of simple/compound if and else clauses # 125 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Simple,elseClause.Simple} > {(){=;if( < )<<; else <<; }} > Type: output Hardness: 30 # 126 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Compound,elseClause.Simple} > {(){=;=;if( == ){ = + 1; <<;}else <<;}} // {(){=;=;if( == ){<<;<<;}else <<;}} // Simplified for S08 > Type: output Hardness: 30 # 127 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Simple,elseClause.Compound} > {(){=;if( > )<<;else{=;<<;}}} // {(){=;if( > )<<;else{=;<<;}<<;}} // Simplified for S08 > Type: output Hardness: 30 # 128 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Compound,elseClause.Compound} > {(){=;=;if( <= ){<<;<<;}else{<<;<<;}}} // {(){=;=;if( <= ){<<;<<;}else{<<;<<;}<<;}} // Simplified for S08 > Type: output Hardness: 40 # 129 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Simple,elseClause.Simple} > {(){=; = - ;if( != 0)<<;else <<;}} > Type: output Hardness: 30 # 130 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Compound,elseClause.Simple} > {(){=;=;if( >= ){ = ; <<;}else <<;}} // {(){=;=;if( >= ){<<;<<;}else <<;}} // Simplified for S08 > Type: output Hardness: 40 # 131 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Simple,elseClause.Compound} > {(){=;if( < )<<;else{=;<<;}}} // {(){=;if( < )<<;else{=;<<;}<<;}} // Simplified for S08 > Type: output Hardness: 30 # 132 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Compound,elseClause.Compound} > {(){=;=;if( == ){<<; = ; }else{<<; = ; }}} // {(){=;=;if( == ){<<;<<;}else{<<;<<;}<<;}} // Simplified for S08 > Type: output Hardness: 40 # 133 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Simple,elseClause.Simple} > {(){=;if( > )<<;else <<;}} > Type: output Hardness: 30 # 134 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Compound,elseClause.Simple} > {(){=;=;if( <= ){ = + 1; <<;}else <<;}} // {(){=;=;if( <= ){<<;<<;}else <<;}} // Simplified for S08 > Type: output Hardness: 40 # 135 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Simple,elseClause.Compound} > {(){=; = * 2;if( != + )<<;else{<<; = + 1;}}} // {(){=; = * 2;if( != + )<<;else{<<;<<;}<<;}} // Simplified for S08 > Type: output Hardness: 30 # 136 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Compound,elseClause.Compound} > {(){=;=;if( >= ){<<;<<;}else{<<;<<;}}} // {(){=;=;if( >= ){<<;<<;}else{<<;<<;}=;<<;}} // Simplified for S08 > Type: output Hardness: 40 # 137 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Compound,elseClause.Simple} > {(){=;if( < ){ = + 1; <<;}else <<;}} // {(){=;if( < ){<<;<<;}else <<;<<;}} // Simplified for S08 > Type: output Hardness: 30 # 138 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Simple,elseClause.Compound} > {(){=;=;if( == )<<;else{ = ; <<;}}} // {(){=;=;if( == )<<;else{<<;<<;}}} // Simplified for S08 > Type: output Hardness: 20 # 139 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Compound,elseClause.Compound} > {(){=;if( > ){ = + 1; <<;}else{=;<<;}}} // {(){=;if( > ){<<;<<;}else{=;<<;}}} // Simplified for S08 > Type: output Hardness: 30 # 140 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Simple,elseClause.Simple} > {(){=;=;=;if( <= )<<;else <<;}} // {(){=;=;=;if( <= )<<;else <<; <<;}} // Simplified for S08 > Type: output Hardness: 40 # 141 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Compound,elseClause.Compound} > {(){=; = + ;if( / 2 != ){<<;<<;}else{<<;<<;}}} > Type: output Hardness: 30 # 142 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Simple,elseClause.Simple} > {(){=;=;if( >= )<< + 1;else << ;}} // {(){=;=;if( >= )<<;else <<;<< + 1;}} // Simplified for S08 > Type: output Hardness: 40 # 143 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Compound,elseClause.Compound} > {(){=;=;if( < ){<<;<<;}else{<<;<<;}}} > Type: output Hardness: 30 # 144 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Simple,elseClause.Simple} > {(){=;if( == )<<; else <<; }} // {(){=;if( == )<<; else <<; <<;}} // Simplified for S08 > Type: output Hardness: 40 # 145 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Compound,elseClause.Simple} > {(){=;if( > ){ = + 1; <<;}else <<;}} // {(){=;if( > ){<<;<<;}else <<;<<;}} // Simplified for S08 > Type: output Hardness: 30 # 146 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Simple,elseClause.Compound} > {(){=;=;if( <= )<<;else{<<; = ;}}} // {(){=;=;if( <= )<<;else{<<;<<;}}} // Simplified for S08 > Type: output Hardness: 20 # 147 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Compound,elseClause.Simple} > {(){=; = * 2;if( + != ){ = ; <<;}else<<;}} // {(){=; = * 2;if( + != ){<<;<<;}else<<;<<;}} // Simplified for S08 > Type: output Hardness: 40 # 148 Selection.ifElse.Condition.Relational.false ? Selection.ifElse.{ifClause.Simple,elseClause.Compound} > {(){=;=;if( >= )<<;else{ <<; = + 1;}}} // {(){=;=;if( >= )<<;else{<<;<<;}}} // Simplified for S08 > Type: output Hardness: 20 // Selection.ifElse.Condition.Declaration.true // Selection.ifElse.Condition.Declaration.false // Selection.ifElse.Condition.Other.true // Selection.ifElse.Condition.Other.false // 250 // Selection.ifElse.ifClause.Simple // Selection.ifElse.ifClause.Compound // Selection.ifElse.elseClause.Simple // Selection.ifElse.elseClause.Compound // 350 // Selection.ifElse.PostStatement // Selection.ifElse.Nested.Cascading **************************************************** 400 // Cascading if Vs else // Alternate simple and compound statements # 400 // ph value Selection.ifElse.Nested.Cascading ? Selection.ifElse.{ifClause.Simple,elseClause.{Simple,Compound}} > {(){=;;if( < 7) = -1; else {if( == 7 ) = 0; else = 1;} <<;}} // {(){=;;if( < 7) = -1; else {if( == 7 ) = 0; else = 1;} <<; <<;}} // Simplified for S08 > Type: output Hardness: 70 # 401 // solid, liquid, gas temperatures of water Selection.ifElse.Nested.Cascading ? Selection.ifElse.{ifClause.Simple,elseClause.{Simple,Compound}} > {(){=;;if( <= 0) = 0; else {if( < 100 ) = 1; else = 2;} <<;}} // {(){=;;if( <= 0) = 0; else {if( < 100 ) = 1; else = 2;} <<; <<;}} // Simplified for S08 > Type: output Hardness: 70 # 402 // Month -> Season Selection.ifElse.Nested.Cascading ? Selection.ifElse.{ifClause.Compound,elseClause.Compound} > {(){=;;if( >= 10){ = 4;} else {if( >= 7 ){ = 3;} else {if( >= 4){ = 2;} else { = 1;}}} <<;}} // {(){=;;if( >= 10){ = 4;} else {if( >= 7 ){ = 3;} else {if( >= 4){ = 2;} else { = 1;}}} <<; <<;}} // Simplified for S08 > Type: output Hardness: 70 # 403 // Degrees and quadrants Selection.ifElse.Nested.Cascading ? Selection.ifElse.{ifClause.Compound,elseClause.Compound} > {(){=;;if( <= 90){ = 1;} else {if( <= 180 ){ = 2;} else {if( <= 270){ = 3;} else { = 4;}}} <<;}} // {(){=;;if( <= 90){ = 1;} else {if( <= 180 ){ = 2;} else {if( <= 270){ = 3;} else { = 4;}}} <<; <<;}} // Simplified for S08 > Type: output Hardness: 70 # 404 // Credits -> year Selection.ifElse.Nested.Cascading ? Selection.ifElse.{ifClause.Simple,elseClause.{Simple,Compound}} > {(){=;;if( <= 28) = 1; else{ if( <= 58 ) = 2; else{ if( <= 85 ) = 3; else = 4;}} <<; }} // {(){=;;if( <= 28) = 1; else{ if( <= 58 ) = 2; else{ if( <= 85 ) = 3; else = 4;}} <<; <<; }} // Simplified for S08 > Type: output Hardness: 70 # 405 // Grade -> GPA Selection.ifElse.Nested.Cascading ? Selection.ifElse.{ifClause.Simple,elseClause.{Simple,Compound}} > {(){=;;if( >= 90) = 4; else {if( >= 80 ) = 3; else{ if( >= 70 ) = 2; else {if( >= 55 ) = 1; else = 0;}}} <<; }} // {(){=;;if( >= 90) = 4; else {if( >= 80 ) = 3; else{ if( >= 70 ) = 2; else {if( >= 55 ) = 1; else = 0;}}} <<; <<; }} // Simplified for S08 > Type: output Hardness: 70 # 406 // leap year Selection.ifElse.Nested.Cascading ? Selection.ifElse.{ifClause.Compound,elseClause.Compound} > {(){=;;if( % 4 == 0){if( % 100 == 0 ){if( % 400 == 0){ = 1;}else { = 0;}} else { = 1;}} else{ = 0;} <<;}} // {(){=;;if( % 4 == 0){if( % 100 == 0 ){if( % 400 == 0){ = 1;}else { = 0;}} else { = 1;}} else{ = 0;}<<; <<;}} // Simplified for S08 > Type: output Hardness: 70 # 407 // slope based on deltax and deltay Selection.ifElse.Nested.Cascading ? Selection.ifElse.{ifClause.Simple,elseClause.{Simple,Compound}} > {(){=;=;;if( == 0) = 0; else {if( == ) = 1; else{ if( < ) = -2; else = 2;}} <<; }} // {(){=;=;;if( == 0) = 0; else {if( == ) = 1; else{ if( < ) = -2; else = 2;}}<<;<<;<<; }} // Simplified for S08 > Type: output Hardness: 70 # 408 // Tsunami scale Selection.ifElse.Nested.Cascading ? Selection.ifElse.{ifClause.Simple,elseClause.{Simple,Compound}} > {(){=;; if( <= 72) = 0; else {if( <= 112 ) = 1; else {if( <= 157 ) = 2; else {if( <= 206 ) = 3; else {if( <= 260 ) = 4; else {if( <= 318 ) = 5; else = 6;}}}}} <<;}} // {(){=;; if( <= 72) = 0; else {if( <= 112 ) = 1; else {if( <= 157 ) = 2; else {if( <= 206 ) = 3; else {if( <= 260 ) = 4; else {if( <= 318 ) = 5; else = 6;}}}}} <<; <<;}} // Simplified for S08 > Type: output Hardness: 70 # 409 // frequency vs decible scale Selection.ifElse.Nested.Cascading ? Selection.ifElse.{ifClause.Simple,elseClause.{Simple,Compound}} > {(){=;; if( <= 200) = 20; else {if( <= 2000 ) = 40; else {if( <= 20000 ) = 60; else {if( <= 200000 ) = 80; else = 100;}}} <<;}} // {(){=;; if( <= 200) = 20; else {if( <= 2000 ) = 40; else {if( <= 20000 ) = 60; else {if( <= 200000 ) = 80; else = 100;}}} <<;<<;}} // Simplified for S08 > Type: output Hardness: 70 # 410 // Frequencies and colors (in reverse order of VBGYOR) Selection.ifElse.Nested.Cascading ? Selection.ifElse.{ifClause.Simple,elseClause.{Simple,Compound}} > {(){=;; if( < 482) = 1; else {if( < 503 ) = 2; else {if( < 520 ) = 3; else {if( < 610 ) = 4; else {if( < 659 ) = 5; else = 6;}}}} <<;}} // {(){=;; if( < 482) = 1; else {if( < 503 ) = 2; else {if( < 520 ) = 3; else {if( < 610 ) = 4; else {if( < 659 ) = 5; else = 6;}}}}<<;<<;}} // Simplified for S08 > Type: output Hardness: 70 # 411 // Plant hardiness zone based on low temperature Selection.ifElse.Nested.Cascading ? Selection.ifElse.{ifClause.Simple,elseClause.{Simple,Compound}} > {(){=;; if( < -50) = 1; else {if( < -40 ) = 2; else {if( < -30 ) = 3; else {if( < -20 ) = 4; else {if( < -10 ) = 5; else {if( < 0 ) = 6; else {if( < 10) = 7; else {if( < 20) = 8; else{if( < 30) = 9; else {if( < 40 ) = 10; else = 11;}}}}}}}}} <<;}} // {(){=;; if( < -50) = 1; else {if( < -40 ) = 2; else {if( < -30 ) = 3; else {if( < -20 ) = 4; else {if( < -10 ) = 5; else {if( < 0 ) = 6; else {if( < 10) = 7; else {if( < 20) = 8; else{if( < 30) = 9; else {if( < 40 ) = 10; else = 11;}}}}}}}}} <<; <<;}} // Simplified for S08 > Type: output Hardness: 70 // temperature and type of candy: 235-240 soft 245-250 firm 250-265 hard ball 270-290 soft crack 300-310 hard crack 320-356 caramelized // Selection.ifElse.Nested.Classification *************************************************** 425 // 4-way // 8-way # 425 // movie admission fee: age, show Selection.ifElse.Nested.Classification ? Selection.ifElse.{ifClause.{Simple,Compound},elseClause.{Simple,Compound}} > {(){=;=;;if( <= 9){if( <= 2 ) = 4; else = 6;}else {if( <= 2 ) = 8; else = 10; } <<;}} // {(){=;=;;if( <= 9){if( <= 2 ) = 4; else = 6;}else {if( <= 2 ) = 8; else = 10; } <<; <<; <<;}} // Simplified for S08 > Type: output Hardness: 80 # 426 // quartile of a number 1-100 Selection.ifElse.Nested.Classification ? Selection.ifElse.{ifClause.{Simple,Compound},elseClause.{Simple,Compound}} > {(){=;;if( >= 50){if( < 75 ) = 3; else = 4;}else {if( < 25) = 1; else = 2; } <<;}} // {(){=;;if( >= 50){if( < 75 ) = 3; else = 4;}else {if( < 25) = 1; else = 2; } <<; <<;}} // Simplified for S08 > Type: output Hardness: 80 # 427 // two numbers, operations based on their positive/negative nature Selection.ifElse.Nested.Classification ? Selection.ifElse.{ifClause.Compound,elseClause.Compound} > {(){=;=;;if( >= 0){if( >= 0){ = + ;}else{ = ;}}else{if( >= 0){ = ;}else{ = 0;}} <<;}} // {(){=;=;;if( >= 0){if( >= 0){ = + ;}else{ = ;}}else{if( >= 0){ = ;}else{ = 0;}} <<;<<;<<;}} // Simplified for S08 > Type: output Hardness: 80 # 428 // cards in a hand Selection.ifElse.Nested.Classification ? Selection.ifElse.{ifClause.Compound,elseClause.Compound} > {(){=;=;;if( <= 10){if( <= 2){ = 15;}else{ = 25;}}else{if( == 1){ = 30;}else{ = 50;}} <<;}} // {(){=;=;;if( <= 10){if( <= 2){ = 15;}else{ = 25;}}else{if( == 1){ = 30;}else{ = 50;}} <<; <<; <<;}} // Simplified for S08 > Type: output Hardness: 80 # 429 // positive/negative, odd even Selection.ifElse.Nested.Classification ? Selection.ifElse.{ifClause.{Simple,Compound},elseClause.{Simple,Compound}} > {(){=;;if( >= 0){if( % 2 == 0 ) = 4; else = 3;}else {if( % 2 == 0 ) = 2; else = 1; } <<;}} // {(){=;;if( >= 0){if( % 2 == 0 ) = 4; else = 3;}else {if( % 2 == 0 ) = 2; else = 1; } <<; <<;}} // Simplified for S08 > Type: output Hardness: 80 # 430 // Rent based on no. of bedrooms and bathrooms Selection.ifElse.Nested.Classification ? Selection.ifElse.{ifClause.{Simple,Compound},elseClause.{Simple,Compound}} > {(){=;=;;if( == 2){if( == 1 ) = 1200; else = 1500;}else {if( == 3 ){if( == 1 ) = 1500; else = 1800;} else{if( <= 2 ) = 2100; else = 2500;}} <<; }} // {(){=;=;;if( == 2){if( == 1 ) = 1200; else = 1500;}else {if( == 3 ){if( == 1 ) = 1500; else = 1800;} else{if( <= 2 ) = 2100; else = 2500;}}<<;<<;<<; }} // Simplified for S08 > Type: output Hardness: 80 # 431 // ice-cream: scoops, toppings Selection.ifElse.Nested.Classification ? Selection.ifElse.{ifClause.{Simple,Compound},elseClause.{Simple,Compound}} > {(){=;=;;if( == 1){if( == 0 ) = 100; else = 150;}else {if( == 2 ){if( == 0 ) = 180; else = 220;} else{if( == 0 ) = 250; else = 300;}} <<; }} // {(){=;=;;if( == 1){if( == 0 ) = 100; else = 150;}else {if( == 2 ){if( == 0 ) = 180; else = 220;} else{if( == 0 ) = 250; else = 300;}}<<;<<;<<; }} // Simplified for S08 > Type: output Hardness: 80 # 432 // speeding tickets: speed, age Selection.ifElse.Nested.Classification ? Selection.ifElse.{ifClause.{Simple,Compound},elseClause.{Simple,Compound}} > {(){=;=;;if( <= 10){if( <= 21 ) = 80; else{ if( <= 25 ) = 60; else = 50;}} else {if( <= 30 ){if( <= 21 ) = 120; else{ if( <= 25 ) = 100; else = 80;}} else {if( <= 21 ) = 200; else{ if( <= 25 ) = 150; else = 120;}}} <<; }} // {(){=;=;;if( <= 10){if( <= 21 ) = 80; else{ if( <= 25 ) = 60; else = 50;}} else {if( <= 30 ){if( <= 21 ) = 120; else{ if( <= 25 ) = 100; else = 80;}} else {if( <= 21 ) = 200; else{ if( <= 25 ) = 150; else = 120;}}}<<;<<;<<; }} // Simplified for S08 > Type: output Hardness: 80 # 433 // Income tax rate Selection.ifElse.Nested.Classification ? Selection.ifElse.{ifClause.{Simple,Compound},elseClause.{Simple,Compound}} > {(){=;=;;if( == 0){if( <= 30 ) = 15; else{ if( <= 80 ) = 30; else = 40;}} else {if( <= 40 ) = 10; else {if( <= 100 ) = 25; else = 35;}} <<;}} // {(){=;=;;if( == 0){if( <= 30 ) = 15; else{ if( <= 80 ) = 30; else = 40;}} else {if( <= 40 ) = 10; else {if( <= 100 ) = 25; else = 35;}} <<; <<; <<;}} // Simplified for S08 > Type: output Hardness: 80 # 434 // sorting 3 numbers Selection.ifElse.Nested.Classification ? Selection.ifElse.{ifClause.Compound,elseClause.Compound} > {(){=;=;=; if( > ){if( > ) {<<; <<; <<;} else {if( > ) {<<; <<; <<;} else {<<;<<;<<;} }} else {if( > ) { if( > ) {<<; <<; <<;} else {<<; <<; <<;} } else {<<; <<; <<;}}}} > Type: output Hardness: 80 // Heading N/E/W/S and turn L/R/Around - new heading // Selection.ifElse.Nested.Random *********************************** 450 // // Selection.ifElse.Nested.DanglingElse ***************************** 475 // Selection.ifElse.Multiple ***************************************** 500 // 2 Vs 3 statements // 2 levels - TT, TF, FT, FF // 3 levels - TTT, TTF, TFT, TFF, FTT, FTF, FFT FFF // (Same variable Vs different variables, all 6 relational operators) - NO postStatement, Compound Vs Simple mixed # 500 // 2 levels - TT, positive and negative numbers Selection.ifElse.Multiple ? Selection.ifElse.{Condition.Relational.true,ifClause.{Simple,Compound},elseClause.{Simple,Compound}} > {(){=;=;if( > ) <<; else {<<;}; if( - >= 0){ = - ;} else = - ; << ;}} > Type: output Hardness: 60 # 501 // 2 levels - TF, Selection.ifElse.Multiple ? Selection.ifElse.{Condition.Relational.{true,false},ifClause.{Simple,Compound},elseClause.{Simple,Compound}} > {(){=; = ;if( > ){<<; <<;} else {<<;<<;} = - ; = + ; if( > ) <<; else <<; }} > Type: output Hardness: 60 # 502 // 2 levels - FT, Selection.ifElse.Multiple ? Selection.ifElse.{Condition.Relational.{true,false},ifClause.{Simple,Compound},elseClause.{Simple,Compound}} > {(){=; if( >= ) {<<;} else <<; = * ; if( <= ) <<; else {<<;}}} > Type: output Hardness: 60 # 503 // 2 levels - FF, -ve numbers Selection.ifElse.Multiple ? Selection.ifElse.{Condition.Relational.false,ifClause.{Simple,Compound},elseClause.{Simple,Compound}} > {(){=; = * -1; if( == )<<;else <<; = * ; = * ; if( != ){ <<;} else {<<;} }} // {(){=; = * -1; if( == )<<;else <<; = * ; = * ; if( != ){ <<;} else {<<; <<;} }} // Simplified for S08 > Type: output Hardness: 60 // TTT - a < b, b < c, c < d // a,b,c < x // TTF - a < x, y, z // with vs without accumulator variable // print smaller // a == b == c or a != b != c # 505 // 3 levels - TTT Selection.ifElse.Multiple ? Selection.ifElse.{Condition.Relational.true,ifClause.{Simple,Compound},elseClause.{Simple,Compound}} > {(){=;=;=;if( < )<< ; else << ; if( <= ) << ; else << ; if( < ) {<<;} else {<<;}}} > Type: output Hardness: 60 # 506 // 3 levels - TTF Selection.ifElse.Multiple ? Selection.ifElse.{Condition.Relational.{true,false},ifClause.{Simple,Compound},elseClause.{Simple,Compound}} > {(){=;if( > )<< ; else {<< - ;} if( >= ) << ; else {<< - ;} if( >= ){ << - ;} else <<; }} > Type: output Hardness: 60 # 507 // 3 levels - TFT - <, >, != Selection.ifElse.Multiple ? Selection.ifElse.{Condition.Relational.{true,false},ifClause.{Simple,Compound},elseClause.{Simple,Compound}} > {(){=; = * -1; if( < ) <<; else <<; if( + != 0){ << + ;} else { <<;} if( * == * ) {<< * ;} else { << + ;}}} // {(){=; = * -1; if( < ) <<; else <<; if( + != 0){ << + ;} else { <<; <<;} if( * == * ) {<< * ;} else { << * ; << * ;}}} // Simplified for S08 > Type: output Hardness: 60 # 508 // 3 levels - TFF - Selection.ifElse.Multiple ? Selection.ifElse.{Condition.Relational.{true,false},ifClause.{Simple,Compound},elseClause.{Simple,Compound}} > {(){=;=; if( != ){<<;}else <<; = ; if( == ) << ; else <<; if( == ) {<<;} else {<<;}}} > Type: output Hardness: 60 # 509 // 3 levels - FFF Selection.ifElse.Multiple ? Selection.ifElse.{Condition.Relational.false,ifClause.{Simple,Compound},elseClause.Compound,PostStatement} > {(){=; = 0; if( >= ) = - 1; else { = + 1;} if( >= ) { = - 1; } else { = + 1;} if( >= ) = - 1; else { = + 1;} <<;}} // {(){=; = 0; if( >= ) << ; else {<<; = + 1;} if( >= ) { <<; } else {<<; = + 1;} if( >= )<<; else {<<; = + 1;} <<;}} // Simplified for S08 > Type: output Hardness: 70 # 510 // 3 levels - FTT - Selection.ifElse.Multiple ? Selection.ifElse.{Condition.Relational.{true,false},ifClause.Compound,elseClause.{Simple,Compound},PostStatement} > {(){=;=; = 0;if( >= ){ = + 2;} else = - 1; =; if( >= ){ = + 2;} else = - 1; if( >= ) { = + 2;} else { = - 1;} <<;}} // {(){=;=; = 0;if( >= ){<< ; = + 1;} else << ; =; if( >= ){ << ; = + 1;} else << ; if( >= ) {<<; = + 1;} else {<<;} <<;}} // Simplified for S08 > Type: output Hardness: 70 # 511 // 3 levels - NOT FFT, but Sieve of Eratosthenes Selection.ifElse.Multiple ? Selection.ifElse.{Condition.Relational.{true,false},ifClause.Simple,elseClause.Simple} > {(){=;=; if( > ) = - ; else = - ; <<; <<; if( > ) = - ; else = - ; <<; <<; if( > ) = - ; else = - ; <<; <<; }} > Type: output Hardness: 80 # 512 // 3 levels - NOT FTF, but divide/subtract based on even/odd Selection.ifElse.Multiple ? Selection.ifElse.{Condition.Relational.{true,false},ifClause.Simple,elseClause.Simple} > {(){=; if( % 2 == 0){ = / 2;} else = - 1; <<; if( % 2 == 0){ = / 2;} else = - 1; <<; if( % 2 == 0){ = / 2;} else = - 1; <<;}} > Type: output Hardness: 80 // 600 // Selection.if.Condition.Relational.true **************************** 600 // All six relational operators // Simple Vs Compound if-clause // PostStatement not very effective when condition is true - equivalent to sequential execution # 600 Selection.if.Condition.Relational.true ? Selection.if.ifClause.Simple > {(){=;if( > )<<;}} > Type: output Hardness: 10 # 601 Selection.if.Condition.Relational.true ? Selection.if.ifClause.Simple > {(){=;if( != )<<;}} > Type: output Hardness: 10 # 602 Selection.if.Condition.Relational.true ? Selection.if.ifClause.Simple > {(){=;if( < )<<;}} > Type: output Hardness: 10 # 603 Selection.if.Condition.Relational.true ? Selection.if.ifClause.Simple > {(){=;=;if( >= )<<;}} > Type: output Hardness: 20 # 604 Selection.if.Condition.Relational.true ? Selection.if.ifClause.Simple > {(){=; = + ;if( == * 2)<<;}} > Type: output Hardness: 20 # 605 Selection.if.Condition.Relational.true ? Selection.if.ifClause.Simple > {(){=;=;if( <= )<<;}} > Type: output Hardness: 20 # 610 Selection.if.Condition.Relational.true ? Selection.if.ifClause.Compound > {(){=;if( > ){<<; = ;}}} // {(){=;if( > ){<<;<<;}}} // Simplified for S08 > Type: output Hardness: 20 # 611 Selection.if.Condition.Relational.true ? Selection.if.ifClause.Compound > {(){=;if( != ){<<; = + 1;}}} // {(){=;if( != ){<<;<<;}}} // Simplified for S08 > Type: output Hardness: 20 # 612 Selection.if.Condition.Relational.true ? Selection.if.ifClause.Compound > {(){=;if( < ){<<; = - 1;}}} // {(){=;if( < ){<<;<<;}}} // Simplified for S08 > Type: output Hardness: 20 # 613 Selection.if.Condition.Relational.true ? Selection.if.ifClause.Compound > {(){=;=;if( >= ){<< - ; = ;}}} // {(){=;=;if( >= ){<<;<<;}}} // Simplified for S08 > Type: output Hardness: 30 # 614 Selection.if.Condition.Relational.true ? Selection.if.ifClause.Compound > {(){=; = * 2;if( - == ){<<; = + 1;}}} // {(){=; = * 2;if( - == ){<<;<<;}}} // Simplified for S08 > Type: output Hardness: 30 # 615 Selection.if.Condition.Relational.true ? Selection.if.ifClause.Compound > {(){=;=;if( <= ){<< - ; = ;}}} // {(){=;=;if( <= ){<<;<<;}}} // Simplified for S08 > Type: output Hardness: 30 // Selection.if.Condition.Relational.false ************************************** 625 // All six relational operators // Simple Vs Compound if-clause // With Vs without PostStatement # 625 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Simple > {(){=;if( < )<<;}} > Type: output Hardness: 10 # 626 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Simple > {(){=;if( == )<<;}} // {(){=;if( == )<<;<<;}} // Simplified for S08 > Type: output Hardness: 20 # 627 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Simple > {(){=;if( > )<<;}} > Type: output Hardness: 10 # 628 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Simple > {(){=;=;if( <= )<<;}} // {(){=;=;if( <= )<<;<<;}} // Simplified for S08 > Type: output Hardness: 20 # 629 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Simple > {(){=; = + ;if( != * 2)<<;}} > Type: output Hardness: 20 # 630 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Simple > {(){=;=;if( >= )<<;}} // {(){=;=;if( >= )<<;<<;}} // Simplified for S08 > Type: output Hardness: 20 # 631 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Compound > {(){=;if( < ){ = - 1; <<;}}} // {(){=;if( < ){<<;<<;}<<;}} // Simplified for S08 > Type: output Hardness: 30 # 632 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Compound > {(){=;if( == ){<<; <<;}}} // {(){=;if( == ){<<;<<;}}} // Simplified for S08 > Type: output Hardness: 20 # 633 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Compound > {(){=;if( > ){<<; = ;}}} // {(){=;if( > ){<<;<<;}<<;}} // Simplified for S08 > Type: output Hardness: 30 # 634 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Compound > {(){=;=;if( <= ){ = ; <<;}}} // {(){=;=;if( <= ){<<;<<;}}} // Simplified for S08 > Type: output Hardness: 20 # 635 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Compound > {(){=; = * 2;if( - != ){ = ; <<;}}} // {(){=; = * 2;if( - != ){<<;<<;}<<;}} // Simplified for S08 > Type: output Hardness: 30 # 636 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Compound > {(){=;=;if( >= ){<<; = ;}}} // {(){=;=;if( >= ){<<;<<;}}} // Simplified for S08 > Type: output Hardness: 20 # 637 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Simple > {(){=;if( < )<<;}} // {(){=;if( < )<<;<<;}} // Simplified for S08 > Type: output Hardness: 20 # 638 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Simple > {(){=;if( == )<<;}} > Type: output Hardness: 10 # 639 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Simple > {(){=;if( > )<<;}} // {(){=;if( > )<<;<<;}} // Simplified for S08 > Type: output Hardness: 20 # 640 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Simple > {(){=;=;if( <= )<<;}} > Type: output Hardness: 10 # 641 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Simple > {(){=; = + ;if( != * 2)<<;}} // {(){=; = + ;if( != * 2)<<;<<;}} // Simplified for S08 > Type: output Hardness: 20 # 642 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Simple > {(){=;=;if( >= )<<;}} > Type: output Hardness: 10 # 643 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Compound > {(){=;if( < ){<<; = ;}}} // {(){=;if( < ){<<;<<;}}} // Simplified for S08 > Type: output Hardness: 20 # 644 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Compound > {(){=;if( == ){<<; = + ;}}} // {(){=;if( == ){<<;<<;}<<;}} // Simplified for S08 > Type: output Hardness: 30 # 645 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Compound > {(){=;if( > ){<<; = - ;}}} // {(){=;if( > ){<<;<<;}}} // Simplified for S08 > Type: output Hardness: 20 # 646 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Compound > {(){=;=;if( <= ){ = ; <<;}}} // {(){=;=;if( <= ){<<;<<;}<<;<<;}} // Simplified for S08 > Type: output Hardness: 30 # 647 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Compound > {(){=; = * 2;if( - != ){<<; = ;}}} // {(){=; = * 2;if( - != ){<<;<<;}}} // Simplified for S08 > Type: output Hardness: 20 # 648 Selection.if.Condition.Relational.false ? Selection.if.ifClause.Compound > {(){=;=;if( >= ){ = + ; <<;}}} // {(){=;=;if( >= ){<<;<<;}<<;<<;}} // Simplified for S08 > Type: output Hardness: 30 // Selection.if.Condition.Declaration.true ******************************* 650 // Boolean Vs Integer condition variable // Simple Vs Compound if-clause // With Vs without PostStatement # 650 Selection.if.Condition.Declaration.true ? Selection.if.ifClause.Simple > {(){if( = true)<< ;}} > Type: output Hardness: 40 # 651 Selection.if.Condition.Declaration.true ? Selection.if.ifClause.Simple > {(){ = ;if( = true)<<;}} // {(){ = ;if( = true)<<;<<;}} // Simplified for S08 > Type: output Hardness: 40 # 652 Selection.if.Condition.Declaration.true ? Selection.if.ifClause.Compound > {(){if( = ){<<; = * 2;}}} // {(){if( = ){<<;<< + 1;}}} // Simplified for S08 > Type: output Hardness: 40 # 653 Selection.if.Condition.Declaration.true ? Selection.if.ifClause.Compound > {(){ = ;if( = ){ = ; <<;}}} // {(){ = ;if( = ){<<;<<;}<<;}} // Simplified for S08 > Type: output Hardness: 40 # 654 Selection.if.Condition.Declaration.true ? Selection.if.ifClause.Simple > {(){if(=)<<;}} > Type: output Hardness: 40 # 655 Selection.if.Condition.Declaration.true ? Selection.if.ifClause.Simple > {(){=;if(=)<<;}} // {(){=;if(=)<<;<<;}} // Simplified for S08 > Type: output Hardness: 40 # 656 Selection.if.Condition.Declaration.true ? Selection.if.ifClause.Compound > {(){if( = true){<<;}}} > Type: output Hardness: 40 # 657 Selection.if.Condition.Declaration.true ? Selection.if.ifClause.Compound > {(){=;if( = true){<<; = * 2;}}} // {(){=;if( = true){<<;<<;}<<;}} // Simplified for S08 > Type: output Hardness: 40 // Selection.if.Condition.Declaration.false ****************************** 675 // Boolean Vs Integer condition variable // Simple Vs Compound if-clause // With Vs without PostStatement # 675 Selection.if.Condition.Declaration.false ? Selection.if.ifClause.Simple > {(){if( = false)<<;}} > Type: output Hardness: 40 # 676 Selection.if.Condition.Declaration.false ? Selection.if.ifClause.Simple > {(){=;if( = false)<<;}} // {(){=;if( = false)<<;<<;}} // Simplified for S08 > Type: output Hardness: 40 # 677 Selection.if.Condition.Declaration.false ? Selection.if.ifClause.Compound > {(){if( = 0){<<; = + 1;}}} // {(){if( = 0){<<;<< + 1;}}} // Simplified for S08 > Type: output Hardness: 40 # 678 Selection.if.Condition.Declaration.false ? Selection.if.ifClause.Compound > {(){=;if( = 0){ = ; <<;}}} // {(){=;if( = 0){<<;<<;}<<;}} // Simplified for S08 > Type: output Hardness: 40 # 679 Selection.if.Condition.Declaration.false ? Selection.if.ifClause.Simple > {(){if( = 0)<<;}} > Type: output Hardness: 40 # 680 Selection.if.Condition.Declaration.false ? Selection.if.ifClause.Simple > {(){=;if( = 0)<<;}} // {(){=;if( = 0)<<;<<;}} // Simplified for S08 > Type: output Hardness: 40 # 681 Selection.if.Condition.Declaration.false ? Selection.if.ifClause.Compound > {(){if( = false){<<;}}} > Type: output Hardness: 40 # 682 Selection.if.Condition.Declaration.false ? Selection.if.ifClause.Compound > {(){=;if( = false){<<; = ;}}} // {(){=;if( = false){<<;<<;}<<;}} // Simplified for S08 > Type: output Hardness: 40 // Selection.if.Condition.Other.true ************************************* 700 // Condition is: // Literal Constant - integer, boolean // Symbolic Constant? // Assignment to a pre-declared variable // Arithmetic expression - with or without variables, mostly +,- // -ve numbers as true # 700 Selection.if.Condition.Other.true ? Selection.if.ifClause.Simple > {(){=;if()<<;}} > Type: output Hardness: 40 # 701 Selection.if.Condition.Other.true ? Selection.if.ifClause.Simple > {(){=;if( = )<<;}} > Type: output Languages: C++ C Hardness: 40 # 702 Selection.if.Condition.Other.true ? Selection.if.ifClause.Compound > {(){=;=;if( + ){ = ; <<;}}} // {(){=;=;if( + ){<<; <<;}}} // Simplified for S08 > Type: output Hardness: 40 # 703 Selection.if.Condition.Other.true ? Selection.if.ifClause.Compound > {(){=;if( * -1){ = * -1; <<;}}} // {(){=;if( * -1){<<; << * -1;}}} // Simplified for S08 > Type: output Hardness: 40 # 704 Selection.if.Condition.Other.true ? Selection.if.ifClause.Simple > {(){=;if(true)<<;}} > Type: output Languages: C++ C Hardness: 40 # 705 Selection.if.Condition.Other.true ? Selection.if.ifClause.Compound > {(){=;=;if( = ){<<; = ;}}} // {(){=;=;if( = ){<<; <<;}}} // Simplified for S08 > Type: output Languages: C++ C Hardness: 40 # 706 Selection.if.Condition.Other.true ? Selection.if.ifClause.Compound > {(){=;=;if( - ){ = + 1; <<;}}} // {(){=;=;if( - ){<<; <<;}}} // Simplified for S08 > Type: output Hardness: 40 # 707 Selection.if.Condition.Other.true ? Selection.if.ifClause.Simple > {(){=;if()<<;}} > Type: output Hardness: 40 # 708 Selection.if.Condition.Other.true ? Selection.if.ifClause.Compound > {(){=;=;if( - ){ = - 1; <<;}}} // {(){=;=;if( - ){<<; <<;}}} // Simplified for S08 > Type: output Hardness: 40 // Selection.if.Condition.Other.false ************************************ 725 // Literal Constant - integer, boolean // Symbolic Constant? // Assignment to a pre-declared variable // Arithmetic expression - with or without variables, mostly +,- # 725 Selection.if.Condition.Other.false ? Selection.if.ifClause.Simple > {(){=0;if()<<;}} > Type: output Hardness: 40 # 726 Selection.if.Condition.Other.false ? Selection.if.ifClause.Simple > {(){=;if( = 0)<<;}} > Type: output Languages: C++ C Hardness: 40 # 727 Selection.if.Condition.Other.false ? Selection.if.ifClause.Compound > {(){=;=;if( - ){ = + 1; <<;}}} // {(){=;=;if( - ){<<; <<;}}} // Simplified for S08 > Type: output Hardness: 40 # 728 Selection.if.Condition.Other.false ? Selection.if.ifClause.Simple > {(){=;if(false)<<;}} > Type: output Languages: C++ C Hardness: 40 # 729 Selection.if.Condition.Other.false ? Selection.if.ifClause.Compound > {(){=;=0;if( = ){ = + 1; <<;}}} // {(){=;=0;if( = ){<<; <<;}}} // Simplified for S08 > Type: output Languages: C++ C Hardness: 40 # 730 Selection.if.Condition.Other.false ? Selection.if.ifClause.Simple > {(){=;if( * 0)<<; }} > Type: output Hardness: 40 # 731 Selection.if.Condition.Other.false ? Selection.if.ifClause.Compound > {(){=;=;if( / ){ = - 1; <<;}}} // {(){=;=;if( / ){<<; <<;}}} // Simplified for S08 > Type: output Hardness: 40 # 732 Selection.if.Condition.Other.false ? Selection.if.ifClause.Compound > {(){=;=;if( + ){<< ; <<;}}} > Type: output Hardness: 40 // 750 // Selection.if.ifClause.Simple // Selection.if.ifClause.Compound // 800 // Selection.if.PostStatement // Selection.if.Nested *************************************** 825 // 2 Vs 3 levels // 2 levels - True-True Vs True-False Vs False-True // 3 levels - TTT, TTF, TFT, FTT // Compound Vs Simple // (Same variable Vs different variables, all 6 relational operators) - NO postStatement // Compound Statement - all are set as compound statements because of problem with indenting code (as described before) # 825 // 2 levels - TT, two var, - number and its square Selection.if.Nested ? Selection.if.{Condition.Relational.true,ifClause.Compound} > {(){=;if( <= ){ = * ; if( >= ){ = + 1; <<;}}}} // {(){=;if( <= ){ = * ; if( >= ){ <<; <<;}}}} // Simplified for S08 > Type: output Hardness: 50 # 826 // 2 levels - TF - one var, Selection.if.Nested ? Selection.if.{Condition.Relational.{true,false},ifClause.Compound} > {(){=;if( >= ){ if( - == 0){ <<;}}}} > Type: output Hardness: 50 # 827 // 2 levels - FT, two vars, sum/difference Selection.if.Nested ? Selection.if.{Condition.Relational.{true,false},ifClause.Compound} > {(){=;=;if( - > 0){ if( + > 0){ <<;}}}} > Type: output Hardness: 50 # 830 // 3 levels - TTT, three vars, var in range Selection.if.Nested ? Selection.if.{Condition.Relational.{true,false},ifClause.Compound} > {(){=;if( <= ){ = + ; if( <= ){ = + ; if( <= ) { = ; <<; }}}}} // {(){=;if( <= ){ = + ; if( <= ){ = + ; if( <= ) { <<; <<; <<;}}}}} // Simplified for S08 > Type: output Hardness: 50 # 831 // 3 levels - TTF, three vars, monotonicity Selection.if.Nested ? Selection.if.{Condition.Relational.{true,false},ifClause.Compound} > {(){=;=; =; = 0; if( >= ){ = + 1; if( >= ){ = + 1; if( >= ){ = + 1;}}} <<;}} // {(){=;=; if( >= ){<<; =; if( >= ){<<; if( >= ){ <<;}}}}} // Simplified for S08 > Type: output Hardness: 50 # 832 // 3 levels - TFT, sum, difference Selection.if.Nested ? Selection.if.{Condition.Relational.{true,false},ifClause.Compound} > {(){=;=;if( != ){ <<; if( - >= 0){<< - ; if( + >= ){ << + ;}}}}} // {(){=;=;if( != ){ <<; <<; if( - >= 0){<< - ; if( + >= ){ << + ;}}}}} // Simplified for S08 > Type: output Hardness: 50 # 833 // 3 levels - FTT Selection.if.Nested ? Selection.if.{Condition.Relational.{true,false},ifClause.Compound} > {(){=;=; = 111;if( == ){ = - 100; if( * >= 0){ = - 10; if( * >= ){ = - 1; }}} <<; }} // {(){=;=;if( == ){ <<; <<; if( * >= 0){ << * ; if( * >= ){ << * ;}}}}} // Simplified for S08 > Type: output Hardness: 50 // Simple Statement - harder than compound statement, hence, later in the template list. # 835 // 2 levels - TT, one var, 2 comparators Selection.if.Nested ? Selection.if.{Condition.Relational.true,ifClause.Simple} > {(){=;if( < ) if( <= ) <<;}} > Type: output Hardness: 50 # 836 // 2 levels - TF - two vars, one comparator Selection.if.Nested ? Selection.if.{Condition.Relational.{true,false},ifClause.Simple} > {(){=;=;if( > ) if( >= ) = ; <<;}} // {(){=;=;if( > ) if( >= ) <<;}} // Simplified for S08 > Type: output Hardness: 50 # 837 // 2 levels - FT, two vars, two comparators Selection.if.Nested ? Selection.if.{Condition.Relational.{true,false},ifClause.Simple} > {(){=;=;if( > ) if( <= ) = ; <<;}} // {(){=;=;if( > ) if( <= ) <<;}} // Simplified for S08 > Type: output Hardness: 50 # 840 // 3 levels - TTT, one var, var in range Selection.if.Nested ? Selection.if.{Condition.Relational.true,ifClause.Simple} > {(){=;if( >= ) if( <= ) if( != ) = ; <<;}} // {(){=;if( >= ) if( <= ) if( != ) <<;}} // Simplified for S08 > Type: output Hardness: 50 # 841 // 3 levels - TTF, three vars, monotonicity Selection.if.Nested ? Selection.if.{Condition.Relational.{true,false},ifClause.Simple} > {(){=;=;=; if( < ) if( <= ) if( <= ) = ; <<;}} // {(){=;=;=; if( < ) if( <= ) if( <= ) <<;}} // Simplified for S08 > Type: output Hardness: 50 # 842 // 3 levels - TFT Selection.if.Nested ? Selection.if.{Condition.Relational.{true,false},ifClause.Simple} > {(){=;=;if( > ) if( >= ) if( + >= ) = ; <<;}} // {(){=;=;if( > ) if( >= ) if( + >= ) <<;}} // Simplified for S08 > Type: output Hardness: 50 # 843 // 3 levels - FTT Selection.if.Nested ? Selection.if.{Condition.Relational.{true,false},ifClause.Simple} > {(){=;=;if( + == 0) if( >= 0) if( <= 0 ) = ; <<;}} // {(){=;=;if( + == 0) if( >= 0) if( <= 0 ) <<;}} // Simplified for S08 > Type: output Hardness: 50 // 850 // Selection.if.Multiple // 2 Vs 3 statements // 2 levels - TT, TF, FT, FF // 3 levels - TTT, TTF, TFT, TFF, FTT, FTF, FFT FFF // (Same variable Vs different variables, all 6 relational operators) - NO postStatement, Compound Vs Simple mixed # 850 // 2 levels - TT, positive and negative numbers Selection.if.Multiple ? Selection.if.{Condition.Relational.true,ifClause.{Simple,Compound}} > {(){=;=;if( > ){<<; = + 1;} if( < 0) <<;}} // {(){=;=;if( > ){<<; <<;} if( + >= 0) << + ;}} // Simplified for S08 > Type: output Hardness: 50 # 851 // 2 levels - TT, <=, >= Selection.if.Multiple ? Selection.if.{Condition.Relational.true,ifClause.{Simple,Compound}} > {(){=;=;if( >= ) <<; if( <= ){ <<;}}} > Type: output Hardness: 50 # 852 // 2 levels - TF, !=, == Selection.if.Multiple ? Selection.if.{Condition.Relational.{true,false},ifClause.{Simple,Compound}} > {(){=;=;if( != )<<; if( - == 0) {<< ; = + 1;}}} // {(){=;=;if( != )<<; if( - == 0) {<< ; << ;}}} // Simplified for S08 > Type: output Hardness: 50 # 853 // 2 levels - FT, >, < Selection.if.Multiple ? Selection.if.{Condition.Relational.{true,false},ifClause.Compound} > {(){=;=;if( > ){<<; <<;} if( < ) {<< ; << ;}}} > Type: output Hardness: 50 # 854 // 2 levels - FF, -ve numbers Selection.if.Multiple ? Selection.if.{Condition.Relational.false,ifClause.Simple} > {(){=;if( + > 0)<<; if( - != 0) << ;}} > Type: output Hardness: 50 # 855 // 3 levels - TTT, +, - and / of two integers being > 0 Selection.if.Multiple ? Selection.if.{Condition.Relational.true,ifClause.{Simple,Compound}} > {(){=;=;if( + > 0)<< ; if( - >= 0) << ; if( * > 0 ) {<< + ; = ;}}} // {(){=;=;if( + > 0)<< ; if( - >= 0) << ; if( / > 0 ) {<<; << ;}}} // Simplified for S08 > Type: output Hardness: 50 # 856 // 3 levels - TTF: doubling a number and subtracting itself Selection.if.Multiple ? Selection.if.{Condition.Relational.{true,false},ifClause.Compound} > {(){=;= * 2;= - ;if( != )<< ; if( != ) << ; if( != ) {<< - ; = ;}}} // {(){=;= * 2;= - ;if( != )<< ; if( != ) << ; if( != ) {<<; << ;}}} // Simplified for S08 > Type: output Hardness: 50 # 857 // 3 levels - TFT - <, >, != Selection.if.Multiple ? Selection.if.{Condition.Relational.{true,false},ifClause.Compound} > {(){=;=;if( < ){<<;} if( > ) << ; if( != ) {<< - ; = ;}}} // {(){=;=;if( < ){<<;} if( > ) << ; if( != ) {<<; <<;}}} // Simplified for S08 > Type: output Hardness: 50 # 858 // 3 levels - TFF - Selection.if.Multiple ? Selection.if.{Condition.Relational.{true,false},ifClause.{Simple,Compound}} > {(){=;if( > 0){<<; = - 1;} = - ; if( > 0) << ; if( <= ) {<< - ; = ;}}} // {(){=;if( > 0){<<;} = - ; if( > 0) << ; if( <= ) {<<; <<;}}} // Simplified for S08 > Type: output Hardness: 50 # 859 // 3 levels - FFF Selection.if.Multiple ? Selection.if.{Condition.Relational.false,ifClause.Simple} > {(){=;if( + 1 < * 1) <<; if( + 2 > * 2 ) << + 2; if( + 3 > * 3)<< + 3;}} > Type: output Hardness: 50 # 860 // 3 levels - FTT - monotonicity Selection.if.Multiple ? Selection.if.{Condition.Relational.{true,false},ifClause.{Simple,Compound}} > {(){=;=;if( < ){<<;<<;} = + ;if( < ) << ; if( <= ) {<<; = ;}}} // {(){=;=;if( < ){<<;} = + ;if( < ) << ; if( <= ) {<<; <<;}}} // Simplified for S08 > Type: output Hardness: 50 # 861 // 3 levels - FFT - binary search Selection.if.Multiple ? Selection.if.{Condition.Relational.{true,false},ifClause.{Simple,Compound}} > {(){=;if( > 20){<< - 20; = - 20;} if( > 10) << - 10; if( >= 5) {<<; = + 20;}}} // {(){=;if( > 20){<< - 20;} if( > 10) << - 10; if( >= 5) {<<;}}} // Simplified for S08 > Type: output Hardness: 50 # 862 // 3 levels - FTF - all negative numbers - not sure they will be able to solve this correctly Selection.if.Multiple ? Selection.if.{Condition.Relational.{true,false},ifClause.{Simple,Compound}} > {(){=;=;if( + > 0){<<; <<;} if( - < 0) << ; if( * > 0) {<<; <<;}}} // {(){=;=;if( + > 0){<<;} if( - < 0) << ; if( * > 0) {<<; <<;}}} // Simplified for S08 > Type: output Hardness: 50 //Errors - If/Else Statements // {(){=;;if( > 0){;<<<;<<;}}} // {(){=;=;if( == ){<<'T';}else{;<<;}}} // {(){=;if( == 100){< == 0){<;<<;}}}} //Errors - If Statements // {(){=;if( > 0){=;}<<;}} // {(){=;;if( > 100){<<;}}} // {(){=;if( == ){;<<;}}} //Code Ok - If/Else Statements // {(){=;if( > 0){<<;}else{<<'E';}=;if( < 100){<<;}else{<<;}}} // {(){=;if( > 0){<;}}} // {(){=;=;if( > ){<<;}else{<<;}}} // {(){=;if( < -100){<<'T';}else{<<'F';}}} // {(){=;if( == ){<<;}else{<<;}}} // {(){=;if( > 0){<<;}else{if( < -500){<<'L';}else{<<'H';}}}} // ------------------ Parsons Puzzles -------------------------------------------------------- // Learning objectives: // Selection.ifElse.Parsons.Single.Simple - 2000 // Braces provided any way, but can be ignored by the student // Selection.ifElse.Parsons.Single.Compound - 2025 // Braces cannot be ignored by the student // Selection.ifElse.Parsons.Multiple.Simple - 2050 // Braces provided any way, but can be ignored by the student // Selection.ifElse.Parsons.Multiple.Compound - 2075 // Braces cannot be ignored by the student // Selection.ifElse.Parsons.Nested.Cascading.Simple - 2100 // Braces provided any way, but can be ignored by the student // Selection.ifElse.Parsons.Nested.Cascading.Compound - 2125 // Braces cannot be ignored by the student // Selection.ifElse.Parsons.Nested.Taxonomic.Simple - 2150 // Braces provided any way, but can be ignored by the student // Selection.ifElse.Parsons.Nested.Taxonomic.Compound - 2175 // Braces cannot be ignored by the student // -------------------------------------------------------------------------------------------- // Selection.ifElse.Parsons.Single.Simple - 2000 // One input: 2000-; Two inputs: 2005- // DemoParsons // Prints whether the number is odd or even # 2000 Selection.ifElse.Parsons.Single.Simple > "It reads a number and prints whether it is odd or even." {(){ /* Declare */ ; /* Read */ << "Enter the number"; >> ; /* Compute and print whether is odd or even */ if( % 2 == 0) {<< << " is even";} else {<< << " is odd";}}} > Type: parsons Hardness: 20 // Read sound in decibels, prints loud if over 85 decibels # 2001 Selection.ifElse.Parsons.Single.Simple > "It reads sound in decibels, and prints whether it is loud (if over 85 decibels) or tolerable." {(){ /* Declare */ ; /* Read */ << "Enter the loudness of sound in decibels"; >> ; /* Compute and print whether the sound is loud (over 85) or tolerable */ if( > 85 ) {<< "Sound is loud";} else {<< "Sound is tolerable";}}} > Type: parsons Hardness: 20 // Read temperature, print has fever if over 98.6 and no fever otherwise # 2002 Selection.ifElse.Parsons.Single.Simple > "It reads body temperature in celsius, and prints whether the person has fever (if over 37) or is normal." {(){ /* Declare */ ; /* Read */ << "Enter the body temperature in celsius"; >> ; /* Compute and print whether the person has fever (over 37) or is normal */ if( > 37 ) {<< "Person has fever";} else {<< "Person is normal";}}} > Type: parsons Hardness: 20 // Pretest // Print the smaller number # 2005 Selection.ifElse.Parsons.Single.Simple > "It reads two numbers and prints the smaller value among them." {(){ /* Declare */ ; /* Declare */ ; /* Read */ << "Enter the first value"; >> ; /* Read */ << "Enter the second value"; >> ; /* If is less than , print . Otherwise, print */ if( < ){<< ;} else {<< ;}}} > Type: parsons Hardness: 30 // Prints buy if the price to earnings ratio is 19 or less, and sell otherwise # 2006 Selection.ifElse.Parsons.Single.Simple > "It reads the price and earnings of a stock. It recommends buying the stock if the price to earnings ratio is 19 or less, and selling otherwise." {(){ /* Declare */ ; /* Declare */ ; /* Read */ << "Enter the price of the stock"; >> ; /* Read */ << "Enter the earnings of the stock"; >> ; /* Compute and print the smaller value of and */ if( / <= 19.0 ){<< "Buy the stock";} else {<< "Sell the stock";}}} > Type: parsons Hardness: 30 // Posttest // Reads two numbers, and prints whether the second is a factor in the first # 2007 Selection.ifElse.Parsons.Single.Simple > "It reads two numbers and prints whether or not the second number is a factor of the first." {(){ /* Declare */ ; /* Declare */ ; /* Read */ << "Enter the first number"; >> ; /* Read */ << "Enter the second number"; >> ; /* Compute and print whether evenly divides */ if( % == 0 ){<< << " is a factor of " << ;} else {<< << " is NOT a factor of " << ;}}} > Type: parsons Hardness: 30 // Compute and print the absolute difference # 2008 Selection.ifElse.Parsons.Single.Simple > "It reads two numbers and prints the absolute difference between them." {(){ /* Declare */ ; /* Declare */ ; /* Declare */ ; /* Read */ << "Enter the first number"; >> ; /* Read */ << "Enter the second number"; >> ; /* Compute and print whether evenly divides */ if( > ){ = - ;} else { = - ;} /* Print */ << ; }} > Type: parsons Hardness: 35 // Based on atomic weight, print whether noble metal/rare earth/ etc. // // Used to test whether we correctly figure out which braces are optional. // # 2002 // Selection.ifElse.Parsons.Single.Simple // > // "It reads a number and prints whether it is odd or even." // {(){ // /* Declare */ // = ; // /* Compute and print */ // if( != 2 ) // { << "Nested1"; << "Nested2"; } // else // // { if( > 0 ){ << "Nested1"; << "Nested2"; << "Nested3"; } } // { if( > 0 ){ << "Positive"; } else { << "Negative"; } } // }} // > // Type: parsons // Hardness: 20 // -------------------------------------------------------------------------------------------- // Selection.ifElse.Parsons.Single.Compound - 2025 // Converting from military hour to civilian hour # 2025 Selection.ifElse.Parsons.Single.Compound ? Selection.ifElse.Parsons.Single.Simple > "It reads military hour (0-23) and prints corresponding civilian hour (12 AM - 12PM)." {(){ /* Declare */ ; /* Read */ << "Enter the military hour"; >> ; /* Compute and print civilian hour */ if( < 12) { if( 0 == ) { << "12"; } else { << ; } << " AM";} else { if( > 12 ) { << - 12; } else { << "12"; } << " PM";}}} > Type: parsons Hardness: 50 // celsius to fahrenheit? from unit, to unit.. // -------------------------------------------------------------------------------------------- // Selection.ifElse.Parsons.Multiple.Simple - 2050 // ice cream or yogurt, cup or cone // positive shallow slope # 2050 Selection.ifElse.Parsons.Multiple.Simple ? Selection.ifElse.Parsons.Single.Simple > "It reads the slope of a line and prints whether it is positive or negative and shallow (less than 45 degrees) or steep." {(){ /* Declare */ ; /* Read */ << "Enter the slope"; >> ; /* Compute and print whether it is positive or negative */ if( >= 0) { << "Slope is positive, "; } else { << "Slope is negative, "; } /* Compute and print whether it is shallow (less than 45 degrees) or steep */ if( < 45 ) { << "shallow"; } else { << "steep"; } }} > Type: parsons Hardness: 20 // Grade A/B/C/D and + or - // suit and face of a card - multiple nested, though! // face card versus pip card (<= 10) black suit (c,s) versus red suit // print north/south based on latitude and east/west based on longitude // Actually, suitable for if.Parsons.Multiple.simple // Smallest of 3 numbers: min is smaller of a and b. if min less than c, print min, else c // -------------------------------------------------------------------------------------------- // Selection.ifElse.Parsons.Multiple.Compound - 2075 // two sets of inputs? // pressure = force / area convert from british to metric units? // // -------------------------------------------------------------------------------------------- // Selection.ifElse.Parsons.Nested.Cascading.Simple - 2100 // 4: 2100; 5: 2105; 7: 2110 // 4 // Month -> Season # 2100 Selection.ifElse.Parsons.Nested.Cascading.Simple > "It reads the month and prints the corresponding season: Winter (January-March), Spring (April-June), Summer (July-September) and Fall otherwise)." {(){ /* Declare */ ; /* Read */ << "Enter the number of the month (1-12)"; >> ; /* Compute and print the season based on */ if( <= 3) {<< "Season is winter (January-March)";} else{ if( <= 6) {<< "Season is spring (April-June)";} else{ if( <= 9) {<< "Season is summer (July-September)";} else {<< "Season is fall (October-December)";}}}}} > Type: parsons Hardness: 20 // DemoParsons // 4 // Degrees and quadrants # 2101 Selection.ifElse.Parsons.Nested.Cascading.Simple > "It reads location in degrees and prints the corresponding quadrant: First (1-90), Second (91-180), Third (181-270) and Fourth otherwise." {(){ /* Declare */ ; /* Read */ << "Enter the location in degrees (1-360)"; >> ; /* Compute and print the quadrant based on */ if( <= 90) {<< "First quadrant";} else{ if( <= 180) {<< "Second quadrant";} else{ if( <= 270) {<< "Third quadrant";} else {<< "Fourth quadrant";}}}}} > Type: parsons Hardness: 20 // Pretest // 5 // numerical to letter grade - integer # 2105 Selection.ifElse.Parsons.Nested.Cascading.Simple > "It reads numerical grade, converts it to letter grade - A (90 and up), B (80-89), C (70-79), D (55-69) and F otherwise - and prints it." {(){ /* Declare */ ; /* Declare */ ; /* Read */ << "Enter the numerical grade"; >> ; /* Compute based on */ if( >= 90) { = 'A';} else{ if( >= 80) { = 'B';} else{ if( >= 70) { = 'C';} else{ if( >= 55) { = 'D';} else{ = 'F';}}}} /* Print */ << ; }} > Type: parsons Hardness: 30 // Posttest // 5 // Prints the status of a student based on the number of credits # 2106 Selection.ifElse.Parsons.Nested.Cascading.Simple > "It reads the number of credits earned by a student and prints the status of the student: freshman (0-28), sophomore (29-56), junior (57-84) senior (85-128) and graduate (129-)." {(){ /* Declare */ ; /* Read */ << "Enter the credits earned by the student"; >> ; /* Compute and print the status of the student */ if( >= 129 ) { << "Status is graduate (over 128 credits)"; } else { if( >= 85 ) { << "Status is senior (85-128 credits)"; } else { if( >= 57 ) { << "Status is junior (57-84 credits)"; } else { if( >= 29 ) { << "Status is sophomore (29-56 credits)"; } else { << "Status is freshman (0-28 credits)"; }}}} }} > Type: parsons Hardness: 30 // 5 // 440 miles and up: Exosphere, 50 miles and up thermosphere, // 31 miles and up is mesosphere, 7 miles and up is stratosphere and otherwise, troposphere // 0-12, 12-50, 50-80, 80-700, 700-10,000 in km all approx // Prints name of atmospheric layer # 2107 Selection.ifElse.Parsons.Nested.Cascading.Simple > "It reads the altitude in miles and prints the name of the atmospheric layer at that altitude: troposphere (0 - 7), stratosphere (8 - 30), mesosphere (31 - 50), thermosphere (51 - 440) and exosphere (over 440)." {(){ /* Declare */ ; /* Read */ << "Enter the altitude"; >> ; /* Compute and print the name of the atmospheric layer */ if( <= 7 ) { << "Troposphere (0-7 miles)"; } else { if( <= 30 ) { << "Stratosphere (8-30 miles)"; } else { if( <= 50 ) { << "Mesosphere (31-50 miles)"; } else { if( <= 440 ) { << "Thermosphere (51-440 miles)"; } else { << "Exosphere (over 440 miles)"; }}}}}} > Type: parsons Hardness: 30 // 6 // Frequencies and colors (in reverse order of VBGYOR) # 2110 Selection.ifElse.Parsons.Nested.Cascading.Simple > "It reads wavelength of light and prints the corresponding color: violet, blue, green, yellow, orange or red." {(){ /* Declare */ ; /* Read */ << "Enter the wavelength in nanometers"; >> ; /* Compute and print the color corresponding to the wavelength */ if( <= 450 ) { << "Color is violet (380-450 nm)"; } else { if( <= 495 ) { << "Color is blue (450-495 nm)"; } else { if( <= 570 ) { << "Color is green (495-570 nm)"; } else { if( <= 590 ) { << "Color is yellow (570-590 nm)"; } else { if( <= 620 ) { << "Color is orange (590-620 nm)"; } else { << "Color is red (620-750 nm)"; } }}}}}} > Type: parsons Hardness: 40 // 7 // Prints enhanced Fujita scale # 2111 Selection.ifElse.Parsons.Nested.Cascading.Simple > "It reads wind speed (mph), computes and prints enhanced Fujita Hurricane scale corresponding to it: F0 (40-72), F1 (73-112), F2 (113-157), F3 (158-206), F4 (207-260) and F5 (261-)." {(){ /* Declare */ ; /* Read */ << "Enter the wind speed in miles per hour"; >> ; /* Compute and print the Fujita scale corresponding to wind speed */ if( >= 261 ) { << "Scale is F5 (over 260 mph)"; } else { if( >= 207 ) { << "Scale is F4 (207-260 mph)"; } else { if( >= 158 ) { << "Scale is F3 (158-206 mph)"; } else { if( >= 113 ) { << "Scale is F2 (113-157 mph)"; } else { if( >= 73 ) { << "Scale is F1 (73-112 mph)"; } else { if( >= 40 ) { << "Scale is F0 (40-72 mph)"; } else { << "Not a hurricane"; } }}}}} }} > Type: parsons Hardness: 40 // 8 oz is smal,, 12 is medium, 16 is large, over 16 is extra large // PROBLEMS THAT NEED AN ALGORITHM - OTHERWISE, ORDER IS NOT FIXED // Leap year # 2115 Selection.ifElse.Parsons.Nested.Cascading.Simple > "It reads a year and prints whether it is a leap year or not." {(){ /* Declare */ ; /* Read */ << "Enter the year"; >> ; /* If is not divisible by 4, it is not a leap year */ if( % 4 != 0 ) { << "Not leap year"; } else { /* If is divisible by 4, but not by 100, it is a leap year */ if( % 100 != 0 ) { << "Leap year"; } else { /* If is divisible by 4 and 100, but not by 400, it is a leap year. Otherwise, it is not. */ if( % 400 == 0 ) { << "Leap year"; } else { << "Not leap year"; } }}}} > Type: parsons Hardness: 20 // calculator: 1 to add, 2 to subtract, 3 to multiply and 4 to divide - real - order not important # 2116 Selection.ifElse.Parsons.Nested.Cascading.Simple > "It implements a calculator: It reads two numbers and an operation (+/-/*/%), applies the operation to the two numbers and prints the result." {(){ /* Declare */ ; /* Declare */ ; /* Declare */ ; /* Declare */ ; /* Read */ << "Enter the first number"; >> ; /* Read */ << "Enter the second number"; >> ; /* Read */ << "Enter + to add, - to subtract, * to multiply and / to divide"; >> ; /* Compute by adding and */ if('+' == ) { = + ;} else{ /* Compute by subtracting from */ if('-' == ) { = - ;} else{ /* Compute by multipying by */ if('*' == ) { = * ;} else{ /* Compute by dividing by */ = / ;}}} /* Print */ << ; }} > Type: parsons Hardness: 20 // Reads character suit of a card, prints its name // name of coin // name of month // pH of 1-6 is acidic, 7 is neutral and 8-14 is basic // types of plastic 1-6 // 1: POLYETHYLENE TEREPHTHALATE (PET OR PETE) (2 lts soda bottles, single-use water bottles // 2: HIGH DENSITY POLYETHYLENE (HDPE) (milk jugs, detergent bottles, yogurt tub, bottle cap // 3: POLYVINYL CHLORIDE (PVC): house siding, pipes, saran wrap, outdoor furniture // 4: LOW DENSITY POLYETHYLENE (LDPE): grocery bags, trash can liners, food storage containers // 5: POLYPROPYLENE (PP): bottle caps, food containers, drinking straws // 6: POLYSTYRENE (PS): styrofoam peanuts, clam shell containers, meat trays, plastic tableware // 7: OTHER: Tupperware // -------------------------------------------------------------------------------------------- // Selection.ifElse.Parsons.Single.Cascading.Compound - 2125 // // mega, giga, after dividing by powers of 10 // # 2125 // Selection.ifElse.Parsons.Nested.Cascading.Compound // > // "It reads the size of memory in bytes, divides by appropriate power of 10 and prints it with appropriate units: bytes (less than 1000), Kilobytes (up to a million), Megabyte (up to a billion), and Gigabyte (above a billion)." // {(){ // /* Declare */ // ; // /* Read */ // << "Enter the size of the memory in bytes"; // >> ; // /* Compute and print the size of memory with units */ // if( <= 1000 ) // { << ; << " bytes"; } // else { // if( <= 1000000 ) // { << / 1000; << " Kilobytes"; } // else { // if( <= 1000000000 ) // { << / 1000000; << " Megabytes"; } // else { // { << / 1000000000; << " Gigabytes"; }}}}}} // > // Type: parsons // Hardness: 20 // federal taxes : rate, deduction // Similary, up to -3: milli, micro, nano, pico, femto, alto.. // credit card: silver, gold, platinum, black - annual fees, interest rate, mini payment // NEED ALGORITHM // tuition: per credit, fees? // -------------------------------------------------------------------------------------------- // Selection.ifElse.Parsons.Single.Taxonomic.Simple - 2150 // smallest of 3 numbers - order not important # 2150 Selection.ifElse.Parsons.Nested.Taxonomic.Simple > "It reads 3 numbers and computes the smallest of the three and prints it." {(){ /* Declare */ ; /* Declare */ ; /* Declare */ ; /* Declare */ ; /* Read */ << "Enter the first number"; >> ; /* Read */ << "Enter the second number"; >> ; /* Read */ << "Enter the third number"; >> ; /* If is greater than */ if( > ) { /* If is greater than , is smallest. Otherwise, is smallest */ if( > ) { = ; } else { = ; } } else { /* If is greater than , is smallest. */ if( > ) { = ; } else { /* If is greater than , is smallest. Otherwise, is smallest */ if( > ) { = ; } else { = ; } } } /* Print */ << ; }} > Type: parsons Hardness: 20 // -------------------------------------------------------------------------------------------- // Selection.ifElse.Parsons.Nested.Taxonomic.Compound - 2175 // [, ] # 2175 Selection.ifElse.Parsons.Nested.Taxonomic.Compound > "Re-assemble the following code. If the value of is less than , it must print the sum of and . Otherwise, it must print the difference of and ." {(){=; if( < ){ = + ;}else { = - ;} << ;}} > Type: parsons Hardness: 20 // ---------------------------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/Problem: // 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 // Options for non-nested if-else // Design: have two in the same program to emphasize their independence // Problem: if-else in output - not something we have done so far // Alternative: use a string variable and have one output statement per variable // Read latitude/parallel (-90 - 90) print northern/southern hemisphere, // read longitude/meridian (1-360), print if west (180 or less) or // east of GMT - 2 if-elses // Note: 15 degrees longitude is 1 hour removed from GMT, but before/after GMT calculations can get messy // Similarly, could just ask for latitude/parallel, print northern/southern hemisphere and // torrid or temperate (23 degrees), but would need Math.abs to have a single if-else // Too complicated Math to compute the hour based on meridian // Read slope (0 - 90) and print whether steep or shallow (< 45), read intercept (any signed number) // and print whether positive or negative intercept - 2 if-elses // Read price, earnings, compute whether to buy/sell and whether good value based on price? // Read a real number (miles/kilometers), and a character m/k, convert to the other unit and print with unit // Could have one combined if-else or two if-elses // For Java, could ask to input 7 for miles, 5 for kilometers (telephone keypad) # 4000 Selection.ifElse.Solve.Multiple > "Write a program to read distance, a real value, and its unit (miles or kilometers), a character value. The program should calculate and print the equivalent distance in the other unit: if input was in miles, output should be in kilometers and vice versa. Print both the equivalent distance and the other unit, e.g., if input is 1 and m, output should be: Distance is 1.6 kilometers" {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: distance Name: Type: */^^;^ /* Statement: Declare Purpose: unit Name: Type: */^^;^ /* Statement: Declare Purpose: equivalent distance Name: Type: */^^;^ /* Statement: Declare Purpose: other unit Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: distance Format: Read distance */ /* Statement: Prompt Purpose: distance Format: Enter distance */^^<< "Enter distance";^ /* Statement: Input Purpose: distance */^^>> ;^ /* Statement: Section Purpose: unit Format: Read unit */ /* Statement: Prompt Purpose: unit Format: Enter unit (m or k) */^^<< "Enter unit (m or k)";^ /* Statement: Input Purpose: unit */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: equivalent distance BasedOn: n miles = 1.6n kilometers */^^if( 'm' == ){ = / 1.6; } else { = * 1.6;}^ /* Statement: Compute Purpose: other unit BasedOn: kilometers if unit is m and miles if unit is k */^^if( 'm' == ){ = "kilometers"; } else { = "miles";}^ /** Output Section */ /* Statement: Output Purpose: equivalent distance Format: Distance is 1.6 */^^<< "Distance is " << ;^ /* Statement: Output Purpose: other unit Format: kilometers */^^<< ;^ }} > Type: code Hardness: 30 // Number of input variables * 5 + number of output variables * 5 + number of expression operators * 5 + number of intermediate variables * 10 // computing tuition and fees based on number of credits # 4001 Selection.ifElse.Solve.Multiple > "Write a program to read the number of credits taken by a student and calculate tuition and fees. Tuition is $ 450 per credit, but capped at $ 5000 for 12 or more credits. Fees are $ 30 per credit, but capped at $ 300 for 10 or more credits." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: credits Name: Type: */^^;^ /* Statement: Declare Purpose: tuition Name: Type: */^^;^ /* Statement: Declare Purpose: fees Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: credits Format: Read credits */ /* Statement: Prompt Purpose: credits Format: Enter credits */^^<< "Enter credits";^ /* Statement: Input Purpose: credits */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: tuition BasedOn: $ 5000 if 12 credits or more and credits * 450 otherwise */^^if( >= 12 ){ = 5000; } else { = * 450;}^ /* Statement: Compute Purpose: fees BasedOn: $ 300 if 10 credits or more and credits * 30 otherwise */^^if( >= 10 ){ = 300; } else { = * 30;}^ /** Output Section */ /* Statement: Output Purpose: tuition Format: Tuition for 8 credits is $ 3600.0 */^^<< "Tuition for " << << " credits is $ " << ;^ /* Statement: Output Purpose: fees Format: Fees for 8 credits is $ 240.0 */^^<< "Fees for " << << " credits is $ " << ;^ }} > Type: code Hardness: 35 // Number of input variables * 5 + number of output variables * 5 + number of expression operators * 5 + number of intermediate variables * 10 // Read a real number (pounds/kilograms), and a character p/k, convert to the other unit and print with unit // Could have one combined if-else or two if-elses // For Java, could ask to input 7 for pounds, 5 for kilograms (telephone keypad) # 4002 Selection.ifElse.Solve.Multiple > "Write a program to read weight, a real value, and its unit (pounds or kilograms), a character value. The program should calculate and print the corresponding weight in the other unit: if input was in pounds, output should be in kilograms and vice versa. Print both the corresponding weight and the other unit, e.g., if input is 1 and k, output should be: Weight is 2.2 pounds" {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: weight Name: Type: */^^;^ /* Statement: Declare Purpose: unit Name: Type: */^^;^ /* Statement: Declare Purpose: corresponding weight Name: Type: */^^;^ /* Statement: Declare Purpose: other unit Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: weight Format: Read weight */ /* Statement: Prompt Purpose: weight Format: Enter weight */^^<< "Enter weight";^ /* Statement: Input Purpose: weight */^^>> ;^ /* Statement: Section Purpose: unit Format: Read unit */ /* Statement: Prompt Purpose: unit Format: Enter unit (p or k) */^^<< "Enter unit (p or k)";^ /* Statement: Input Purpose: unit */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: corresponding weight BasedOn: n kilograms = 2.2n pounds */^^if( 'p' == ){ = / 2.2; } else { = * 2.2;}^ /* Statement: Compute Purpose: other unit BasedOn: kilograms if unit is p and pounds if unit is k */^^if( 'p' == ){ = "kilograms"; } else { = "pounds";}^ /** Output Section */ /* Statement: Output Purpose: corresponding weight Format: Weight is 2.2 */^^<< "Weight is " << ;^ /* Statement: Output Purpose: other unit Format: pounds */^^<< ;^ }} > Type: code Hardness: 30 // Number of input variables * 5 + number of output variables * 5 + number of expression operators * 5 + number of intermediate variables * 10 // 1 input, 1 output, 2 intermediate variables // prix fixe restaurant // If 10 or more people, $ 25.00 per meal otherwise, $ 30 per meal. input number of patrons // if 6 or more, 25% service charge, 15% o/w. Calc and print total cost # 4003 Selection.ifElse.Solve.Multiple > "A prix fixe restaurant charges a flat price per meal: $ 25 per meal for a party of 10 or more diners and $ 30 per meal otherwise. It charges 25% service charge for a party of 6 or more diners and 15% otherwise. Write a program to read the number of diners in the party, and calculate and print the total cost." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: diners Name: Type: */^^;^ /* Statement: Declare Purpose: price per meal Name: Type: */^^;^ /* Statement: Declare Purpose: service charge Name: Type: */^^;^ /* Statement: Declare Purpose: total cost Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: diners Format: Read diners */ /* Statement: Prompt Purpose: diners Format: Enter number of diners */^^<< "Enter number of diners";^ /* Statement: Input Purpose: diners */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: price per meal BasedOn: $ 25 if 10 or more diners and $ 30 otherwise */^^if( >= 10 ){ = 25; } else { = 30; }^ /* Statement: Compute Purpose: service charge BasedOn: 25% if 6 or more diners and 15% otherwise */^^if( >= 6 ){ = .25; } else { = .15; }^ /* Statement: Compute Purpose: total cost BasedOn: price per meal * diners * (1 + service charge) */^^ = * * (1 + );^ /** Output Section */ /* Statement: Output Purpose: total cost Format: The cost for 5 diners is $ 172.50 */^^<< "The cost for " << << " diners is $ " << ;^ }} > Type: code Hardness: 30 // Number of input variables * 5 + number of output variables * 5 + number of expression operators * 5 + number of intermediate variables * 10 // Read a real number (celsius/fahrenheit), and a character c/f, convert to the other unit and print with unit // Could have one combined if-else or two if-elses // For Java, could ask to input 1 for celsius, 2 for fahrenheit (telephone keypad) # 4004 Selection.ifElse.Solve.Multiple > "Write a program to read temperature, a real value, and its unit (celsius or fahrenheit), a character value. The program should convert the temperature to the other unit, i.e., convert celsius to fahrenheit and fahrenheit to celsius. It should print the converted temperature and the other unit, e.g., if input is 32 and f, output should be: Temperature is 0 celsius" {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: temperature Name: Type: */^^;^ /* Statement: Declare Purpose: unit Name: Type: */^^;^ /* Statement: Declare Purpose: converted temperature Name: Type: */^^;^ /* Statement: Declare Purpose: other unit Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: temperature Format: Read temperature */ /* Statement: Prompt Purpose: temperature Format: Enter temperature */^^<< "Enter temperature";^ /* Statement: Input Purpose: temperature */^^>> ;^ /* Statement: Section Purpose: unit Format: Read unit */ /* Statement: Prompt Purpose: unit Format: Enter unit (c or f) */^^<< "Enter unit (c or f)";^ /* Statement: Input Purpose: unit */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: converted temperature BasedOn: n fahrenheit = (n - 32) * .55 celsius and n celsius = 1.8n + 32 fahrenheit */^^if( 'c' == ){ = * 1.8 + 32; } else { = ( - 32) * .55;}^ /* Statement: Compute Purpose: other unit BasedOn: fahrenheit if unit is c and celsius if unit is f */^^if( 'c' == ){ = "fahrenheit"; } else { = "celsius";}^ /** Output Section */ /* Statement: Output Purpose: converted temperature Format: Temperature is 32 */^^<< "Temperature is " << ;^ /* Statement: Output Purpose: other unit Format: celsius */^^<< ;^ }} > Type: code Hardness: 30 // Number of input variables * 5 + number of output variables * 5 + number of expression operators * 5 + number of intermediate variables * 10 // 2 // Ordering a restaurant meal: input cost, here or to go (h/g) // If for here, tips = 15%, delivery = 0. If to go, tips = 0, delivery = $ 10 // Could benefit from the interface where the user clicks on an existing if-else to add code to it // Use tuition and fees problem instead of 4 // 4 // Ordering furniture: input cost, pick up or delivery (d/p) (3/7 for Java) // pickup: tax: 6%, delivery fee = 0. delivery: tax: 3%, delivery fee = $ 75 // Could benefit from the interface where the user clicks on an existing if-else to add code to it 6 // Ordering appliance: input cost, purchase or install (i/p) (4/7 for Java) // purchase: tax: 6%, install fee = 0. install: tax: 0, install fee = $ 75 // Could benefit from the interface where the user clicks on an existing if-else to add code to it // Similarly, buying from a local store versus online // Read two numbers, print their absolute difference (using a third var) and their smaller ratio // Note: similar to smaller number // Read a number, print if it is positive/negative, odd/even - 2 if-elses // Purchase: // If groceries, tax = 0, else tax = 6% // // Airline luggage charges: input weight, largest dimension in inches // $ 40 per bag. If over 60 pounds, $ 25 surcharge. If largest dimension over 30", $ 25 surcharge // But, this only needs an if, not an if-else // --------------------multi input, 1 output problems------------------------- // computing the larger of the two sides of a rectangle - numerical, boring # 4020 Selection.ifElse.Solve.Multiple-Input-Output > "Write a program to read a length and width of a rectangle, compute the longer side and print it." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: length Name: Type: */^^;^ /* Statement: Declare Purpose: width Name: Type: */^^;^ /* Statement: Declare Purpose: longer Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: length Format: Read length */ /* Statement: Prompt Purpose: length Format: Enter length */^^<< "Enter length";^ /* Statement: Input Purpose: length */^^>> ;^ /* Statement: Section Purpose: width Format: Read width */ /* Statement: Prompt Purpose: width Format: Enter width */^^<< "Enter width";^ /* Statement: Input Purpose: width */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: longer BasedOn: larger of length and width */^^if( > ){ = ; } else { = ; }^ /** Output Section */ /* Statement: Output Purpose: longer Format: Larger side of 12 and 16 is 16 */^^<< "Larger side of " << << " and " << << " 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 // 1 input, 1 output // Get number of patrons for the movie, start hour of the movie // if starts at 7 or after, 15.25 per ticket o/w 12;50 per ticket // Compute total cost and print it // 2 inputs, 1 output // - input car's speed, speed limiit, calc excess speed, // speeding fine of 75 if excess over 15 mph and 60 otherwise // Nah - does not work // 2 inputs, 2 outputs // input length and width of a house, calc area // town taxes are 1.25 per square foot if under 1000 sq ft and 1.50 per o/w // --------------------------1 input, 1 output, multiple if-elses------------------------------ // 2 inputs, 3 outputs, 2 back-to-back if-elses // tree nursery: $ 150 for 3 years or younger, years * 50 for over 3 years // $ 50 for shipping within 100 miles, $ 150 otherwise // // Shipper charges $ 5 per pound up to 10 pounds and $ 75 for packages over 10 pounds // It charges a handling charge of $ 15 if volume of the package is less // pe ratio - calculate before output // print absolute difference // +ve/-ve slope based on endpoints // smaller of two numbers // odd or even - need string data type // tax based on type otf item // multiple if-elses // north west // top left // ice cream/sorbet, cup/cone cost // --------------------------1 input, 1 output, cascading-style nested if-else------------------------------ // computing the category of tornado - 4 options - only considered up to category 3 # 4100 Selection.ifElse.Nested.Cascading.Solve.Single-Input-Output > "Write a program to read wind speed and calculate Fujita tornado scale as follows: 0 for less than 73 mph, 1 for less than 113 mph, 2 for less than 158 mph and 3 otherwise." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: speed Name: Type: */^^;^ /* Statement: Declare Purpose: scale Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: speed Format: Read speed */ /* Statement: Prompt Purpose: speed Format: Enter speed */^^<< "Enter speed";^ /* Statement: Input Purpose: speed */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: scale BasedOn: 0 if less than 73 mph, 1 if less than 113 mph, 2 if less than 158 mph and 3 otherwise */^^if( < 73 ){ = 0; } else { if( < 113 ){ = 1; } else { if( < 158 ){ = 2; } else { = 3; } } }^ /** Output Section */ /* Statement: Output Purpose: scale Format: Wind speed of 200 mph is 3 on Fujita scale */^^<< "Wind speed of " << << " mph is " << << " on Fujita scale";^ }} > Type: code Hardness: 15 // Number of input variables * 5 + number of output variables * 5 + number of expression operators * 5 + number of intermediate variables * 10 // 3 for less than 207 mph, 4 for less than 261 mph, // , 3 if less than 207 mph, 4 if less than 261 mph, // computing the status based on credits - 4 options # 4101 Selection.ifElse.Nested.Cascading.Solve.Single-Input-Output > "Write a program to read the number of credits taken by a student and calculate the student's status as follows: freshman if credits <= 32, sophomore if credits <= 64, junior if credits <= 96 and senior otherwise." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: credits Name: Type: */^^;^ /* Statement: Declare Purpose: status Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: credits Format: Read credits */ /* Statement: Prompt Purpose: credits Format: Enter credits */^^<< "Enter credits";^ /* Statement: Input Purpose: credits */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: status BasedOn: freshman if credits up to 32, sophomore if credits up to 64, junior if credits up to 96 and senior otherwise */^^if( <= 32 ){ = "freshman"; } else { if( <= 64 ){ = "sophomore"; } else { if( <= 96 ){ = "junior"; } else { = "senior"; } } }^ /** Output Section */ /* Statement: Output Purpose: status Format: With 32 credits, your status is freshman */^^<< "With " << << " credits, your status 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 // computing lettergrade given numerical grade - 5 options # 4102 Selection.ifElse.Nested.Cascading.Solve.Single-Input-Output > "Write a program to read the numerical grade of a student and calculate the student's letter grade as follows: A if >= 90, B if >= 80, C if >= 70, D if >= 55 and F otherwise." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: numerical grade Name: Type: */^^;^ /* Statement: Declare Purpose: letter grade Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: numerical grade Format: Read numerical grade */ /* Statement: Prompt Purpose: numerical grade Format: Enter numerical grade */^^<< "Enter numerical grade";^ /* Statement: Input Purpose: numerical grade */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: letter grade BasedOn: A if >= 90, B if >= 80, C if >= 70, D if >= 55 and F otherwise */^^if( >= 90 ){ = 'A'; } else { if( >= 80 ){ = 'B'; } else { if( >= 70 ){ = 'C'; } else { if( >= 55 ){ = 'D'; }else{ = 'F'; } } } }^ /** Output Section */ /* Statement: Output Purpose: letter grade Format: The letter grade is A */^^<< "The letter grade 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 // computing season based on month # 4103 Selection.ifElse.Nested.Cascading.Solve.Single-Input-Output > "Write a program to read the month as a number and print the corresponding season, computed as follows: January - March is Winter, April - June is Spring, July - September is Summer and October - December is Fall." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: month Name: Type: */^^;^ /* Statement: Declare Purpose: season Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: month Format: Read month */ /* Statement: Prompt Purpose: month Format: Enter month */^^<< "Enter month";^ /* Statement: Input Purpose: month */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: season BasedOn: January - March is Winter, April - June is Spring, July - September is Summer and October - December is Fall */^^if( <= 3 ){ = "Winter"; } else { if( <= 6 ){ = "Spring"; } else { if( <= 9 ){ = "Summer"; } else { = "Fall"; } } }^ /** Output Section */ /* Statement: Output Purpose: season Format: The season is Summer */^^<< "The season 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 // TEST: unsignedtype specification // 0 -> 6 acidic, neutral, 8 -> 14 basic, illegal # 4104 Selection.ifElse.Nested.Cascading.Solve.Single-Input-Output > "Write a program to read the ph value of a solution (a positive number) and compute its nature as follows: 0 - 6 is acidic, 7 is neutral, 8 - 14 is basic and invalid otherwise." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: ph Name: Type: */^^;^ /* Statement: Declare Purpose: nature Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: ph Format: Read ph value */ /* Statement: Prompt Purpose: ph Format: Enter ph value */^^<< "Enter ph value";^ /* Statement: Input Purpose: ph */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: nature BasedOn: 0 - 6 is acidic, 7 is neutral, 8 - 14 is basic and invalid otherwise. */^^if( <= 6 ){ = "acidic"; } else { if( 7 == ){ = "neutral"; } else { if( <= 14 ){ = "basic"; } else { = "invalid"; } } }^ /** Output Section */ /* Statement: Output Purpose: nature Format: ph value of 7 is neutral */^^<< "ph value of " << << " 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 // toll: 15 for car, 22.50 for bus, 30 for truck, 9.95 for motorcycle - ABANDONED - BETTER FOR SWITCH // icecream, yogurt, sorbet, - bettre for switch // tax rate: nj, nj, pa, ct - better for switch // number of sides --> triangle, rectangle, pentagon, septagon, hexagon, octagon, - better for switch // color wavelengths? // 380-450: violet, 450-495: blue, 495-570: green, 570-590: yellow, 590-620: orange, 620-750: red // 100-400: ultraviolet, 400-780: visible, 780-1000: infrared, microwave and radio after that // gamma and x-rays before ultraviolet // leap year, negated? // Meant to test while loop but it does not work because validation script specifies do-while # 4198 Selection.ifElse.Nested.Cascading.Solve.Single-Input-Output > "Write a program to read the month as a number and print the corresponding season, computed as follows: January - March is Winter, April - June is Spring, July - September is Summer and October - December is Fall." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: month Name: Type: */^^;^ /* Statement: Declare Purpose: season Name: Type: */^^;^ /** Input Section */ /* Block: Section Purpose: month Function: validate Control: while */ while( !( >= 1 && <= 12) ) { /* Statement: Section Purpose: month Format: Read month */ /* Statement: Prompt Purpose: month Format: Enter month */^^<< "Enter month";^ /* Statement: Input Purpose: month */^^>> ;^ } /** Compute Section */ /* Statement: Compute Purpose: season BasedOn: January - March is Winter, April - June is Spring, July - September is Summer and October - December is Fall */^^if( <= 3 ){ = "Winter"; } else { if( <= 6 ){ = "Spring"; } else { if( <= 9 ){ = "Summer"; } else { = "Fall"; } } }^ /** Output Section */ /* Statement: Output Purpose: season Format: The season is Summer */^^<< "The season 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 // --------------------------2 inputs, 1 output, classification-style nested if-else------------------------------ // b&b: one rate through June, also based on number of days of stay # 4200 Selection.ifElse.Nested.Classification.Solve.Multiple-Input-Output > "A bread and breakfast charges based on the month of stay and the number of days for which a room is booked: for January - September stay: $ 99.95 if booked for up to 3 days and $ 89.95 if booked for 4 or more days. for October - December: $ 69.95 if booked for up to 3 days and $ 49.95 otherwise. Write a program to read the month of stay and the number of days booked and calculate the cost per day." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: month Name: Type: */^^;^ /* Statement: Declare Purpose: days Name: Type: */^^;^ /* Statement: Declare Purpose: cost Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: month Format: Read the month */ /* Statement: Prompt Purpose: month Format: Enter the month (1-12) */^^<< "Enter the month (1-12)";^ /* Statement: Input Purpose: month */^^>> ;^ /* Statement: Section Purpose: days Format: Read days of booking */ /* Statement: Prompt Purpose: days Format: Enter days booked */^^<< "Enter days booked";^ /* Statement: Input Purpose: days */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: cost BasedOn: January - September stay: $ 99.95 for up to 3 days and $ 89.95 for 4 or more days. October - December: $ 69.95 for up to 3 days and $ 49.95 otherwise. */^^if( <= 9 ){ if( <= 3 ){ = 99.95; }else{ = 89.95; } } else { if( <= 3 ){ = 69.95; }else{ = 49.95; } }^ /** Output Section */ /* Statement: Output Purpose: cost Format: The cost per day is $ 99.95 */^^<< "The cost per day is $ " << ;^ }} > Type: code Hardness: 25 // Number of input variables * 5 + number of output variables * 5 + number of expression operators * 5 + number of intermediate variables * 10 // postal rate - arrival in how many days, what weight of package # 4201 Selection.ifElse.Nested.Classification.Solve.Multiple-Input-Output > "An online store charges for shipping based on the weight of the package and the days in which it should be delivered: for 1-5 pounds: $ 9.95 if delivered within 2 days and $ 7.95 otherwise. for more than 5 pounds: $ 17.95 if delivered within 2 days and $ 13.95 otherwise. Write a program to read the weight of the package and the number of days in which to be delivered and calculate the cost of shipping." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: weight Name: Type: */^^;^ /* Statement: Declare Purpose: days Name: Type: */^^;^ /* Statement: Declare Purpose: cost Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: weight Format: Read the weight */ /* Statement: Prompt Purpose: weight Format: Enter the weight */^^<< "Enter the weight";^ /* Statement: Input Purpose: weight */^^>> ;^ /* Statement: Section Purpose: days Format: Read days of delivery */ /* Statement: Prompt Purpose: days Format: Enter delivery days */^^<< "Enter delivery days";^ /* Statement: Input Purpose: days */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: cost BasedOn: 1-5 pounds: $ 9.95 to deliver within 2 days and $ 7.95 otherwise. More than 5 pounds: $ 17.95 to deliver within 2 days and $ 13.95 otherwise. */^^if( <= 5 ){ if( <= 2 ){ = 9.95; }else{ = 7.95; } } else { if( <= 2 ){ = 17.95; }else{ = 13.95; } }^ /** Output Section */ /* Statement: Output Purpose: cost Format: The shipping cost is $ 17.95 */^^<< "The shipping cost is $ " << ;^ }} > Type: code Hardness: 25 // Number of input variables * 5 + number of output variables * 5 + number of expression operators * 5 + number of intermediate variables * 10 // bakery - cakes one price for fewer than 5, another for more than 5, how many days in advance the order is placed # 4202 Selection.ifElse.Nested.Classification.Solve.Multiple-Input-Output > "A bakery charges for cakes based on the number of cakes ordered and how many days ahead they were ordered: for 1-5 cakes: $ 19.95 per cake if ordered at least 3 days in advance and $ 29.95 otherwise. For more than 5 cakes: $ 15.95 if ordered at least 3 days in advance and $ 26.95 otherwise. Write a program to read the number of cakes and the number of days ordered in advance and calculate the cost per cake." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: cakes Name: Type: */^^;^ /* Statement: Declare Purpose: days Name: Type: */^^;^ /* Statement: Declare Purpose: cost Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: cakes Format: Read number of cakes */ /* Statement: Prompt Purpose: cakes Format: Enter number of cakes */^^<< "Enter number of cakes";^ /* Statement: Input Purpose: cakes */^^>> ;^ /* Statement: Section Purpose: days Format: Read number of days */ /* Statement: Prompt Purpose: days Format: Enter days in advance */^^<< "Enter days in advance";^ /* Statement: Input Purpose: days */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: cost BasedOn: 1-5 cakes: $ 19.95 if ordered at least 3 days ahead and $ 29.95 otherwise. More than 5 cakes: $ 15.95 if ordered at least 3 days ahead and $ 26.95 otherwise */^^if( <= 5 ){ if( >= 3 ){ = 19.95; }else{ = 29.95; } } else { if( >= 3 ){ = 15.95; }else{ = 26.95; } }^ /** Output Section */ /* Statement: Output Purpose: cost Format: The cost per cake is $ 15.95 */^^<< "The cost per cake is $ " << ;^ }} > Type: code Hardness: 25 // Number of input variables * 5 + number of output variables * 5 + number of expression operators * 5 + number of intermediate variables * 10 // computing insurance premium based on gender and age # 4203 Selection.ifElse.Nested.Classification.Solve.Multiple-Input-Output > "Write a program to read gender and age of a driver and calculate insurance premium as follows: $ 195 for male driver under 25, $ 135 for male driver 25 or over, $ 155 for female driver under 25 and $ 105 for female driver 25 or over." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: gender Name: Type: */^^;^ /* Statement: Declare Purpose: age Name: Type: */^^;^ /* Statement: Declare Purpose: premium Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: gender Format: Read gender */ /* Statement: Prompt Purpose: gender Format: Enter gender (m/f) */^^<< "Enter gender (m/f)";^ /* Statement: Input Purpose: gender */^^>> ;^ /* Statement: Section Purpose: age Format: Read age */ /* Statement: Prompt Purpose: age Format: Enter age */^^<< "Enter age";^ /* Statement: Input Purpose: age */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: premium BasedOn: $ 195 for male drivers under 25, $ 135 for male drivers 25 or over, $ 155 for female drivers under 25 and $ 105 for female drivers 25 or over */^^if( 'm' == ){ if( < 25 ){ = 195; }else{ = 135; } } else { if( < 25 ){ = 155; }else{ = 105; } }^ /** Output Section */ /* Statement: Output Purpose: premium Format: Premium is $ 135 */^^<< "Premium is $ " << ;^ }} > Type: code Hardness: 25 // Number of input variables * 5 + number of output variables * 5 + number of expression operators * 5 + number of intermediate variables * 10 // movie tix: child vs adult, matinee vs prime time # 4204 Selection.ifElse.Nested.Classification.Solve.Multiple-Input-Output > "Write a program to read the type of patron (child/adult) and the time of the movie and calculate the cost of a movie ticket as follows: $ 9.95 for a child before 5 and $ 13.95 afterwards, $ 14.95 for adults before 5 and $ 19.95 afterwards." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: type Name: Type: */^^;^ /* Statement: Declare Purpose: time Name: Type: */^^;^ /* Statement: Declare Purpose: cost Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: type Format: Read type of patron */ /* Statement: Prompt Purpose: type Format: Enter type of patron (c/a) */^^<< "Enter type of patron (c/a)";^ /* Statement: Input Purpose: type */^^>> ;^ /* Statement: Section Purpose: time Format: Read time */ /* Statement: Prompt Purpose: time Format: Enter time of movie (1-12) */^^<< "Enter time of movie (1-12)";^ /* Statement: Input Purpose: time */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: cost BasedOn: $ 9.95 for a child before 5 and $ 13.95 afterwards, $ 14.95 for adults before 5 and $ 19.95 afterwards */^^if( 'c' == ){ if( < 5 ){ = 9.95; }else{ = 13.95; } } else { if( < 5 ){ = 14.95; }else{ = 19.95; } }^ /** Output Section */ /* Statement: Output Purpose: cost Format: The cost of the ticket is $ 14.95 */^^<< "The cost of the ticket is $ " << ;^ }} > Type: code Hardness: 25 // Number of input variables * 5 + number of output variables * 5 + number of expression operators * 5 + number of intermediate variables * 10 // reliable ranges: month, age, weight, height, speed, volume, pressure.. // See if you can come up with two range variables, rather than 1 value and 1 range variable as in the previous two examples // iffy problems: // cost of a drink: up to 32 oz, over 32 oz, regular/diet // toll: cars vs trucks, before 17 vs after // airtix: coach, business, peak season vs non-peak season for a certain route // meal plan: weekdays vs weekends, lunch vs dinner // parking lot: rate based on weight, whether regular customer // -------------------------------------------------------------------------- // 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 // --------------------------------------------------------------------------