Upload
ngoxuyen
View
222
Download
0
Embed Size (px)
Citation preview
Practical Challenges in Programming
Workbook and Tracker
King Edward VI SchoolStratford-upon-Avon
Name: ….......................................................... Form:.................
Programming Tracker
Program Focus De
sig
ne
d
Co
de
d
Test
ed
Pyt
ho
n
VB
.Ne
t C
on
so
le
VB
.Ne
t G
UI
Java
Java
scri
pt
Oth
er
1. Hello World Sequence
2. Hello User Sequence
3. AreaCalc Sequence, simple maths
4. PerimeterCalc Sequence, simple maths
5. Bigger and Bigger Selection
6. Form Chooser Selection
7. VAT Calculator Sequence, simple maths
8. Vol and Surface Calc Sequence, simple maths
9. Mini-Calc Selection, simple maths
10. Cafe Adder Selection, simple maths
11, Five-A-Day Iteration
12. Countdown Iteration
13. Times-tabler Iteration
14. Squares and Cubes Iteration, simple maths
15. Fibonacci Iteration, moderate maths
16. FizzBuzz Iteration, moderate maths
17. Reversal Arrays
18. Bingo Bingo Arrays
19. Sort it Out! Arrays
20. Student Average Arrays, simple maths
21. Username Strings
22. Back to Front Strings
23. Word Count Strings
24. Palindromes Strings
25. Vowel Counter Strings, arrays
26. Anagrams Strings, arrays
27. Code Words 1 Strings
28. Code Words 2 Strings
29. Decoder Strings
30. Initialise Strings
31. Registration File handling
32. New Boy File handling
33. New Class File handling
34. Fullnames Needed File handling
35. Child Finder File handling
36. Off Roll File handling
37. All-in-one File handling
38. Mythological Beasts File handling
39. Thesaurus File handling
40. The Rehash Copout File handling
41. Wordsearch Searching and Sorting
42. Wordsearch 2 Searching and Sorting
43. Proof of the Pudding Searching and Sorting
44. Searching and Sorting
45. Searching and Sorting
46. Searching and Sorting
2
47. Searching and Sorting
48. Searching and Sorting
49. Searching and Sorting
50. Searching and Sorting
51. Carpet Quoter Complete Algorithms
52. Ker-Ching Complete Algorithms
53. Tax Calculator Complete Algorithms
54. Painter Quoter Complete Algorithms
55. Thief! Complete Algorithms
56. Treasure Hunt Complete Algorithms
57. Password Reset Complete Algorithms
58. Fruity Complete Algorithms
59. Contagion Complete Algorithms
60. Classification Complete Algorithms
61. Vending Machine Simulation Complete Algorithms
62. Noughts and Crosses Complete Algorithms
63. Hi-Q Haiku Complete Algorithms
64. Connectron Complete Algorithms
65. Snake Eyes Complete Algorithms
66. Simon Complete Algorithms
67. Battleships Complete Algorithms
68. Where’s Shakey Complete Algorithms
69. Dungeon Crawler Complete Algorithms
70. Over To You... Complete Algorithms
3
Contents
Practical Challenges Part 1: Sequence and Selection1. Hello World2. Hello User3. AreaCalc4. PerimeterCalc5. Bigger and Bigger6. Form Chooser7. VAT Calculator8. Volume and Surface Calculator9. Mini-Calc10. Cafe AdderProgramming Showcase Briefing
Practical Challenges Part 2: Iteration and Arrays11. Five-A-Day12. Countdown13. Times-tabler14. Squares and Cubes15. Fibonacci16. FizzBuzz17. Reversal18. Bingo Bingo19. Sort it Out!20. Student AverageProgramming Showcase Briefing
Practical Challenges Part 3: Strings and Things21. Username22. Back to Front23. Word Count24. Palindromes25. Vowel Counter26. Anagrams27. Code Words 128. Code Words 229. Initialise30. DecoderProgramming Showcase Briefing
4
Practical Challenges Part 4: File Handling31. Registration32. New Boy33. New Class34. Fullnames Needed35. Child Finder36. Off Roll37. All-in-one38. Mythological Beasts39. Thesaurus40. The Rehash CopoutProgramming Showcase Briefing
Practical Challenges Part 5: Sorting and Searching41. Wordsearch42. Wordsearch 243. Proof of the Pudding44.45.46.47.48.49.50.
Practical Challenges Part 6: The Big Ones51. Carpet Quoter52. Ker-Ching!53. Tax Calculator54. Painter Quoter55. Thief!56. Treasure Hunt57. Password Reset58. Fruity59. Contagion60. Classification61. Vending Machine Simulation62. Noughts and Crosses63. Hi-Q Haiku64. Connectron65. Snake Eyes66. Simon67. Battleships68. Where’s Shakey?69. Dungeon Crawler70. Over to you...
5
Note to teachers
This booklet covers most of the key practical techniques and skills required for both GCSE and AS level.
The tasks have been adapted from a wide variety of sources and were originally written to help students learn the VB.Net language in preparation for OCR GCSE and AS level courses. The current version aims to be reasonably language agnostic. Students are encouraged to think, plan and design before developing their solutions and to test and evaluate afterwards. A number of theory questions and tasks are incorporated into the booklet, as well as opportunities to present Showcases, which may be used for formal assessment or as preparation for Controlled Assessment tasks. Students may use the tracker and target sheets on the inside covers to assess their progress and inform their next choice of task.
The tasks in each section are presented roughly in order of complexity/difficulty and cover the following key aspects of designing and creating a programmed solution to a problem:
VariablesConstantsDatatypesArraysLoopsConditions/SelectionString manipulation
The final section gives some suggestions for slightly longer programs, with the student expected to become increasingly independent and able to plan, design and create their programs with minimal supervision. Many of the final programs can be extended or turned into full games/apps.
Additional sections covering file handling, modules, recursion and graphics will be added to a future version.
Corrections, comments and suggestions for improvements are always welcomed via the CAS forums.
Please feel free to adapt and distribute the contents of this booklet as you see fit for non-commercial purposes. Some tasks have been adapted from BIO and exam board past papers. Please do get in touch if you feel your copyright has been infringed through the use of the adaptations and the items will be removed.
Richard [email protected]
This document is placed into the public domain under a Creative Commons license: Attribution-NonCommercial-ShareAlike 4.0 International
http://creativecommons.org/licenses/by-nc-sa/4.0/
6
Note to Students
The challenges in this booklet have been put together to help you plan, design, create and then test a range ofprograms. When you start your programming journey, experience and practice are absolutely vital. Knowing when and how to use certain features of a programming language, such as conditions and loops, are often difficult at first. Thinking about your program BEFORE you create any code is highly recommended, and indeed, vital at GCSE and AS/A2 Level for the higher grades. You can use the grids on the inside covers to help monitor your progress and track the programming skills you have begun to master.
BEFORE creating a program you should:• Identify the Inputs, Processing and Outputs• Identify key variables and other data structures• Design a labelled interface (for non-console apps)• Think about the steps the program should execute (using flowcharts and/or pseudocode)• Draw up a test plan
After you have created your program, it should be thoroughly tested using a test plan that covers valid, invalid and extreme data. Only when all of the challenge is complete should you mark it off on your tracker grids.
The challenges were originally written with the VB.Net language in mind. The wording of some of the written questions may not be 100% familiar to users of other languages, although similar features and concepts will be available in their language of choice.
I->P->O DiagramThis simple diagram helps you focus on what goes into the program and what should come out. Inputs and Outputs should be stated as clearly and accurately as possible and should help you start to think about the variables needed for the program. The processing may be expressed simply at this stage.
Examples:
Variables and Other Data StructureNearly all programs will need to store and manipulate data in some way. You should work out the main requirements before you create the program. Think about the structures needed to store the inputs and outputs of the program. Think about the actual processing involved – does it need to be done in stages and if so, what extra data structures are needed? Would an array or list be appropriate?
BEFORE creating a program, you should think about the following for each data structure needed: name; datatype; typical value; minimum/maximum values (validation).Flowcharts and PseudocodeDrawing a flowchart or diagram should help you think about the various stages needed in the program: What are they? In what order should they be executed (sequence)? Which sections involve making decisions (selection)? Which sections involve repeating instructions (iteration)?
Pseudocode should help you get to grips with the hardest part of the program: the processing. How exactly are7
width of rectangle
length of rectangle
area=width * length area of rectangle
price of item
payment made
change=payment - price
Calculate coins to return
Number and type of
each coin to return as change
you going to turn those inputs into the expected outputs? What needs to be done? Is it a mathematical formula? Do you need to manipulate strings?
A good piece of pseudocode focuses on the logic and helps solve the difficult parts of the problem so that when you come to actually writing your code, most of the thinking has already been done. Good pseudocode will also help you work out where you might go wrong or what problems/traps might lay in store (eg what happens if an input is left blank?)
Avoid Pointless Pseudocode
Input number1Input number2Input number3 Version 1 doesn't really help...Input number4Input number5Output average
Input 5 numbersaverage=(sum of the five numbers) / 5 Although shorter, Version 2 is a bit more helpfulOutput average
numberOfItems=5total=0 In Version3, nearly all the “thinking” has been doneaverage=0for c=1 to numberOfItems
Output “Please enter a number”Input numbertotal=total+number
nextaverage=total / numberOfItemsOutput “The average is “ & average
Test PlanHow will you know if your program works correctly? How will you know what crashes/kills your program?
Create a test plan BEFORE you write the code. You should be able to predict the output created by a set of inputs. Try to design tests that cover valid, invalid and extreme inputs. A good test will highlight a problem/bug; there's no point in 10 “it works ok” tests.
In some of the challenges, a few starting tests have been given but feel free to add more!
8
Part 1: Sequence and Selection
1. Hello WorldDesign and implement a program that displays the message “Hello World” when a button is pressed
Pseudocode:
….........................................................................................................................................................
............................................................................................................................................................
Explain these terms:
Form:.....................................................................................................................................
Control:..................................................................................................................................
Button:...................................................................................................................................
Label:.....................................................................................................................................
Event:.....................................................................................................................................
Implement your program!
TestingHow do you know whether your program works?
9
X
2. Hello UserDesign and implement a program that allows the user to enter his/her name. When a button is clicked, the program displays “Hello user”, where user is the name entered.
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Pseudocode:
….........................................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
Explain these terms:
Textbox:...............................................................................................................................................
Property:..................................................................................................................................
String:..................................................................................................................................................
Concatenation:....................................................................................................................................
Implement your program!What is the difference between the Name property of an object/control and its Text property?
….......................................................................................................................................................
…....................................................................................................................................................…
3. AreaCalcDesign and implement a program that allows the user to enter 2 numbers representing the width and length of a rectangle. The program calculates and displays the area of the rectangle.
10
X
Flowchart/Pseudocode
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Input Expected Output Actual Output Comments
2, 3
100, 100
4.2, 1.8
1m, 3
Implement your program!What is the difference between an integer and a real number?
….........................................................................................................................................................
TestingUse the table above to identify any issues with your program
11
X
4. PerimeterCalcDesign and implement a program that allows the user to enter 2 numbers representing the width and length of a rectangle. The program calculates and displays the perimeter of the rectangle.
Flowchart/Pseudocode
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Input Expected Output Actual Output Comments
2, 3
100, 100
4.2, 1.8
1m, 3
1, 3m
Implement your program!
TestingUse the table above to identify any issues with your programWhat is the purpose of the 4th and 5th tests in the test plan?
….........................................................................................................................................................
12
X
5. Bigger and BiggerDesign and implement a program that allows the user to enter 3 numbers in any order. The program displays the largest number.
Flowchart/Pseudocode
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Input Expected Output Actual Output Comments
2, 9, 3
100, 4, 47
4.2, 1.8, 5
1, 0, -1
5, 8, 5
Implement your program!
TestingUse the table above to identify any issues with your program
What is the purpose of the 5th test in the test plan?
….........................................................................................................................................................
13
X
6. Form ChooserDesign and implement a program that allows the user to enter his/her name and form. When a button is clicked, the program greets the user by name and tells him/her which room to go to for registration.
Eg Inputs: Ben, 9TOutput: Hello Ben, please go to Room 16
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
14
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines. Include valid and invalid data.
Input Expected Output Actual Output Comments
Explain these terms:
Selection:............................................................................................................................................
Alternative Route:................................................................................................................................
Error Checking:....................................................................................................................................
Valid data:............................................................................................................................................
Invalid data:............................................................................................................................................
Validation:............................................................................................................................................
Implement your program!
Hint:You may choose to use If...Then...End If statementsYou may choose to use a Select...Case...End Select statement
add a printout of your code here
15
7. VAT CalculatorDesign and implement a program that allows the user to enter the price of an item. The program calculates theamount of VAT to be paid at 20%. The VAT amount and total price are then displayed.
Flowchart
Pseudocode............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
.........................................................................................…
.........................................................................................…
............................................................................................
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
16
X
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Input Expected Outputs Actual Outputs Comments
0.50
50.00
35.75
£10.00
Ten pounds
Explain these terms:
Variable:............................................................................................................................................
Initialise:............................................................................................................................................
Constant:............................................................................................................................................
Integer:..............................................................................................................................................
Floating Point:...................................................................................................................................
Double:..............................................................................................................................................
Implement your program!
Hint: You may need to use val() to get the value of the price entered
add a printout of your code here
17
8. Volume and Surface CalcDesign and implement a program that allows the user to enter 3 numbers representing the height, width and length of a cuboid. The program calculates and displays the volume and total surface area of the cuboid.
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
18
X
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Input Expected Outputs Actual Outputs Comments
2, 2, 2
3, 3, 3
2.5, 3, 4
4, 6, 8
4, 8, 8
3, 0, 3
Implement your program!
TestingUse the table above to identify any issues with your program
What is the purpose of the 3th and 6th tests in the test plan?
….........................................................................................................................................................
….........................................................................................................................................................
add a printout of your code here
19
9. Mini-CalcDesign and implement a program that allows the user to enter 2 numbers and choose a mathematical operation (+ - * /). The program calculates the result and displays the answer as a full equation (eg the user enters 4 and 10 and chooses +. The program displays 4 + 10 = 14
NB: the interface does NOT have to look like a calculator!
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
20
X
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
4, 10, +
4, 10, -
4, 10, *
40, 10, /
25.5, 5, /
100000, 10000, *
10,0, /
10, , +
Ten, 4, +
Implement your program!
Hint:You may need to use val() to get the value of the numbers enteredYou may choose to use a drop-down list for the 4 mathematical operations.
TestingUse the table above to identify any issues with your program
Why do the first 4 tests use the same numbers?
….........................................................................................................................................................
What is the purpose of the 6th test in the test plan?
….........................................................................................................................................................
add a printout of your code here
21
10. Café AdderDesign and implement a program that allows the user to create the bill for a café. The user can enter the nameand price for up to 5 items and how many were ordered. If the order is to take-out, 20% VAT is added. If the customer is a pensioner, a 10% discount is applied. The program displays an appropriate bill/receipt..
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
.........................................................................................…
............................................................................................
22
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
Coffee, £2, 2Cake £1.50, 2
Coffee, £2, 2Cake £1.50, 2,Take-out
Coffee, £2, 2Cake £1.50, 2,Pensioner
Implement your program!
Hint:It is very easy to over-complicate this one. Don't!You could choose drop-down boxes to limit the variety of items and their pricesYou might choose to use check-boxes for Take-Away and Pensioner inputsYou might choose to use an array or you might not!
TestingUse the table above to identify any issues with your program
The test data has values such as “£2” and “£1.50”? Why are these not correct in reality?
….........................................................................................................................................................
23
Programming Showcase
A Programming Showcase is a formal document showing how you progressed through all of the stages in the development process. It will use some of the design, development and testing work you have completed in thisbooklet as well as a detailed narrative of what you did at each stage, and, more importantly, why and how youdid it. It will also include a full evaluation of the final version of your program and incorporate feedback and thoughts from other people (eg members of your class).
The showcase will be marked using the exam board's guidelines for Controlled Assessment or Coursework Projects.
The Showcase should cover the following main points:
AimDescription of program's main purposes(s). You could paraphrase the task's instructions.
Design and PlanningI->P->O diagramFlowchartPseudocodeVariables/data structures needed (and validation)For the highest grades, remember to discuss why you are using a particular approach
Test PlanDetailed testing strategy – how will you know if your program works?Detailed testing table – what data will you use to test your program?Valid, invalid and extreme data
DevelopmentAnnotated screenshots showing stages of developmentDiscussion of any problems you encountered and how you fixed them (or didn't!)Explicit, detailed discussion of changes made to your code following alpha testingFull code listing for the final program, commented, indented, using ssensible variable names etc
TestingCompleted test plan with appropriate comments and evidence (screenshots?)
EvaluationDiscuss good/bad aspectsFeedback from othersSuggestions for further improvementNote how the following evaluation paragraphs each cover a Fact, an Opinion and an Improvement (F->O->I)
The interface for the program uses drop-down lists so the user can choose the items bought.This is good because it prevents the user from entering invalid spellings or non-existent items. When the program first loads up, the drop-down lists always shows “coffee”. I could set them to be blank so the user doesn't have to change them to blank if fewer than 5 items are bought.
The program correctly works out the student's average score in most cases. However, the maximum score for each test is supposed to be 20 and it is possible to enter higher scores than this. I could add some error-handling to prevent the user from entering invalid numbers,
eg:repeat
input scoreuntil score>-1 and score<21
24
25
Part 2: Iteration and Arrays11. Five-A-DayDesign and implement a program that allows the user to enter a positive number. The program displays all of the numbers divisible by 5 up to the number entered. Eg the user enters 30, the program displays 5, 10, 15, 20, 25, 30
Flowchart/Pseudocode
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Input Expected Output Actual Output Comments
30
100000
86
0
-27
Implement your program!
TestingUse the table above to identify any issues with your programWhat is the purpose of the 4th and 5th tests in the test plan?
….........................................................................................................................................................
26
X
12. Countdown!Design and implement a program that allows the user to enter a positive number. The program displays a countdown from the number to 0. Eg the user enters 10 and the program displays 10, 9, 8, 7, 6, 5 4, 3, 2, 1, 0
Flowchart/Pseudocode
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Input Expected Output Actual Output Comments
10
100
1000000
0
-5
Implement your program!
TestingUse the table above to identify any issues with your program
What is the purpose of the 5th test in the test plan?
….........................................................................................................................................................
27
X
13. Times-TablerDesign and write a program that allows the user to choose a number (1-12). The program displays the times-table for the chosen number
Flowchart/Pseudocode
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Input Expected Output Actual Output Comments
10
7
19
0
-5
Implement your program!
TestingUse the table above to identify any issues with your programWhat is the purpose of the 3rd, 4th and 5th tests in the test plan?
….........................................................................................................................................................
28
X
14. Squares and CubesThe squared number sequence starts: 1, 4, 9, 16, 25. The cubed number sequence starts: 1, 8, 27, 64. Designand write a program to display N numbers in the squared or cubed sequence according to user choice.
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
29
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
squared, 5
cubed, 5
squared, 10
cubed, 10
Implement your program!
TestingUse the table above to identify any issues with your program
add a printout of your code here
30
15. FibonacciThe first few numbers in the Fibonacci sequence are: 0, 1, 1, 2, 3, 5, 8, 13, 21 … Design and write a program to display N Fibonacci numbers, where N is entered by the user
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
31
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
3
7
9
0
Implement your program!
TestingUse the table above to identify any issues with your program
Explain these terms:
Iteration:........................................................................................................................................................
Loop:.............................................................................................................................................................
Stopping Condition:.......................................................................................................................................
What is the difference between a FOR...NEXT loop and a REPEAT....UNTIL loop?
…...................................................................................................................................................................
What is the difference between a FOR...NEXT loop and a WHILE....DO loop?
…...................................................................................................................................................................
What is the difference between a REPEAT...UNTIL loop and a REPEAT....UNTIL loop?
…...................................................................................................................................................................
32
16. FizzBuzzWrite a program to print out the numbers 1-n, where n is entered by the user. However, if a number is divisible by 3 (3, 6, 9 etc), it is replaced by “FIZZ!”. If a number is divisible by 5 (5, 10 etc) it is replaced by “BUZZ!” If a number is divisible by 3 and 5, it is replaced by “FIZZBUZZ!”
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
33
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
12
36
100
0
ten
Implement your program!
Hint:It is very easy to over-complicate this one. Don't!Be careful with your interface – if there are 20 test scores to enter, do you really want 20 textboxes?Do you want to use an array? Really?Do you want to use iteration? A FOR...NEXT loop? A REPEAT...UNTIL loop? Really?
TestingUse the table above to identify any issues with your program
What is the purpose of the 4th and 5th tests?
….........................................................................................................................................................
add a printout of your code here
34
17. ReversalWrite a program that allows the user to enter 5 numbers. The numbers are then displayed in reverse order.
Flowchart/Pseudocode
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Input Expected Output Actual Output Comments
5, 10, 12, 3, 9
Implement your program!
TestingUse the table above to identify any issues with your program
Explain these terms:
Array:......................................................................................................................................................
Datatype:................................................................................................................................................
Index:......................................................................................................................................................
35
X
18. Bingo BingoWrite a program that allows the user to enter the Bingo Call for any number 1-90. The user can choose to haveall the calls displayed. Eg 1: Kelly's eye 22: two little ducks etc
Flowchart/Pseudocode
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Input Expected Actual Output Comments
1: Kelly's eye 22: two little ducks
Implement your program!
Hint:You might want to make your program skip any numbers that haven't had a Bingo Call entered
TestingUse the table above to identify any issues with your program
36
X
19. Sort It Out!Write a program that allows the user to enter 5 words. The words are sorted and displayed in alphabetical order.
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
37
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
and, but, car, egg, dust
dust, egg, car, and,but
egg, dust, car, but, and
and, able, but, bit, bat
and, but, car, car, dust
Implement your program!
Hint:It is very easy to over-complicate this one. Don't!Be careful with your interface – there are up to 30 test scores to enter, do you really want 30+ textboxes?Do you want to use more than one array? Do you want to use iteration? A FOR...NEXT loop? A REPEAT...UNTIL loop?
TestingUse the table above to identify any issues with your program
38
20. Student AverageDesign and implement a program that allows the user to enter the names of up to 10 students and the scores for each of the 3 tests they have taken (out of 20). The user can then enter a student number (1-10) and the program displays his/her name, test scores and average score.
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
39
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
Implement your program!
Hint:It is very easy to over-complicate this one. Don't!Be careful with your interface – there are up to 30 test scores to enter, do you really want 30+ textboxes?Do you need to use more than one array? Do you want to use iteration? A FOR...NEXT loop? A REPEAT...UNTIL loop?
TestingUse the table above to identify any issues with your program
40
Programming Showcase
A Programming Showcase is a formal document showing how you progressed through all of the stages in the development process. It will use some of the design, development and testing work you have completed in thisbooklet as well as a detailed narrative of what you did at each stage, and, more importantly, why and how youdid it. It will also include a full evaluation of the final version of your program and incorporate feedback and thoughts from other people (eg members of your class).
The showcase will be marked using the exam board's guidelines for Controlled Assessment or Coursework Projects.
The Showcase should cover the following main points:
AimDescription of program's main purposes(s). You could paraphrase the task's instructions.
Design and PlanningI->P->O diagramFlowchartPseudocodeVariables/data structures needed (and validation)For the highest grades, remember to discuss why you are using a particular approach
Test PlanDetailed testing strategy – how will you know if your program works?Detailed testing table – what data will you use to test your program?Valid, invalid and extreme data
DevelopmentAnnotated screenshots showing stages of developmentDiscussion of any problems you encountered and how you fixed them (or didn't!)Explicit, detailed discussion of changes made to your code following alpha testingFull code listing for the final programCode should be commented, indented, use sensible variable names etc
TestingCompleted test plan with appropriate comments and evidence (screenshots?)
EvaluationDiscuss good/bad aspectsFeedback from othersSuggestions for further improvementNote how the following evaluation paragraphs each cover a Fact, an Opinion and an Improvement (F->O->I)
The interface for the program uses drop-down lists so the user can choose the items bought.This is good because it prevents the user from entering invalid spellings or non-existent items. When the program first loads up, the drop-down list is blank. I could improve this be setting it to show a common item, such as coffee.
The program correctly works out the student's average score in most cases. However, the maximum score for each test is supposed to be 20 and it is possible to enter higher scores than this. I could add some error-handling to prevent the user from entering invalid numbers,
eg:repeat
input scoreuntil score>-1 and score<21
41
42
Part 3: String and Things21. UsernameWrite a program that inputs the user's first name and surname. It then generates and prints a username following the convention SURNAME.INITIAL
eg entering “John” and “Smith” gives the username “Smith.J”
Flowchart/Pseudocode
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................Variables and Other Data Structures
Name Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs ExpectedOutput
Actual Outputs Comments
Alan Jones
Mark Freeman
Andy Barnes-Nobles
Frank
(blank)
Implement your program!
TestingUse the table above to identify any issues with your program
43
X
22. Back to FrontDesign and write a program that reverses a piece of text entered by the user.
Flowchart/Pseudocode
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
computing
Is cool
Implement your program!
TestingUse the table above to identify any issues with your program
44
X
23. Word CountDesign and write a program that counts the number of words in a passage of text entered by the user.
Flowchart/Pseudocode
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
…..............................................................
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
Try this first
Now try this one.
And finally. Now forsomething, completely, different!
Implement your program!
Hint:What is a word? Are you always “out by one”?
TestingUse the table above to identify any issues with your program
45
X
24. PalindromesA palindrome is a word or phrase that is exactly the same when written forwards or backwards. Eg “noon”, “Dammit I'm mad!” (if you ignore the punctuation). Design and write a program that ascertains whether a word or phrase entered by the user is a palindrome.
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
46
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
noon
kayak
dammit im mad
Dammit! I'm mad!
As I pee, sir, I see Pisa!
Implement your program!
TestingUse the table above to identify any issues with your program
What is the purpose of the 4th test in the test plan?
….........................................................................................................................................................
add a printout of your code here
47
25. Vowel CounterDesign and write a program that counts the number of each vowel in a passage of text entered by the user. Egthe user enters “Computing is cool” and the program displays: a – 0, e – 0, i – 2, o – 3, u – 1
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
48
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
Computing is cool
Implement your program!
Hint:Could you use an array to cut down on the amount of code?
TestingUse the table above to identify any issues with your program
add a printout of your code here
49
26. AnagramsA word is an anagram of another word if it contains exactly the same letters, but in a different order. Design and create a program that ascertains whether 2 words are anagrams of each other. Eg “reap” is an anagram of “pear”, but not “peer”.
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
50
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
pear, reap
was, saw
saw, sore
thin, hints
maxi, maxim
Implement your program!
TestingUse the table above to identify any issues with your program
add a printout of your code here
51
27. Codewords 1In a simple substitution code, the letter A is replaced by the number 1, B by the number 2 etc.Design and write a program that allows the user to enter a short sentence, which is then encoded and displayed using the substitution rules.
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
52
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
COMPUTING
IS COOL
TRU3
dat
Implement your program!
Hint:Do you know about ASCII?
TestingUse the table above to identify any issues with your program
add a printout of your code here
53
28. CodeWords 2Write a program that converts any entered word into a codeword using these rules:
• “egg” is inserted into the mid-point of any word of even-numbered length -eg “good” becomes “goeggod”
• “ga” is inserted either side of the mid-point of any word of odd numbered lengtheg “puppy” becomes “pugapgapy”
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
54
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
good
puppy
Implement your program!
TestingUse the table above to identify any issues with your program
add a printout of your code here
55
29. InitialiseDesign and write a program that allows the user to enter a lengthy piece of text. The initial letter of each word is extracted and displayed in the hope of finding a secret message.Eg the user enters Today Harry indicated sadly “I shall frequently undergo nightmares” and the program displays “thisisfun”
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
56
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
Begin untying Malcolm soon
Today Harry indicated sadly “I shall frequently undergo nightmares”
Implement your program!
TestingUse the table above to identify any issues with your program
add a printout of your code here
57
30. DecoderDesign and write a program that decodes a message created using the program from Challenge 28: Code Words 2. The program should strip out any added “egg”s and “ga”s
Eg goeggod is turned back into goodGaaga goeggod pugapgapy is turned back into a good puppy
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
58
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
goeggod
pugapgapy
Gaaga goeggod pugapgapy
Implement your program!
TestingUse the table above to identify any issues with your program
add a printout of your code here
59
Programming Showcase
A Programming Showcase is a formal document showing how you progressed through all of the stages in the development process. It will use some of the design, development and testing work you have completed in thisbooklet as well as a detailed narrative of what you did at each stage, and, more importantly, why and how youdid it. It will also include a full evaluation of the final version of your program and incorporate feedback and thoughts from other people (eg members of your class).
The showcase will be marked using the exam board's guidelines for Controlled Assessment or Coursework Projects.
The Showcase should cover the following main points:
AimDescription of program's main purposes(s). You could paraphrase the task's instructions.
Design and PlanningI->P->O diagramFlowchartPseudocodeVariables/data structures needed (and validation)For the highest grades, remember to discuss why you are using a particular approach
Test PlanDetailed testing strategy – how will you know if your program works?Detailed testing table – what data will you use to test your program?Valid, invalid and extreme data
DevelopmentAnnotated screenshots showing stages of developmentDiscussion of any problems you encountered and how you fixed them (or didn't!)Explicit, detailed discussion of changes made to your code following alpha testingFull code listing for the final programCode should be commented, indented, use sensible variable names etc
TestingCompleted test plan with appropriate comments and evidence (screenshots?)
EvaluationDiscuss good/bad aspectsFeedback from othersSuggestions for further improvementNote how the following evaluation paragraphs each cover a Fact, an Opinion and an Improvement (F->O->I)
The interface for the program uses drop-down lists so the user can choose the items bought. This is good because it prevents the user from entering invalid spellings or non-existent items. When the program first loads up, the drop-down list is blank. I could improve this be setting it to show a common item, such as coffee.
The program correctly works out the student's average score in most cases. However, the maximum score for each test is supposed to be 20 and it is possible to enter higher scores than this. I could add some error-handling to prevent the user from entering invalid numbers,
eg:repeat
input scoreuntil score>-1 and score<21
60
61
Part 4: File HandlingLearning how to permanently store data is an important skill. However, it can be a little complex, especially on a network.
The basic process is:Open a file (in the correct MODE)Read one line at a timeDo some stuff with the data you have just readClose the file
A file has to be opened in one of the following MODES:Read-only (you can read the data, but not change it)Append (you can read the file and add data. All new data will be added to the end of the file)Write (you can read and write to the file. Any new data will OVERWRITE any existing data)
Whenever you open a file, the operating system and your program does not really have an easy way to know how long the file is or how much data is in it. Ideally, you should also check whether the file actually exists!
Therefore, it is very common to use the following method to open and then iterate through the file without trying to go past the end of the data:
If file existsOpen fileWhile NOT End of File
Read one lineDo some stuff
LoopClose File
ElsePrint “File not found”
End if
The content of files cannot magically sorted into order and basic files have to be accessed “in-order”, ie starting from the first item and working through the file one line at a time. Think carefully about howyou organise the data you want to store and how you will be able to extract the parts you want later on. Simplicity is the key!
This section of the book covers the following basic operations:Reading from a fileSearching for an item in a fileAdding (appending) to the end of a fileCreating a new fileInserting into a file
62
Challenges 31 – 35 need the following text file created FIRST!
Use a text editor (eg Notepad) to create a text file asin Screenshot 1.
It must be saved as “names.txt”.
It must then be copied into the same folder as the executable (binary) file created by your IDE as inScreenshot 2.
This means that, for the moment, you do not have toworry with providing full file-paths in your code. The executable will look in its own folder for the text file needed.
For each challenge, start with a fresh copy of the text file you have just created.
63
Screenshot 1The list of names
Screenshot 2Executable file (Registration.exe) andtext file (names.txt) in the same folder
31. RegistrationDesign and write a program that opens, reads and displays the text file “names.txt”. Remember that the program won't know in advance how many names are in the text file. If you are using a GUI, think carefully about which control you will use – a fixed amount of text boxes is not really good enough!
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
64
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanHow will you know if your program works?
…..................................................................................................................................................................
Implement your program!
Hint:It is very easy to over-complicate this one. Don't!
Open the fileRead and display one line at a timeClose the file
TestingTest your program. Does it work?
Add another name to the text file using a text editor. Does your program still display all the names in the file?
Delete a couple of names from the text file. Does your program still display the full list?
ExtensionCreate group1.txt, group2.txt and group3.txt files containing different sets of names.
Add a feature to your program that allows the user to choose which file to display.
Think about the advantages of disadvantages of each of the following methods of choosing the file:
a. A text box where the user can type in any filenameb. A drop down menu with the 3 text files already listedc. A file-picker control
65
32. New BoyYou will need the text file “names.txt” from Challenge 31.
Design and create a program that allows a teacher to enter the name of a new student. The name is added to the end of the “names.txt” file (append). The file is then displayed in full.
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
66
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
ZebedeeAttwood, Barnes, Campbell, Derry, Jennings, Spender, Vaughan, Zebedee
Ashton ,Attwood, Barnes, Campbell, Derry, Jennings, Spender, Vaughan, Zebedee,Ashton
Implement your program!
Hint:Get the input firstOpen the file in append mode and write the new name to the file. Close the file.Re-open the file (this will set the data pointer back to the first line of the file)Read and display the file one line at a timeClose the file
TestingUse the table above to identify any issues with your program
67
33. New ClassIt's the start of the new school year. Hurrah.
Design and create a program that allows a teacher to enter the surnames of all the students in her new class. The surnames are saved in to a new text file “newclass.txt”. A good program will allow the teacher to create and save several new classes.
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
68
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
Smith, Jones, Hanson
Text file containing the names
Davies, Roberts, Thompson, Valdemort
Text file containing the names
Implement your program!
Hint:Using Write Mode will replace any data already in the file.You will need a way for the teacher to signify that all of the names have been added.Don't forget to close the file at the end
TestingUse the table above to identify any issues with your program
add a printout of your code here
69
34. Fullnames NeededYou will need the text file “names.txt” from Challenge 31.
The teacher from Challenges 31-32 has been told off for only knowing his students' last names. Design and create a program that displays the names from the “names.txt” file. The teacher can then enter each student's first name. The first name and surname are saved to a new text file “fullnames.txt”.
Eg: Attwood becomes John AttwoodDerry becomes Carla Derry etc
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
70
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
John, Carla etc File containing full names: John Attwood, Carla Derry etc
Implement your program!
Hint:Think about the interface – you don't necessarily need to display all of the names at once (that would be easy for 5 names, but 30?)
TestingUse the table above to identify any issues with your program
add a printout of your code here
71
35. Child FinderYou will need the “fullnames.txt” file from Challenge 34. Make sure there are at least 10 full names in the file.
Our intrepid teacher has spotted a piece of graffiti on a desk in the classroom. As we know, he is rubbish at remembering names. Design and create a program that allows the teacher to enter an initial letter. The program reads through the “fullnames.txt” file and displays only those names starting with the initial letter entered.
Eg “J” entered. John and Jenna etc are displayed
You could extend the program by searching for matching first and surnames.Eg “J” entered. John, Jenna, Jennings, Jones etc are displayed
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
72
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
J Only names startingwith J displayed
SOnly names startingwith S displayed
XNo names displayed
Implement your program!
Hint:You might need to revise some of your String handling programs. Do you need to read the whole file in one go? Can you read and check one name at a time?
TestingUse the table above to identify any issues with your program
add a printout of your code here
73
36. Off-RollYou will need the “fullnames.txt” file from Challenge 34/35. Make sure there are at least 10 full names in the file.
One of the students in the group has moved to a new school. Create a program that allows the teacher to remove a student from the list of names. The new list is displayed in full. A good program will make sure that the correct student is removed, especially if there are duplicate names in the list (eg 2 girls called Fran, 2 students with the surname Davison etc). A good program will also allow the teacher to change his/her mind – eg if they accidentlally entered the wrong name.
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
.........................................................................................…
.........................................................................................…
74
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
John, yes Correct “John” removed from list
Smith, yesCorrect “Smith” removed from list
John, noCorrect John identified, but delete action is cancelled!
Implement your program!
Hint:How do you delete information from a file? Perhaps it is easier to move items across to a new file, but skip the item to be delete. You can then delete the old file and rename the new one.
Think about the interface carefully – how can you make sure you give the user the chance to cancel the deletion without becomin intrusive/overly complex?
TestingUse the table above to identify any issues with your program
add a printout of your code here
75
37. All-in-one!This challenge is a follow-on to the extension for number 31 - Registration
You will need 3 text files, group1.txt, group2.txt and group3.txt. Each file contains the names of students in a class, preferably in alphabetical order! Create a program that merges all 3 files into a new text file containing all of the students in order. There is no need to delete the original files!
A good program will make sure all the names are in the correct order, will spot duplicates and ask if there are really 2 students with the same name, or if the duplicate should be skipped.
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
.........................................................................................…
.........................................................................................…
76
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
Implement your program!
TestingUse the table above to identify any issues with your program
ExtensionAllow the user to choose the files to merge and the name of the new file.
add a printout of your code here
77
38. Mythological BeastsCreate a program that allows the user to enter the name and description of a mythical beast. The information is added to a text file. The user can also choose to display all of the information in the encyclopedia.
Add a search function so that the user can enter the name of a beast to look for.
Example encyclopedia:Centaur – Half man, half horse from Greek legendsDragon – ferocious flying lizard that breathes fireZombie – undead creature. Walks slowly. Groans a lot.
Flowchart
Pseudocode............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
.........................................................................................…
.........................................................................................…
78
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
Implement your program!
Hint:Keep the file structure simple, but logical. Compare the advantages and disadvantages of using each of the following structures:
TestingUse the table above to identify any issues with your program
ExtensionA good program will spot and prevent duplicates – eg “centaur” and “Centaur” are the same and should use the same information in the encyclopedia. If the user tries to add an item that is already in the file, the programshould offer the user the choice of replacing or adding to the beast's descritopn.
You can go to town on this program! Add other fields/data such as size, speed, rarity etc. You could turn this into a Top Trumps, Pokemon or RPG style database. You could find out how to display images and have an image file available for some of the creatures.
79
39. ThesaurusA thesaurus is a book that lists alternative words with the same meaning. For example under difficult you mightfind challenging, problematic, arduous, ambitious, onerous, tough, demanding etc.
Design and write a program that allows the user to enter a short sentence. The program checks to see if each word in the sentence is listed in the thesaurus.txt file and displays the alternative words available. The user can choose to replace the current word with one of those from the thesaurus.
You could work in a group to build up a longer thesaurus file. Make sure you all use the same file strucutre!
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
.........................................................................................…
.........................................................................................…
80
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
Implement your program!
TestingUse the table above to identify any issues with your program
ExtensionAdapt your program. The user can choose a text file containing a short paragraph or essay. The program uses the thesaurus.txt file to automatically translate the original file into a new one with “better” vocabularly.
add a printout of your code here
81
40. The Rehash Cop-outPrograms use files in order to store data permanently, ie the computer can be switched off and the data reloaded at a later date.
Several of the earlier challenges in this book would benefit from adding file-handling abilities.
Look again at the following and consider how file handling could be usefully incorporated.
11. Cafe Adder18. Bingo Bingo19. Sort it out20. Student Average28. Codewords 229. Decoder
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
82
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
Implement your program!
TestingUse the table above to identify any issues with your program
add a printout of your code here
83
Programming Showcase
A Programming Showcase is a formal document showing how you progressed through all of the stages in the development process. It will use some of the design, development and testing work you have completed in thisbooklet as well as a detailed narrative of what you did at each stage, and, more importantly, why and how youdid it. It will also include a full evaluation of the final version of your program and incorporate feedback and thoughts from other people (eg members of your class).
The showcase will be marked using the exam board's guidelines for Controlled Assessment or Coursework Projects.
The Showcase should cover the following main points:
AimDescription of program's main purposes(s). You could paraphrase the task's instructions.
Design and PlanningI->P->O diagramFlowchartPseudocodeVariables/data structures needed (and validation)For the highest grades, remember to discuss why you are using a particular approach
Test PlanDetailed testing strategy – how will you know if your program works?Detailed testing table – what data will you use to test your program?Valid, invalid and extreme data
DevelopmentAnnotated screenshots showing stages of developmentDiscussion of any problems you encountered and how you fixed them (or didn't!)Explicit, detailed discussion of changes made to your code following alpha testingFull code listing for the final program, commented, indented, using ssensible variable names etc
TestingCompleted test plan with appropriate comments and evidence (screenshots?)
EvaluationDiscuss good/bad aspectsFeedback from othersSuggestions for further improvementNote how the following evaluation paragraphs each cover a Fact, an Opinion and an Improvement (F->O->I)
The interface for the program uses drop-down lists so the user can choose the items bought.This is good because it prevents the user from entering invalid spellings or non-existent items. When the program first loads up, the drop-down lists always shows “coffee”. I could set them to be blank so the user doesn't have to change them to blank if fewer than 5 items are bought.
The program correctly works out the student's average score in most cases. However, the maximum score for each test is supposed to be 20 and it is possible to enter higher scores than this. I could add some error-handling to prevent the user from entering invalid numbers,
eg:repeat
input scoreuntil score>-1 and score<21
84
85
Part 4: Searching and Sorting
Add some theory about:linear searchbinary searchbubble sortmerge sortinsertion sort
86
41. WordsearchA computer science student keeps a list of all the weird and wacky words her teacher uses along with a brief explanation of what the word means.
Egconcatenation : joining two strings togetherubiquitous : they're everywhere! Eg USB sticksanalogue : not-digital, wave based. Eg natural sounddenary : another word for base ten or decimal
Design and create a program that allows the user to enter a word. The explanation of the word is displayed or a “not found” message if the word is not in the list.
A linear search compares the sought data to the first item, then moves on to the second, third item etc until thelist has been examined completely. As the data items are not in order, a linear search would be appropriate in this situation.
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
87
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
Implement your program!
TestingUse the table above to identify any issues with your program
ExtensionAn internal search looks through data that is stored completely in RAM, eg searching through an array.
An external search looks through data that is stored in secondary storage, such as in a file on a hard drive. It is not always necessary to read/store the whole file in RAM when performing a search.
1. By developing your program further, consider the advantages and disadvantages of using an external search compared to an internal search.
2. Imagine the words and their descriptions are stored in alphabetical order. How can your search routines be made more efficient?
Eganalogue : not-digital, wave based. Eg natural soundconcatenation : joining two strings togetherdenary : another word for base ten or decimalubiquitous : they're everywhere! Eg USB sticks
88
42. Wordsearch 2A binary search compares the sought data to the middle item in a list or data structure. If the sought item is smaller, then the latter half of the list is discarded. If the sought item is greater, then the first half of the list is discarded. The list has now effectively been cut in half. The sought data item is now compared to the middle ofthe new (shorter) list and the process repeated. Eventually the item will have been found, or the list exhausted.
The computer science student now keeps the word list in alphabetical order (see extension to no 41). There are now 12 words and their explanations in her list.
Design and create a program that allows the user to enter a word. The explanation of the word is displayed or a “not found” message if the word is not in the list.
Think carefully about the error checking needed to make sure that all items are covered in the search and that the program correctly discards half of the list each iteration.
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
89
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Add your own tests to the blank lines.
Inputs Expected Output Actual Outputs Comments
Implement your program!
TestingUse the table above to identify any issues with your program
ExtensionLook back at the definitions of internal and external searches in no 41. Is it possible to complete a binary search on a file? Carry out research to justify your answer (eg compare different programming languages).
90
43. Proof of the Pudding
To be added
44. To be added
45. To be added
46. To be added
47. To be added
48. To be added
49. To be added
50. To be added
91
Part 5: The Big Ones51. Carpet QuoterA carpet store needs a system to create quotes for customers’ queries. The program should allow the user to enter:
• Width and length of room in metres
• Cost of carpet per square metre
• Optional fixed delivery cost (£20)
• Optional fitting cost of £5 per square metre
• Optional 10% sales discount (on carpet only, not on delivery or fitting)
The program should display:
• Sub total, the amount of VAT charged (at 20%) and the Final Total
Flowchart
Pseudocode (focus on the decisions needed):
…..........................................................................................
.............................................................................................
.............................................................................................
.............................................................................................
.............................................................................................
.............................................................................................
.............................................................................................
.............................................................................................
.............................................................................................
.............................................................................................
92
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Remember to include valid, invalid and extreme data.
Inputs Expected Output Actual Outputs Comments
Implement your program!
Hint:The GUI for this one can be difficult to follow if you aren't careful – think about a logical and clear layout
TestingUse your table above to identify any issues with your program
93
52. Ker-Ching Change GiverDesign and write a program to simulate the operation of a cash register within a Hotel Shop. It accepts as input the amount paid by the customer as well as the amount due. The program should return as output the change due expressed as coins of the relevant denominations eg.
Amount due = £28.76Amount tendered £50.00Change Due = £21.24 as
1* £20 Note0 * £10 Note0 * £5 Note0 * £2 Coin1 * £1 Coin0 * 50p1 * 20p0 * 10p0 * 5p2 * 2p0 * 1p
Pseudocode Flowchart
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
94
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. Run the tests to see if your program works.
Inputs Expected Output Actual Outputs Comments
Implement your program!
Hint:There are brute-force ways to tackle this and there are more elegant methods that produce more compact andefficient code. Which will you choose?
TestingUse the table above to identify any issues with your program
Explain these terms:
Repeated subtraction........................................................................................................................................
Integer division..................................................................................................................................................
Modulus division................................................................................................................................................
Array:.................................................................................................................................................................
Constant:.............................................................................................................................................................
95
53. Tax CalculatorWrite a program to calculate the amount of Tax payable MONTHLY by an employee at a Hotel. An employee can earn £7500 p.a. free of tax after which 10% tax is payable on the next £2500. An employee should then pay 25% tax on the amount up to £38000 p.a. and 40% thereafter. The user can enter his annual salary and the program then shows the monthly pay and tax payable for the employee.
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
96
X
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. As usual, include valid, invalid and extreme data. For this program, testing the boundaries of each tax level is absolutely vital.
Inputs Expected Output Actual Outputs Comments
Implement your program!
Hint:You really need to be clear about the maths – work out a few examples first!
TestingUse the table above to identify any issues with your program
Explain these terms:Test data...................................................................................................................................................
Valid data...................................................................................................................................................
Invalid data...................................................................................................................................................
Extreme data...................................................................................................................................................
Boundary data...................................................................................................................................................
97
54. Painter QuoterYou have been asked to develop a program to help give quotations for decorating rooms.
The program will assume that a room is a rectangular box, with the length, width and height being given in metres. The quotation will be simply for the worker’s time in decorating and will not include the cost of materials (paints, wallpaper etc).
Walls:
N.B. When working out the costs for decorating the walls, ignore any doors, windows etc – just assume that each wall is a featureless surface for these calculations.
Painting walls costs £1.25 per square metre; wall-papering walls costs £1.75 per square metre. If walls are taller than 2.25 metres then the workers will need to work on ladders and trestles, so the price goes up to £2.00 per square metre for painting and £2.50 per square metre for wall-papering.
In addition:
· painting skirting boards costs 50p per metre length (assume that the skirting board goes all around the base of the room – again ignore gaps for doors etc)
· painting a door costs £5.50
· painting a window costs £10.00
Ceilings:
Painting ceilings costs £2.20 per square metre. If the ceiling is higher than 2.25 metres then the cost rises to £3.00 per square metre.
Floors (optional):
If the customer has wooden floors that they want sanding and varnishing, this costs £4.00 per square metre.
There is an additional charge of £10 for hire of dustsheets to protect furniture and carpets from the decorating. This is a standard charge, irrespective of the size of the room.
Design, write and test a program to fulfil the above specification. You will need to plan the calculations carefullyand use sensible test data.
Submit a fully detailed Showcase for your program
98
55. Thief!This is a tough one!
A thief has managed to find out the four digits for an online PIN code, but doesn't know the correct sequence needed to hack into the account.
Design and write a program that displays all the possible combinations for any four numerical digits entered bythe user. The program should avoid displaying the same combination more than once.
Submit a fully detailed Showcase for your program
56. Treasure Hunt
A treasure hunt game is played on a 5 x 5 grid. One square contains a pot of gold, 5 squares contain deadly creatures (spiders, scorpions etc). At the start of the game, the program randomly hides the treasure and the deadly creatures. The player then chooses squares until he either finds the treasure, or is killed by a deadly creature. The program should show which squares the player has chosen so far and display appropriate messages when he encounters an object or chooses an empty location.
The program gives a “getting warmer” message if the player chooses a location 2 squares from the treasure and a “getting hot” message if he is 1 square away. It gives similar messages for choosing squares close to the deadly creatures
57. Password resetA password for an online banking system consists of 9 characters, at least one of which must be an upper case letter and at least one of which must be a number. Users must change their password every month. The new password must not contain more than 3 of the same characters used in the current password.
Write a program to compare 2 strings to see if the second is a valid new password. The program should give the following feedback according to how many of the same characters are used in the new password.
4-6: Invalid password. Your new password contains too many letters from the existing password.7-8: Invalid password. Your new password contains almost identical letters to the existing password.9: Invalid password. Your new password contains identical letters to the existing password.
58. FruityWrite a program to simulate a Fruit Machine that displays 3 symbols at random from Cherry, Bell, Lemon, Orange, Star, Skull.
The player starts with £1 credit, with each go costing 20p. If the Fruit Machine “rolls” 2 of the same symbol, theuser wins 50p. The player wins £1 for 3 of the same and £5 for 3 Bells. The players loses £1 if 2 skulls are rolled and all of his/her money if 3 skulls are rolled. The player can choose to quit with the winnings after each roll or keep playing until there is no money left!
59. ContagionWrite a program to simulate the spread of a disease in a 20 x 20 area. The program randomly sets one “cell” tobe diseased at the start of the game. Each round, every cell is checked and if any cell is next to a diseased cell (including diagonally), it too becomes diseased. The display is updated every round to show diseased/healthy cells.
Every 5 rounds, the player can choose to inject one cell with an antibody. Every round the antibody spreads using the same rules as the disease. Can the player wipe out the disease? How many rounds can the player last before all cells are diseased?
99
60. ClassificationA simple classification system asks a series of Yes/No questions in order to work out what type of animal is being looked at. Eg Does it have 4 legs? Does it eat meat? Does it have stripes? Etc
These systems can often be drawn using a “tree” structure. Carry out some simple research on classification trees, then write a program to help the user decide between the following:
horse, cow, sheep, pig, dog, cat, lion, tiger, whale, dolphin, seal, penguin, ostrich, sparrow, spider, ant, bee, wasp, termite, octopus, squid
Is there a better way to do this than using 101 IF...ELSE...END IFs?
Develop your classification system for your own area of interest: pop bands; pokemon; cars; footballers; teachers; diseases etc
61. Vending Machine SimulatorA vending machine holds 20 different items in a 4 x 5 grid. The “slots” for the items are given codes: A1, A2, A3, A4, B1, B2 etc. Each slot can hold up to 10 items.
The customer can enter coins into the machine, which displays how much has been entered. The customer can then use a keypad to choose the code for the item he/she wishes to purchase. If enough money has been entered and there is at least one of the chosen items left, the item is delivered into the tray at the bottom of themachine. Appropriate change is then delivered into a change-tray underneath the keypad.
1. Draw a flowchart to represent the user’s experience of the vending machine
2. What data structures are needed for the vending machine?
3. What other variables will be needed for the system?
4. Design 2 suitable interfaces for the Vending Machine Simulation, explaining the advantages/disadvantages of each. Make a recommendation.
5. What are the potential difficulties you will face in creating a solution?
Create a suitable solution using a high level language and featuring an appropriate graphical interface.
62. Noughts and CrossesNoughts and Crosses is a simple 2 player “time-waster” game
1. Create a 2 player Noughts and Crosses game
2. Add an AI routine to take the place of the 2nd player
3. Allow “best of 5” games
4. Add an option to extend the board to a 5x5 grid
100
63. HaikuHaiku is a Japanese form of poetry, usually 3 lines long and with 17 syllables* in a 5, 7, 5 pattern. The poems frequently deal with nature and our response to it and usually incorporate a “cut” or change of perspective, imagery or viewpoint.
Examples:old pond . . . a frog leaps in water’s sound
the first cold shower even the monkey seems to want a little coat of straw
On the jagged cliff, sadly gazing far below, his troubles end here
ChallengeDesign (flowchart, pseudocode, variables), write and test a program to create a traditional Haiku. The program should allow the user to enter a number of key words that will be used in the poem.
Success Criteria for the program are:The user enters at least 2 nouns, 2 verbs and 1 adjective These key words are used appropriately in the poemOther verbs, nouns and adjectives are incorporated appropriatelyA 3 line Haiku is displayedGrammar (eg verb endings, plurals) are used accuratelyThe user can choose to save a good haiku to a fileThe file of Haikus can be displayed appropriately
The Haiku has 17 syllablesThe Haiku follows the 5, 7, 5 pattern
Expected SkillsYou may need to use some/all of the following:
String manipulationArrays/ListsError handlingFile handling
* Haiku usually have 17 onji (sound symbols). These are not quite equivalent to English syllables. EG, some vowel combinations (such as ai) are worth 2 onji and a final n is also considered as an on.
101
64. ConnectronConnectron is a Connect 4 style game played by 0-10 players.
The size of the grid can be anything from 6x 6 to 100 x 100 in size.
To win, a player must create a horizontal, vertical or diagonal line of his/her counters. The winning player scores points equal to the number of players (ie 4 points if there are 4 players).
The length of the line needed to win can be 4-10 counters, chosen at the start of the game.
Players take turns to drop a counter into a column. The counter falls to the bottom of the column.
If fewer than 2 players are playing, the computer will take turns for the missing players
Players can choose to play a “best of 3” or “best of 5” round match etc. The winner is the player with the most points at the end of all rounds.
Special RulesA counter in any of the four corners counts as 2 counters, or 3 counters if the winning line needs to be 7 or more.
If a “solitaire” counter is completely surrounded by counters from 1 other player, the solitaire is destroyed, removed from the grid and the other counters in that column move down to replace it.
Once per game, each player can play a “bomb-counter”, which, when played, will detonate, destroying itself and any immediately adjacent counters. Counters already in the grid will fall down into empty spaces where appropriate.
If the board is at least 8 rows in depth, any counter filling a column completely will “overflow” into adjacent columns, allowing an extra 1 or 2 counters to be played immediately.
AlliancesAt the start of a round/game players can form alliances. In an alliance game, counters from each allied player count as if one colour for the sake of winning lines and the “solitaire” rule. If a winning line is made up of more than 1 colour, each relevant player receives a share of the points available. If a player wins using just his/her colour, the player receives all of the points.
If a multiple round match is being played, players can choose new alliances at the start of each round.
InterfaceThis could be done in console mode, although lots of scrolling text is not really helpfulThis could be done with a GUI, but there is no need for a million buttons!There is absolutely no need for animation – the counters can “appear” in the correct locationThere is absolutely no need for fancy graphics, although coloured circles might be appropriateThink about the interface size : 6x6 up to to 100x100. HmmThink about the number of players and what needs to be displayed to help them
1. Make sure you understand the game (play it with pen and paper)
2. Describe the inputs, outputs and processing required
3. Design data structures needed – board, players, rounds etc. Global/local?
4. Consider the interface.
5. Make a list of modules/functions needed, in the order they will be executed
6. Create the program using a modular approach – certain tasks, such as the special rules, can be put off for avery long time! Some tasks, such as checking for winning lines, can be broken down into several modules
102
65. Snake EyesA group of friends (usually 4) are playing a dice game called Snake Eyes.
During a round, each player rolls 2 normal, 6-sided dice. The player scores the total of the dice roll.
The player can choose to gamble by rolling again and increasing his/her score by adding on the new roll.
However, if a 1 is rolled, the player scores 0 for that round and passes the dice to the next player.
If two 1s are rolled, the player’s total score for all rounds so far is set to 0.
The friends usually play 5 rounds to see who is the overall winner
Draw a FlowChart and write pseudocode to represent the above system
Describe a suitable test plan for the system.
Code the Snake Eyes Game
66.Simon“Simon” is a popular electronic game. It consists of 4 lights (red, green, blue and yellow) which flash in a random sequence. Players have to press the lights in the order of the sequence. Each time they get it right, the sequence repeats, but gets longer and faster.
Recreate the class Simon game.
Think of additional features for your game: high score table? Multi-player?
67. BattleshipsYou know what to do.If you don’t, then find out.
103
68. Where's Shakey?William Shakespeare. Don't you just love him?
The sneaky sonnet-meister has gone missing. He doesn't want to attend his own birthday parade so has gone into hiding!
Can you help track down the pesky poet before the parade starts? Search the school/town of Stratford-upon-Avon to stop the scribe skiving, but be careful. As soon as you spot him, he'll dash off to a new hiding place. The only way to catch him is to wear him out by keeping him on the run. The longer it takes to find him, the more energy he will recover and the more times he can dash off and hide.
Your job is to design and create the Where's Shakey app for Android.
1. Overview
Draw a diagram showing the main screens and sections needed for the app
2. Design
Draw sample screen layouts for the main screens/sections
Draw a table showing key variables needed
List any resources you need
3. Algorithms
Write language-agnostic pseudocode for each key section
4. Test plan
How will you know if the app works correctly? List the key success criteria and explain how you will test each of them
5. Coding preparation
What new code do you need? What help do you need?
6. Create your app
Keep a log or diary of your work
7. Test it
Prove that your app meets the success criteria
8. Evaluation
Gather feedback on your app
Write an evaluation of your app
NB: This task was originally part of an AppInventor project, but could be adapted for other systems.
104
68. Dungeon CrawlerAngband is a classic dungeon crawler game with an ASCII-art based interface. Represented by an @ symbol, you wander around forests, dungeons and castles killing mythical creatures and trying to amass gold and, more importantly, experience points.
If all this sounds too geeky for you, then frankly, you shouldn’t be studying Computer Science.
Angband is Open Source and there is a variant for pretty much every Operating System ever developed.
So go away, download Angband, play it obsessively and come back in a few weeks.
You’re back? Good. Here’s your task:
Recreate Angband.
Too much?
Okay – easy version.
Create a simple dungeon crawler game. It could be text based, or you could use those new-fangled fancy graphics with 8 colours. It could be based on Tolkein, Rowling, Pokemon or any other magical world where strange creatures abound and weird characters frustrate your every move. Like school, for example.
If you want to make the game playable and, importantly, easily extendible, you will need to plan it carefully. What will the character creation system look like? How will combat work? What attributes do you need to storefor the player character and for the monsters/enemies? Will the terrain/dungeon be randomly generated or planned? How will you incorporate different levels? Can the player actually win?
Whew. That’s probably enough to be getting on with for the moment.
70. Over To YouYou should have loads of ideas by now – so go on and create your own app or game!What’s the worst that could happen?
105
Design SheetUse this sheet to plan and design your own programs
Aim of program:
….......................................................................................................................................................................
….......................................................................................................................................................................
Flowchart
Pseudocode
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
106
X
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
Variables and Other Data StructuresName Datatype Typical Value Minimum Value Maximum Value
Test PlanComplete the first 2 columns of the following Test Plan BEFORE implementation. As usual, include valid, invalid and extreme data.
Inputs Expected Output Actual Outputs Comments
Implement your program!
Test your program!
Evaluate your program!
107
Programming Target Tracker
Date Program Grade Target Evidence of Achieving Target
eg FormChooser C Investigate Select...Case as analternative to using multiple
nested Ifs...
Used Select...Case in the Mini-Calc program to choose between
operators
108
Programming Resources
Background Reading
http://www.i-programmer.info/babbages-bag.html
http://computer.howstuffworks.com/
http://www.howitworks.net/
Tutorials
http://www.i-programmer.info/ebooks/master-visual-basic.html
http://www.java2s.com/Tutorial/VB/0300__2D-Graphics/Catalog0300__2D-Graphics.htm
http://www.dreamincode.net/forums/forum/78-programming-tutorials/
http://www.codeavengers.com/
https://www.futurelearn.com/courses/begin-programming
http://www.w3schools.com/sitemap/default.asp#examples
http://www.w3schools.com/php/default.asp
http://www.w3schools.com/sql/default.asp
http://www.youtube.com/user/Axsied
http://www.tech-recipes.com/rx/category/computer-programming/
109