A food manufacturer produces ‘pots’ of yoghurt. It is important that the amount of yoghurt in each pot is at least the amount stated on the pot. The weight of yoghurt in a sample of pots is measured.
Design a program using pseudo-code with the following inputs:
● the required weight
● the number of pots to be sampled
● the weight of yoghurt in each of the pots in the sample
The outputs for the program should be for each pot found to be underweight:
● the pot number (1,2,3,etc.) and the weight of yoghurt in that pot
The program should also output the total number of underweight pots in the sample.
All outputs should contain suitable messages where helpful.
For instance, if the inputs are:
151
8
151 152 150 154 149 152 151 153
The outputs should be similar to:
Underweight pot: 3 150
Underweight pot: 5 149
Total number of underweight pots: 2 [6]
Try answering the question with this level of support. If you get stuck Try the next level.
Use the Big 6 to help you and the code listing below (REMEMBER these are not in order)
Declare & Initialise variables
Use all of these declaration statements
declare requiredWeight as integer
declare numberOfPots as integer
declare weight as integer
declare totalUnderWeight as Integer
Input(s)
Use all of these instructions
output "Please enter the weight of the current pot"
input weight
output "Please enter the required weight"
input requiredWeight
output "Please enter the number of pots"
input numberOfPots
Loop structure & increment
Use one style of loop
Counter Controlled Loop (these loops work a set number of times)
for potNumber = 1 to numberOfPots
.....
next potNumber
Condition Controlled loops - Exit controlled loop (check the condition after entering the loop)
------------------------------------ OR -------------------------------------------------
potNumber = 0
do repeat
.... ....
potNumber = potNumber + 1 OR potNumber = potNumber + 1
while (potNumber <= numberOfPots) until (potNumber > numberOfPots)
----------------------------------- OR ------------------------------------------------
Condition Controlled loops - Entry controlled loop (check the condition before entering the loop)
potNumber = 1
while (potNumber < numberOfPots)
....
potNumber = PotNumber + 1
end while
Output(s)
Use all of these instructions
output "Underweight Pot: " , potNumber , potWeight (+ or , can be used to concatinate)
output "Total number of underweight pots: " , totalUnderWeight
Selection / Errors
Use this selection statement but populate it
if (potWeight < requiredWeight) then
...
end if
Calculations / Processing
Use all of this instruction
totalUnderWeight = totalUnderWeight + 1
Use the Big 6 to help you, some examples of the instructions have been given but you will have to add some more of your own. (REMEMBER these might not be in order)
Declare & Initialise variables
Use all of these declaration statements
declare requiredWeight as integer
declare numberOfPots as integer
declare weight as integer
declare totalUnderWeight as integer
Input(s)
Use similar output then an input statement
output "Please enter in a number of ..."
input number...
Loop structure & increment
Chose which style of iteration you will use you can alter the condition controlled loops to act as a counter controlled loop.
You could use potNumber insteed of i, we tent to use i and then j as counters
Counter Controlled Loop (these loops work a set number of times)
for i = 1 to ???
...
next i
Condition Controlled loops - Exit controlled loop (check the condition after entering the loop)
--------------------------------------- OR -----------------------------------------------------
do repeat
... OR ...
i = i + 1 i = i + 1
while (i <= ???) until (i > ???)
--------------------------------------- OR -----------------------------------------------------
Condition Controlled loops - Entry controlled loop (check the condition before entering the loop)
i = ??
while (i <= ???)
...
i = i + 1
end while
Output(s)
Use this output but another is missing
output "Total number of underweight pots: " + totalUnderWeight
Selection / Errors
Use this selection statement but populate the condition
if (????? < ????) then
...
end if
Calculations / Processing
Use this instruction
totalUnderWeight = totalUnderWeight + 1
----------------------------------- EXAMPLE ---------------------------------
Use this Example to help you understand how to layout your pseudo code
Write an algorithm to input two numbers from a user, add them together and calculate the average.
If the user typed in the numbers 7 and 3, then your output should look something like:
Please enter first number
Please enter second number
The average of your two numbers is 5
Procedure CalculateAverage
Begin
Declare firstNum as Integer
Declare secondNum as Integer
Declare Total as Integer
Declare Average as Real
firstNum = 0
secondNum = 0
Total = 0
Average = 0
Output ‘Please enter first number’
Input firstNum
Output ‘Please enter second number’
Input secondNum
Total = firstNum + secondNum
Average = Total / 2
Output ‘The average of your two numbers is ‘, Average
End
Use the Big 6 and the following example instructions to help you (REMEMBER you will have to structure your code):
Declare & Initialise variables
declare number as integer (you can omit declare e.g. number is integer)
inserted is Boolean
set number = 0
set inserted = False
Input(s)
output "Enter in a number"
input number
Loop structure & increment
You could use your own variable name potNumber insteed of i, we tend to use i and then j as counters within loops
Counter Controlled Loops
for i = 1 to ???
.....
next i
Condition Controlled loops - Exit controlled loop (check the condition after entering the loop)
--------------------------------------- OR -----------------------------------------------------
do repeat
.... OR ...
i = i + 1 i = i + 1
while (i <= ???) until (i > ???)
--------------------------------------- OR -----------------------------------------------------
Condition Controlled loops - Entry controlled loop (check the condition before entering the loop)
i = ??
while (i <= ???)
....
i = i + 1
end while
Output(s)
output "This is an output text"
output "The total is " , total
Selection / Errors
The condition can be made up of multiple elements using. OR AND NOT logical expressions between each condition
For single selection use one if statement
ONE Output
if (mark < passMark) then
....
end if
For double selection use one if else statement
if (mark < passMark) then
....
else
....
end if
For multiple selection use more than one if statement (else if)
if (mark < passMark) then
....
else if ( mark = passMark) then
....
else
....
end if
Calculations / Processing
total = total + number
total = total + (i * 3)
average = total / numberOfItems
sort Numbers
Use the Big 6 to help you:
Declare & Initialise variables
Input(s)
Loop structure & increment
Output(s)
Selection / Errors
Calculations / Processing
Also mark for
Algorithm works correctly