<< PrevALCON PROBLEM 4:
STRAK ENTERPRISES
After Problem 2's fantastic 5 entries, Problem 3 was a bit more disappointing with only 2 entries. Let's try to bring that up next time!
Week 3 asked you to write a program that allows Hairy Bottler and Hermit Grunger to manage and update their spellbook by looping through a sequential file.
There were
two entries for this problem - anomalous and cthulu did well with a fantastic 6/7 and 4/7 respectively. If you missed this problem, you can always do them in your spare time and get feedback in your code.
Sample answer:(note [u ][/u] tags mean that the code was underlined.)
BEGIN [u]FindSpell()[/u]
OPEN “Spellbook” for INPUT
Get target from user input
FoundFlag = False
READ element from Spellbook
IF element == target THEN
FoundFlag = True
READ use
PRINT “Spell: “, element
PRINT “Use: “, use
ELSE
READ use
READ element
ENDIF
WHILE NOT FoundFlag AND element != “ZZZ” DO
READ use
IF element == target THEN
FoundFlag = True
PRINT “Spell: “, element
PRINT “Use: “, use
ENDIF
READ element
ENDWHILE
IF NOT FoundFlag THEN
PRINT “Spell not found”
ENDIF
CLOSE “Spellbook”
END [u]FindSpell [/u]
//Challenge
BEGIN [u]UpdateSpells()[/u]
Get name from user input
Get use from user input
OPEN “Spellbook” for APPEND
READ element
WHILE NOT EOF DO
READ element
ENDWHILE
WRITE name, use TO “Spellbook”
CLOSE “Spellbook”
END [u]UpdateSpells[/u]
Please make sure you've read the rules
here.
Week 4 question:You’re the new intern at Strak Enterprises, and Toby Strak has tasked you with keeping track of all the Nickel Man suits in the facility. Currently, there’s a relative file containing the code name and location of each suit, in no particular order.
Mr Strak has decided he wants the file moved into a multidimensional array instead, and alphabetised by code name. Pick an appropriate sorting method and write a program to carry out the requirements.
Optional challenge add-on (+2 marks)
Jarvis has compiled an alphabetised 2d array (100 x 2 elements) with the code name and the unique nickname Mr Strak comes up with for each suit. E.g. “MK1906” is called “Mark”. Write an additional program that takes in the nickname and looks through the array to output the code name for the suit.
Because Mr Strak talks quickly, this searching process must be done
as quickly as possible.
You’ll be marked on correctness, efficiency, and defensive programming.
Learning objectives for the week:-> Search and sort arrays.
-> Open and read relative files.
-> Manage multidimensional arrays.
Don't forget to
login or
register an account to submit your answer!
Good luck, and as always, happy algorithming!