Due Date: 07.09
1. Objectives
Completing
all tasks in this assignment will help you:
·
write nested selection statements
·
check for illegal input with the
function isnumeric
·
concatenate strings
First skim, and then carefully read the entire assignment before starting any
tasks.
2. Pac-Man Scores
Write a script M-file called PacScore.m that will rate a
user-supplied score on Pac-Man. To
determine the rating, your program will:
·
Prompt the user for a score. Assume the user enters an integer. If the user enters an illegal numerical
value, the program finishes with a warning.
Hint: No score may be negative,
and a score cannot be a character string.
·
Determine an initial rating
based on the following ranges:
o
A score of at least 750,000 is Kwisatz Packerach.
o
A score between 600,000 and 749,999
is Pac Jedi.
o
A score between 450,000 and 599,999
is Pac Master.
o
A score between 300,000 and 499,999
is Pacawan Learner.
o
A score between 150,000 and 299,999
is Pac Apprentice.
o
A score of 149,999 or lower is Pac Novice.
Variable rating
must be a character array (a string).
·
Modify rating
based on the specific score range:
o
If
the player is a Pac Master or Pac
Jedi, and the
score is in the first third of its range, the score is modified as starting. If the score is in the last third of its range, it is modified as
sublime. So a score of 700,000
is sublime Pac Jedi.
o
If
the player is a Pac Apprentice or Pacawan
Learner, a score
in the first third is modified as newbie, and a score in the last third
is modified as tested.
o
If
the player is a Pac Novice, no modifications are
needed.
o
To
clarify this part, you may want to introduce constants like THIRD = 50000; J_HI
= 749999; J_LO
= 600000; etc.
·
Report
the rating.
Fun question: which is
larger, J_LO or the number of minutes in J.Lo’s recent marriage? By how much? :-)
Your
program should contain two sets of if-elseif blocks: The first set determining the initial rating, the second set modifying the result of the first. Be
as efficient as you can with the second.
Hint: To concatenate the string ‘sublime
’ with the string variable rating, create an array from the two strings as so:
rating
= [ ‘sublime ‘, rating ];
3. Testing Your Program
Test your
program on the following scores 14600, 175000, 503600, 700000, 999990. Submit the output along
with your M-file.
4. Submitting Your Work
Type your
name, student ID, and the date at the top of PacScore.m. Print and sign the file.
Hand the signed document along with your output to the teaching
assistant at the beginning of lab on Tuesday 9 July 2002.