Extended Response11 MarksCommunity
An anagram is a word or phrase formed by rearranging the letters of another. For example, “listen” and “silent” are anagrams of one another.
Consider an array called ALPHA of size 26 initialised to contain only zeros. Also consider a function LTR2NUM() which accepts a single character and returns it's position in the English alphabet. For example, LTR2NUM('a') and LTR2NUM('z') return 1 and 26 respectively.
(a).
Given a Collection of letters called LETTERS, construct an algorithm to accumulate the total number of each type of letter in corresponding ALPHA index locations. For example, if the letter 'b' occurs 7 times in LETTERS then, once the algorithm has completed, ALPHA[1] should equal 7.
[4]
(b).
Construct an algorithm that outputs True if every value in ALPHA is equal to zero
[3]
Assume now that the two algorithms from a) and b) were augmented to form functions called createAlpha() and isZero() respectively.
The function createAlpha() accepts as input a Collection of letters and returns a new array called ALPHA of size 26 where the total number of each type of letter in the Collection provided as input is accumulated at corresponding ALPHA index locations. For example:
createpAlpha(["a","a","b","e","z","z","z"]) → [2,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3]
The function isZero() accepts as input an array of numbers and returns a boolean to indicate whether or not the array provided is full of zeros. For example:
isZero([0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]) → false isZero([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]) → true
(c).
Given an empty array called ARR of size 26 and two Collections of letters, one called WORDA and another called WORDB, construct an algorithm to return true if WORDA is an anagram of WORDB, otherwise output false.
[4]
301542
N7 Education
Extended Response10 MarksCommunity
A busy cafe has decided to streamline their business by implementing a software assisted ordering system. The new system will record customer orders at the front counter whereupon they are automatically added to a queue of orders accessed by a barista working at the back of the cafe to fulfill orders uninterrupted.
(a).
State one reason why a queue would be better suited to holding coffee orders than a stack.
[1]
(b).
The new systems holds the price for each type of coffee in an array called ITEMS as follows:
[6]
+--------------+--------------+ | Espresso | 1.20 | | Latte | 2.50 | | Cappuccino | 3.70 | +--------------+--------------+
Coffee orders are held in a queue called ORDERS where each order is a single integer indicating the type of coffee to be made by their respective row index in ITEMS array.
Additionally, a 3x3 2D array called SALES is initially defined as follows:
+--------------+--------------+--------------+ | Espresso | 0 | 0 | | Latte | 0 | 0 | | Cappuccino | 0 | 0 | +--------------+--------------+--------------+
Given ITEMS, ORDERS and SALES, write pseudocode such that column one and column two contain the total number of orders and total income for each coffee type respectively.
For example, the following ORDERS queue:
+-------+-------+-------+-------+-------+ 1 0 1 2 0 +-------+-------+-------+-------+-------+
would result in the following SALES array:
+--------------+--------------+--------------+ | Espresso | 2 | 2.40 | | Latte | 2 | 5.00 | | Cappuccino | 1 | 3.70 | +--------------+--------------+--------------+
(c).
The method rowswap(ARR, ROWA, ROWB) acts on the array ARR provided to swap the row at index ROWA with the row at index ROWB.
[3]
Without using loops, write pseudocode to sort the rows of SALES from lowest to highest total income. The row for the coffee with the highest total income should be at row index 2.
802982
N7 Education
Short Answer1 MarkCommunity
Define the term foreign key.
[1]
10341
N7 Education