Using DIV and MOD together (8.1a)

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Using DIV and MOD together (8.1a)

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which expression gives the whole hours in 135 minutes?
A MOD(135, 60)
B DIV(135, 60)
2. Which expression gives the leftover minutes after taking out whole hours from 200 minutes?
A MOD(200, 60)
B DIV(200, 60)
3. 250 cents split with DIV(250, 100) and MOD(250, 100) gives which result?
A 50 dollars and 2 cents
B 2 dollars and 50 cents
4. 47 items are packed in boxes of 10. Which tells you how many items are left loose?
A MOD(47, 10) = 7
B DIV(47, 10) = 4
5. Which pair of lines correctly splits 200 minutes into hours and minutes?
A Hours ← DIV(200, 60) and Minutes ← MOD(200, 60)
B Hours ← MOD(200, 60) and Minutes ← DIV(200, 60)

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1Hours ← DIV(135, 60) ADIV was used to find the items left over. DIV gives 4 full boxes, but the leftover items need MOD, which gives 2.
2Left ← MOD(135, 60) BFinds the minutes left over after taking out whole hours, which is 15
3To find how many full boxes of 12 are needed for 50 items, use DIV with the total and the box size CFullBoxes ← DIV(50, 12)
4To find how many cents remain after taking out whole dollars from 275 cents, use MOD with the total and 100 DCents ← MOD(275, 100)
5Hours ← MOD(200, 60) EMOD was used to find the whole hours. MOD gives the remainder (20), but whole hours need DIV, which gives 3.
6Spare ← DIV(50, 12) FFinds the number of whole hours in 135 minutes, which is 2

Definitions

DIV(Total, Size) and MOD(Total, Size)

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
Hours ← ___(TotalMinutes, 60)
2.
Minutes ← ___(TotalMinutes, 60)
3.
Dollars ← DIV(Cents, ___)
4.
CONSTANT BoxSize ← 12 Boxes ← DIV(Items, BoxSize) Left ← MOD(Items, _______)
5.
Items ← 50 Boxes ← DIV(Items, 12) OUTPUT "Full boxes: ", _____

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A TotalMinutes = 135
B Hours ← DIV(TotalMinutes, 60)
C Mins ← MOD(TotalMinutes, 60)
D OUTPUT Hours, Mins
Question 2
A Total ← 47
B BoxSize ← 12
C Boxes ← DIV(Total, BoxSize)
D Left ← DIV(Total, BoxSize)
E OUTPUT Boxes, Left
Question 3
A Cents ← 875
B Dollars ← DIV(Cents, 10)
C Change ← MOD(Cents, 100)
D OUTPUT Dollars, Change
Question 4
A DECLARE Eggs : REAL
B Eggs ← 50
C Cartons ← DIV(Eggs, 6)
D Spare ← MOD(Eggs, 6)
Question 5
A Secs ← 200
B Mins ← DIV(Secs, 60)
C Rest ← MOD(Secs 60)
D OUTPUT Mins, Rest

Answer Key

Using DIV and MOD together (8.1a)
Section A: Quick Questions
Q1
B — DIV(135, 60)
Q2
A — MOD(200, 60)
Q3
B — 2 dollars and 50 cents
Q4
A — MOD(47, 10) = 7
Q5
A — Hours ← DIV(200, 60) and Minutes ← MOD(200, 60)
Section B: Match the Pairs
Q1
Hours ← DIV(135, 60) → Finds the number of whole hours in 135 minutes, which is 2
Q2
Left ← MOD(135, 60) → Finds the minutes left over after taking out whole hours, which is 15
Q3
To find how many full boxes of 12 are needed for 50 items, use DIV with the total and the box size → FullBoxes ← DIV(50, 12)
Q4
To find how many cents remain after taking out whole dollars from 275 cents, use MOD with the total and 100 → Cents ← MOD(275, 100)
Q5
Hours ← MOD(200, 60) → MOD was used to find the whole hours. MOD gives the remainder (20), but whole hours need DIV, which gives 3.
Q6
Spare ← DIV(50, 12) → DIV was used to find the items left over. DIV gives 4 full boxes, but the leftover items need MOD, which gives 2.
Section C: Definitions
Q1
DIV(Total, Size) and MOD(Total, Size) — DIV gives how many whole groups fit in the total, MOD gives what is left over. Together they split a total into whole units plus a remainder. E.g. 135 minutes is 2 hours 15.
Section D: Fill in the Blanks
Q1
Hours ← DIV(TotalMinutes, 60)
Q2
Minutes ← MOD(TotalMinutes, 60)
Q3
Dollars ← DIV(Cents, 100)
Q4
CONSTANT BoxSize ← 12 Boxes ← DIV(Items, BoxSize) Left ← MOD(Items, BoxSize)
Q5
Items ← 50 Boxes ← DIV(Items, 12) OUTPUT "Full boxes: ", Boxes
Section E: Spot the Error
Q1
A — Cambridge pseudocode assigns a value with the ← operator, not =. The line should be TotalMinutes ← 135.
Q2
D — The items left over after filling the boxes come from MOD, not DIV. DIV gives the number of full boxes. The line should be Left ← MOD(Total, BoxSize).
Q3
B — There are 100 cents in a dollar, so the size to divide by is 100, not 10. The line should be Dollars ← DIV(Cents, 100).
Q4
A — DIV and MOD work on whole numbers, and a count of eggs is a whole number. Eggs should be declared as INTEGER, not REAL.
Q5
C — The two arguments of MOD must be separated by a comma. The line should be Rest ← MOD(Secs, 60).