<< PrevALCON PROBLEM 2:
CAPTAIN SPACK JARROW
Congratulations on making it past the first week's problem - it was tough! But we got there. Before we reveal the problem for this fortnight, a quick recap on Week 1's problem and sample solution.
Week 1 asked you to write a program that inputs a fabric given three options. The program should print the largest number of rolls AND the fabric.
There was
one submission, so congratulations to
anomalous for the wonderful submission. They've earned points and will be listed on the leaderboard. Remember, if you missed a problem, then you can still participate in that contest to help aid you for your exams. We will help lead you in the right direction from time to time.
Sample answer:(note [u ][/u] tags mean that the code was underlined.)
BEGIN MAINPROGRAM
plain = 0
striped = 0
dotted = 0
fabric = INPUT(“Enter the name of the fabric type: “)
WHILE Fabric != “done” DO
CASEWHERE fabric is
“plain”: INCREMENT plain
“striped”: INCREMENT striped
“dotted”: INCREMENT dotted
END CASE
fabric = INPUT(“Enter the name of the next fabric type: ”)
ENDWHILE
[u]Find_Largest(plain, striped, dotted)[/u]
END MAINPROGRAM
#This is for the main question-- assumes only one solution
BEGIN [u]Find_Largest(plain, striped, dotted)[/u]
CASEWHERE
Plain > striped AND plain > dotted: PRINT(plain, “plain”)
Striped > plain AND striped > dotted: PRINT(striped, “Striped”)
Dotted > striped AND dotted > plain: PRINT(dotted, “dotted)
OTHERWISE: [u]Call_Challenge(plain, striped, dotted)[/u]
ENDCASE
END [u]Find_Largest[/u]
#Challenge answer-- you know it’s multiple answers, so it’s either all three or a pair
BEGIN [u]Call_Challenge(plain, striped, dotted)[/u]
IF plain == striped AND plain == dotted THEN
PRINT(plain, “plain, striped, and dotted”)
ELSE
CASEWHERE
Plain == striped: PRINT(plain, “plain and striped”)
Plain == dotted: PRINT(plain, “plain and dotted”)
Striped = dotted: PRINT(striped, “striped and dotted”)
ENDCASE
ENDIF
END [u]Call_Challenge(plain, striped, dotted)[/u]
Please make sure you've read the rules
here.
Week 2 question:Running a ship takes a lot of crew members, and each of them have a designated role on the ship. E.g. the boatswain (bosun) is in charge of equipment and crew, the coxswain is in charge of the navigation, etc.
Captain Spack Jarrow wants to keep track of all personnel on his ship in what he calls “the Pirate’s Log” (i.e. a database of some sort).
Write a program that allows him to look up the details of a crew member on the Pirate’s Log, meeting the following specifications:
He can search for crew members by name.
Each crew member has a name, a role, an age, and a “mutiny meter” (“low”, “medium”, or “high”, depending on how likely the crew member will commit mutiny)
Once given a name, the program will search and output all the details about that particular crew member (name, role, age, and mutiny meter)
Assume the common sailor roles are numbered so each role name is unique- e.g. sailor1, sailor2, etc. Names are also unique.
Optional challenge add on (+2 marks)
Modify the program to allow Captain Jarrow to search by either name or role.
You’ll be marked on correctness, efficiency, and defensive programming.
Learning objectives for the week:-> Arrays
-> Loops and searches
-> Records and fields
Don't forget to
login or
register an account to submit your answer!
Good luck, and as always, happy algorithming!