Note that your final mark will not be saved in the system.
Programming Concepts GapFill
You must fill all the gaps before clicking ‘Check Answers!’
Once you have decided on an algorithm to solve a problem, it is useful to think about the programming constructs that you will need to use.
For example, in this algorithm:
Step 1: Get user input
Step 2: Ask the user if they would like to make a substring from their input
Step 3: If they say yes, ask them for the start position and length of their desired substring
Step 4: Set the value of the input to be the substring specified by the user
Step 5: Repeat the previous three steps until the user says no
Step 6: Output the final value of the input
We can see from above that the algorithm will require some sort of selection. We can see from that it will also require iteration.
To start programming the algorithm, we should start from the first step and follow each step through in order. First, we get input from the user:
PRINT('Enter a word or phrase')
userString
= ''
The response of the user input is stored as
so that it can be used and edited later. We then move on to the next step, asking the user if they would like to make a substring from their input:
PRINT('Would you like to make a substring of '+ userString + (y/n)')
response ← USERINPUT
The next two steps depend on the result of the entry so we need a statement:
PRINT('Would you like to make a substring of '+ userString + (y/n)')
response ← USERINPUT
IF 'y' THEN
PRINT('Enter the start position of your new substring')
subStrStart ← USERINPUT
PRINT('Enter the end position of your new substring')
subStrEnd ← USERINPUT
userString ←
We now need to make the program loop through the necessary steps:
WHILE response 'n'
...
Finally, we output the result: