<< PrevALCON PROBLEM 3:
HAIRY BOTTLER
It's been a month since we first launched ALCON, and it's been gaining interest rapidly. Problem 1 saw one entry; we've grown to 5 entries in Problem 2. That's fantastic news, and we're looking to expand on that in the future
Week 2 asked you to write a program that allows Captain Spack Jarrow to look up details of crew members on the Pirate Log. The program had to output all of the details about that particular crew member.
There were
five submissions. Huge congratulations to
DrDusk and
Jenna Chan on their perfect 7/7. Absolutely mental
Everyone who submitted code has been listed on the leaderboard, so be sure to check back to find where you're currently sitting! If you've missed Problem 2, don't worry! You can always do them in your spare time and get feedback for your code.
Sample answer:(note [u ][/u] tags mean that the code was underlined.)
BEGIN [u]Search_Log(piratesLog)[/u]
Get query_type from user input
CASEWHERE query_type is
“name”: [u]searchName(piratesLog)[/u]
“role”: [u]searchRole(piratesLog)[/u]
ENDCASE
END [u]Search_Log[/u]
BEGIN [u]searchName(piratesLog)[/u]
Get target from user input
FOR i=1 TO piratesLog.length STEP 1
IF piratesLog[i].name == target THEN
PRINT piratesLog[i].name, piratesLog[i].role, piratesLog[i].age, piratesLog[i].mutiny
i = piratesLog.length + 1
ENDIF
ENDFOR
END searchName
BEGIN [u]searchRole(piratesLog)[/u]
Get target from user input
FOR i=1 TO piratesLog.length STEP 1
IF piratesLog[i].role == target THEN
PRINT piratesLog[i].name, piratesLog[i].role, piratesLog[i].age, piratesLog[i].mutiny
i = piratesLog.length + 1
ENDIF
ENDFOR
END [u]searchRole[/u]
Please make sure you've read the rules
here.
Week 3 question:Being able to manage a book of spells is Hairy Bottler’s job. But he doesn’t want to manually update them. Instead, Hairy outsources this job to you.
Luckily for you, Hermit Grunger has agreed to help-- she’s compiled a sequential file of all existing spells that contains the name of each spell followed by its use.
Write a program that searches through the file to determine if a given spell exists or not, and returns the correct use (e.g. if I search for “wingardium leviosa” it returns “levitation charm”).
Optional challenge add-on (+2 marks)
Modify the program so that Hairy can update the spellbook file with new spells.
You’ll be marked on correctness, efficiency, and defensive programming.
Learning objectives for the week:-> Reading and opening files.
-> Update files.
-> Close files.
Marking guidelines
[
Don't forget to
login or
register an account to submit your answer!
Good luck, and as always, happy algorithming!