// 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 / parsons // 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 // ------------------------------------------------------------------------------- // The actual learning objectives: // 2000 // Sequence.Parsons.Single // 2025 // Sequence.Parsons.Tandem // // Input-Compute-Output-Dependent Input-Compute-Output // 2050 // Sequence.Parsons.Hidden // Input-ComputeHidden-Compute-Output // ---------------------------Addition------------------------------------------- // Calculate total as sum of cost and tax # 2000 Sequence.Parsons > "It reads the cost of an item and tax, calculates the sum of the two and prints it." {(){ /* Declare */ ; /* Declare */ ; /* Declare */ ; /* Read */ << "Enter the cost of the item"; >> ; /* Read */ << "Enter the tax to be paid"; >> ; /* Calculate as sum of and */ = + ; /* Print */ << ;}} > Type: parsons Hardness: 20 // Calculate the total duration as the duration of the move and trailers # 2001 Sequence.Parsons > "It reads the duration of the movie and trailers, calculates their sum and prints it." {(){ /* Declare */ ; /* Declare */ ; /* Declare */ ; /* Read */ << "Enter the duration of the movie"; >> ; /* Read */ << "Enter the duration of the previews"; >> ; /* Calculate as the sum of and */ = + ; /* Print */ << ;}} > Type: parsons Hardness: 20 // ---------------------------Subtraction------------------------------------------- // Calculate balance of income - expenses # 2005 Sequence.Parsons > "It reads income, and expenses, calculates the balance and prints it." {(){ /* Declare */ ; /* Declare */ ; /* Declare */ ; /* Read */ << "Enter income"; >> ; /* Read */ << "Enter expenses"; >> ; /* Calculate as difference of and */ = - ; /* Print */ << ;}} > Type: parsons Hardness: 20 // Calculate payment as cost - discount/rebate # 2006 Sequence.Parsons > "It reads the price of an item and discount, calculates their difference and prints it." {(){ /* Declare */ ; /* Declare */ ; /* Declare */ ; /* Read */ << "Enter price"; >> ; /* Read */ << "Enter discount"; >> ; /* Calculate as difference of and */ = - ; /* Print */ << ;}} > Type: parsons Hardness: 20 // ---------------------------Multiplication------------------------------------------- // DemoParsons # 2010 Sequence.Parsons > "It reads the size of a rectangular room, calculates its area and prints the area." {(){ /* Declare */ ; /* Declare */ ; /* Declare */ ; /* Read */ << "Enter the first dimension"; >> ; /* Read */ << "Enter the second dimension"; >> ; /* Calculate as product of and */ = * ; /* Print */ << ;}} > Type: parsons Hardness: 20 // Pretest // Calculate the interest on a loan # 2011 Sequence.Parsons > "It reads the amount of loan and interest rate, calculates the interest and prints it." {(){ /* Declare */ ; /* Declare */ ; /* Declare */ ; /* Read */ << "Enter principal"; >> ; /* Read */ << "Enter interest rate"; >> ; /* Calculate as product of and */ = * ; /* Print */ << ; }} > Type: parsons Hardness: 20 // Posttest // Input hourly rate, number of hours, compute total pay # 2012 Sequence.Parsons > "It reads the hourly rate and number of hours, calculates the total pay and prints it." {(){ /* Declare */ ; /* Declare */ ; /* Declare */ ; /* Read */ << "Enter hourly rate"; >> ; /* Read */ << "Enter number of hours"; >> ; /* Calculate as product of and */ = * ; /* Print */ << ; }} > Type: parsons Hardness: 20 // Calculation of hypotenuse // ---------------------------Division------------------------------------------- // Calculate the shares bought # 2015 Sequence.Parsons > "It reads the amount invested and cost per share, calculates the number of shares bought and prints it." {(){ /* Declare */ ; /* Declare */ ; /* Declare */ ; /* Read */ << "Enter investment"; >> ; /* Read */ << "Enter price per share"; >> ; /* Calculate by dividing by */ = / ; /* Print */ << ; }} > Type: parsons Hardness: 20 // Calculate velocity as distance divided by time # 2016 Sequence.Parsons > "It reads the distance covered and time spent, calculates the speed and prints it." {(){ /* Declare */ ; /* Declare */ ; /* Declare */ ; /* Read */ << "Enter the distance covered"; >> ; /* Read */ << "Enter the time taken"; >> ; /* Calculate by dividing by */ = / ; /* Print */ << ; }} > Type: parsons Hardness: 20 // Cmputes bmi and prints healthy if bmi less than 25, and not healthy otherwise // mass in pounds, height in inches, bmi = (mass/height) * 703 // 2050 // Sequence.Parsons.Hidden // Input-ComputeHidden-Compute-Output // e.g., mean, stdev // But, No if-else or any other control // ---------------------------Solvelet problems----------------------------- // WARNING: LAST LINE AND ONLY LAST LINE OF INSTRUCTIONS MUST END WITH DOUBLE-QUOTES // --------------------1 input, 1 output problems------------------------- // computing square of a number - works # 4000 Sequence.Solve.Single-Input-Output > "Write a program to read a number, calculate its square and print it." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: number Name: Type: */^^;^ /* Statement: Declare Purpose: square Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: number Format: Read number */ /* Statement: Prompt Purpose: number Format: Enter a number */^^<< "Enter a number";^ /* Statement: Input Purpose: number */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: square BasedOn: product of and */^^ = * ;^ // /* Statement: Compute Purpose: square BasedOn: product of number and number */^^ = * ;^ /** Output Section */ /* Statement: Output Purpose: square Format: Square of 4 is 16 */^^<< "Square 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 // What I had tried to test for loop shell inclusion: // /* Statement: Compute Purpose: square BasedOn: product of number and number */^^for( = ; > ; = - 1){<<;}^ // /* Statement: Compute Purpose: square BasedOn: product of number and number */^^for( = 9; > 5; = - 1){<<;}^ // ---------------------------------- // feet to meters: m = ft / 3.28 - the problem below - works // alternative: meters to feet: ft = m * 3.28 - easier # 4001 Sequence.Solve.Single-Input-Output > "Write a program to read distance (real value) in feet, calculate the equivalent distance in meters (meters = feet / 3.28) and print it." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: feet Name: Type: */^^;^ /* Statement: Declare Purpose: meters Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: feet Format: Read feet */ /* Statement: Prompt Purpose: feet Format: Enter distance in feet */^^<< "Enter distance in feet";^ /* Statement: Input Purpose: feet */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: meters BasedOn: feet divided by 3.28 */^^ = / 3.28;^ /** Output Section */ /* Statement: Output Purpose: meters Format: 30.28 feet = 10 meters */^^<< << " feet = " << << " meters";^ }} > 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 kg = 2.2 pounds - works // alternative: 1 pound = 0.45 kg # 4002 Sequence.Solve.Single-Input-Output > "Write a program to input weight (real value) in pounds, calculate the equivalent weight in kilograms and print it." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: pounds Name: Type: */^^;^ /* Statement: Declare Purpose: kilograms Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: pounds Format: Read weight in pounds */ /* Statement: Prompt Purpose: pounds Format: Enter weight in pounds */^^<< "Enter weight in pounds";^ /* Statement: Input Purpose: pounds */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: kilograms BasedOn: pounds divided by 2.2 */^^ = / 2.2;^ /** Output Section */ /* Statement: Output Purpose: kilograms Format: 22 pounds = 10 kilograms */^^<< << " pounds = " << << " kilograms";^ }} > 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 donuts left over after packing a dozen to a box - works # 4003 Sequence.Solve.Single-Input-Output > "Write a program to input the number of donuts, calculate the number of donuts leftover after packing a dozen donuts in each box, and print it (e.g., given 40 donuts, 4 donuts are left over after packing a dozen donuts in each box)." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: donuts Name: Type: */^^;^ /* Statement: Declare Purpose: leftover Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: donuts Format: Read donuts */ /* Statement: Prompt Purpose: donuts Format: Enter number of donuts */^^<< "Enter number of donuts";^ /* Statement: Input Purpose: donuts */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: leftover BasedOn: donuts modulus 12 */^^ = % 12;^ /** Output Section */ /* Statement: Output Purpose: leftover Format: 4 donuts left over */^^<< << " donuts left over ";^ }} > Type: code Hardness: 15 // Number of input variables * 5 + number of output variables * 5 + number of expression operators * 5 + number of intermediate variables * 10 // ---------------------------------- // celsius to fahrenheit: f = c * 9 / 5 + 32 - works // DANGER - USER MAY USE PARENTHESES // alternative: fahrenheit to celsius: (f - 32) * 5/9: problem areas are parenthesis, integer diviaion issues # 4004 Sequence.Solve.Single-Input-Output > "Write a program to input temperature in celsius, calculate its equivalent in fahrenheit and print it." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: celsius Name: Type: */^^;^ /* Statement: Declare Purpose: fahrenheit Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: celsius Format: Read temperature in celsius */ /* Statement: Prompt Purpose: celsius Format: Enter temperature in celsius */^^<< "Enter temperature in celsius";^ /* Statement: Input Purpose: celsius */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: fahrenheit BasedOn: celsius * 9 / 5 + 32 */^^ = * 9 / 5 + 32;^ /** Output Section */ /* Statement: Output Purpose: fahrenheit Format: 20 celsius = 68 fahrenheit */^^<< << " celsius = " << << " fahrenheit";^ }} > Type: code Hardness: 25 // Number of input variables * 5 + number of output variables * 5 + number of expression operators * 5 + number of intermediate variables * 10 // 1 ounce = 28.35 grams // 1 hp = 745.7 watts // 1 inch = 2.54 cms // 1 psi = 6894.76 pascals // miles to kilometers: km = 1.6 * m // kilometers to miles: m = km / 1.6 - real variables only // ounces to pounds: 16 oz = 1 pound // --------------------more than 1 input or more than 1 output problems------------------------- // ---------------------------------- // computing area of a rectangle - works # 4010 Sequence.Solve.Multiple-Input-Output > "Write a program to read the income and expenses of a household, calculate its savings and print it." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: income Name: Type: */^^;^ /* Statement: Declare Purpose: expenses Name: Type: */^^;^ /* Statement: Declare Purpose: savings Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: income Format: Read income */ /* Statement: Prompt Purpose: income Format: Enter the income */^^<< "Enter the income";^ /* Statement: Input Purpose: income */^^>> ;^ /* Statement: Section Purpose: expenses Format: Read expenses */ /* Statement: Prompt Purpose: expenses Format: Enter the expenses */^^<< "Enter the expenses";^ /* Statement: Input Purpose: expenses */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: savings BasedOn: difference between income and expenses */^^ = - ;^ /** Output Section */ /* Statement: Output Purpose: savings Format: Savings is $ 35.10 */^^<< "Savings is $ " << ;^ }} > Type: code Hardness: 20 // Number of input variables * 5 + number of output variables * 5 + number of expression operators * 5 + number of intermediate variables * 10 // ---------------------------------- // computing area of a rectangle - works # 4011 Sequence.Solve.Multiple-Input-Output > "Write a program to read the length and width of a rectangle, calculate its area and print it." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: length Name: Type: */^^;^ /* Statement: Declare Purpose: width Name: Type: */^^;^ /* Statement: Declare Purpose: area Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: length Format: Read length */ /* Statement: Prompt Purpose: length Format: Enter the length */^^<< "Enter the length";^ /* Statement: Input Purpose: length */^^>> ;^ /* Statement: Section Purpose: width Format: Read width */ /* Statement: Prompt Purpose: width Format: Enter the width */^^<< "Enter the width";^ /* Statement: Input Purpose: width */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: area BasedOn: product of and */^^ = * ;^ /** Output Section */ /* Statement: Output Purpose: area Format: Area is 128 */^^<< "Area is " << ;^ }} > Type: code Hardness: 20 // Number of input variables * 5 + number of output variables * 5 + number of expression operators * 5 + number of intermediate variables * 10 // ---------------------------------- // Given height inches, print it in feet and inches - works // Changed order of inches to 3 so that output statement is properly assembled as feet first, inches next. # 4012 Sequence.Solve.Multiple-Input-Output > "Write a program to read the height of a person in inches, calculate it in feet and inches and print it." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: height Name: Type: */^^;^ /* Statement: Declare Purpose: feet Name: Type: */^^;^ /* Statement: Declare Purpose: inches Name: Type: */^^;^ /** Input Section */ /* Statement: Section Purpose: height Format: Read height */ /* Statement: Prompt Purpose: height Format: Enter height in inches */^^<< "Enter height in inches";^ /* Statement: Input Purpose: height */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: feet BasedOn: height divided by 12 */^^ = / 12;^ /* Statement: Compute Purpose: inches BasedOn: height modulus 12 */^^ = % 12;^ /** Output Section */ /* Statement: Output Purpose: feet Format: Height of 75 inches = 6 feet */^^<< "Height of " << << " inches = " << << " feet";^ /* Statement: Output Purpose: inches Format: 3 inches */^^<< << " inches";^ }} > Type: code Hardness: 25 // Number of input variables * 5 + number of output variables * 5 + number of expression operators * 5 + number of intermediate variables * 10 // savings = income - expenses // pay = hourlyRate * numHours // shares bought = investment / costPerShare // change = quarters * 25 + dime * 10 + nickels * 5 + pennies // leftover players = numPlayers % teams // ------------------------------EXPERIMENTAL SECTION - DO NOT DEPLOY WITHOUT TESTING--------------------------------------------- // DO NOT USE THIS VERSION - USE 4001 # 4100 Sequence.Solve > "Write a program to manage loans for a bank. It will ask the user for the principal, interest rate and duration of a loan. It will calculate and print the interest on the loan." {(){ /* Variable Declaration Section */ /* Declare */ ; /* Declare */ ; /* Declare */ ; /* Declare */ ; /* Input Section */ << "Enter the principal"; >> ; << "Enter the interest rate"; >> ; << "Enter the duration"; >> ; /* Compute Section */ /* Calculate by multiplying by and */ = * * ; /* Output Section */ /* Print */ << ; }} > Type: solve Hardness: 20 // VERSION OF 4000 WITH CLOZE SYNTAX FOR CODE # 4101 Sequence.Solve > "Write a program to manage loans for a bank. It will ask the user for the principal, interest rate and duration of a loan. It will calculate and print the interest on the loan." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: principal Name: Type: real */^^;^ /* Statement: Declare Purpose: rate Name: Type: real */^^;^ /* Statement: Declare Purpose: duration Name: Type: int */^^;^ /* Statement: Declare Purpose: interest Name: Type: real */^^;^ /** Input Section */ /* Statement: Section Purpose: principal Format: Read principal */ /* Statement: Prompt Purpose: principal Format: Enter the principal */^^<< "Enter the principal";^ /* Statement: Input Purpose: principal */^^>> ;^ /* Statement: Section Purpose: rate Format: Read interest rate */ /* Statement: Prompt Purpose: rate Format: Enter the interest rate */^^<< "Enter the interest rate";^ /* Statement: Input Purpose: rate */^^>> ;^ /* Statement: Section Purpose: duration Format: Read duration */ /* Statement: Prompt Purpose: duration Format: Enter the duration */^^<< "Enter the duration";^ /* Statement: Input Purpose: duration */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: interest BasedOn: product of principal, rate and duration */^^ = * * ;^ /** Output Section */ /* Statement: Output Purpose: interest Format: interest */^^<< ;^ }} > Type: code Hardness: 20 // /* Statement: Section Purpose: interest Format: interest */ // Not a particularly interesting problem # 4103 Sequence.Solve > "Write a program to read a number, calculate the sum of all the numbers from 1 up to it and print it." {(){ /** Variable Declaration Section */ /* Statement: Declare Purpose: number Name: Type: int */^^;^ /* Statement: Declare Purpose: sum Name: Type: int */^^;^ /** Input Section */ /* Statement: Section Purpose: number Format: Read number */ /* Statement: Prompt Purpose: number Format: Enter a number */^^<< "Enter a number";^ /* Statement: Input Purpose: number */^^>> ;^ /** Compute Section */ /* Statement: Compute Purpose: sum BasedOn: number * (number + 1) / 2 */^^ = * ( + 1) / 2;^ /** Output Section */ /* Statement: Output Purpose: sum Format: sum */^^<< ;^ }} > Type: code Hardness: 10 // ---------------------------Demo Problem------------------------------------------- // Problem to help students practice with the user interface # 2999 Demonstration > "It prints Alpha, Bravo and Charlie." {(){ /* Prints A */ << "Alpha"; /* Prints B */ << "Bravo"; /* Prints C */ << "Charlie"; }} > Type: parsons Hardness: 20